當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.getString方法代碼示例

本文整理匯總了Java中android.content.Context.getString方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.getString方法的具體用法?Java Context.getString怎麽用?Java Context.getString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.Context的用法示例。


在下文中一共展示了Context.getString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNotificationText

import android.content.Context; //導入方法依賴的package包/類
/**
 * Constructs and returns the summary of a particular day's forecast using various utility
 * methods and resources for formatting. This method is only used to create the text for the
 * notification that appears when the weather is refreshed.
 * <p>
 * The String returned from this method will look something like this:
 * <p>
 * Forecast: Sunny - High: 14°C Low 7°C
 *
 * @param context   Used to access utility methods and resources
 * @param weatherId ID as determined by Open Weather Map
 * @param high      High temperature (either celsius or fahrenheit depending on preferences)
 * @param low       Low temperature (either celsius or fahrenheit depending on preferences)
 * @return Summary of a particular day's forecast
 */
private static String getNotificationText(Context context, int weatherId, double high, double low) {

    /*
     * Short description of the weather, as provided by the API.
     * e.g "clear" vs "sky is clear".
     */
    String shortDescription = SunshineWeatherUtils
            .getStringForWeatherCondition(context, weatherId);

    String notificationFormat = context.getString(R.string.format_notification);

    /* Using String's format method, we create the forecast summary */
    String notificationText = String.format(notificationFormat,
            shortDescription,
            SunshineWeatherUtils.formatTemperature(context, high),
            SunshineWeatherUtils.formatTemperature(context, low));

    return notificationText;
}
 
開發者ID:rashikaranpuria,項目名稱:ubiquitous,代碼行數:35,代碼來源:NotificationUtils.java

示例2: getPlayerText

import android.content.Context; //導入方法依賴的package包/類
@NonNull
public static String getPlayerText(Context context, int player) {
    String text;
    switch (player) {
        case Settings.PV_PLAYER__AndroidMediaPlayer:
            text = context.getString(R.string.VideoView_player_AndroidMediaPlayer);
            break;
        case Settings.PV_PLAYER__IjkMediaPlayer:
            text = context.getString(R.string.VideoView_player_IjkMediaPlayer);
            break;
        case Settings.PV_PLAYER__IjkExoMediaPlayer:
            text = context.getString(R.string.VideoView_player_IjkExoMediaPlayer);
            break;
        default:
            text = context.getString(R.string.N_A);
            break;
    }
    return text;
}
 
開發者ID:jiajunhui,項目名稱:PlayerBase,代碼行數:20,代碼來源:IjkVideoView.java

示例3: buildTrackType

import android.content.Context; //導入方法依賴的package包/類
private String buildTrackType(int type)
{
    Context context = getContext();
    switch (type)
    {
        case ITrackInfo.MEDIA_TRACK_TYPE_VIDEO:
            return context.getString(R.string.TrackType_video);
        case ITrackInfo.MEDIA_TRACK_TYPE_AUDIO:
            return context.getString(R.string.TrackType_audio);
        case ITrackInfo.MEDIA_TRACK_TYPE_SUBTITLE:
            return context.getString(R.string.TrackType_subtitle);
        case ITrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT:
            return context.getString(R.string.TrackType_timedtext);
        case ITrackInfo.MEDIA_TRACK_TYPE_METADATA:
            return context.getString(R.string.TrackType_metadata);
        case ITrackInfo.MEDIA_TRACK_TYPE_UNKNOWN:
        default:
            return context.getString(R.string.TrackType_unknown);
    }
}
 
開發者ID:Dreamxiaoxuan,項目名稱:AndroidTvDemo,代碼行數:21,代碼來源:IjkVideoView.java

示例4: VariableViewAdapter

import android.content.Context; //導入方法依賴的package包/類
/**
 * @param variableNameManager The name manager containing the variables.
 * @param context A context for inflating layouts.
 * @param resource The {@link TextView} layout to use when inflating items.
 */
public VariableViewAdapter(Context context, NameManager variableNameManager,
                           @LayoutRes int resource) {
    super(context, resource);

    mVariableNameManager = variableNameManager;
    mVars = mVariableNameManager.getUsedNames();

    mRenameString = context.getString(R.string.rename_variable);
    mDeleteString = context.getString(R.string.delete_variable);
    refreshVariables();
    variableNameManager.registerObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            refreshVariables();
        }
    });
}
 
開發者ID:Axe-Ishmael,項目名稱:Blockly,代碼行數:23,代碼來源:BasicFieldVariableView.java

示例5: onReceive

import android.content.Context; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    final String action = intent.getAction();
    LogUtils.i(TAG, "onReceive action : " + action);
    BaseControlActivity baseControlActivity = mReference.get();
    if (baseControlActivity != null) {
        if (action.equals(MusicServiceConstants.QUEUE_CHANGED)) {
            if (baseControlActivity.shouldShowControls()) {
                baseControlActivity.showPlaybackControls();
            } else {
                baseControlActivity.hidePlaybackControls();
            }
        } else if (action.equals(MusicServiceConstants.META_CHANGED)) {
            baseControlActivity.onMetaChanged();
        } else if (action.equals(MusicServiceConstants.PLAYSTATE_CHANGED)) {
            baseControlActivity.mControlFragment.updateState();
        } else if (action.equals(MusicServiceConstants.REFRESH)) {
            //refresh data
            baseControlActivity.refreshData();
        } else if (action.equals(MusicServiceConstants.PLAYLIST_CHANGED)) {
            baseControlActivity.onPlaylistChanged();
        } else if (action.equals(MusicServiceConstants.TRACK_ERROR)) {
            final String errorMsg = context.getString(R.string.error_playing_track,
                    intent.getStringExtra(MusicServiceConstants.TRACK_NAME));
            Toast.makeText(baseControlActivity, errorMsg, Toast.LENGTH_SHORT).show();
        }
    }
}
 
開發者ID:komamj,項目名稱:KomaMusic,代碼行數:32,代碼來源:BaseControlActivity.java

示例6: getPlayRecordType

import android.content.Context; //導入方法依賴的package包/類
public static String getPlayRecordType(Context context, PlayRecord record, long btime) {
    if (record == null) {
        return null;
    }
    String loadingStr;
    if (record.playedDuration <= 0 || record.playedDuration == btime) {
        loadingStr = TipUtils.getTipMessage(DialogMsgConstantId.ON_LOADING, R.string.player_loading);
    } else {
        String defaultMsg = context.getString(R.string.play_record_loading_tag);
        String msg = TipUtils.getTipMessage("100072", defaultMsg);
        if (!msg.contains("%s")) {
            msg = defaultMsg;
        }
        loadingStr = String.format(msg, new Object[]{StringUtils.stringForTimeNoHour(record.playedDuration * 1000)});
    }
    return loadingStr;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:LetvUtils.java

示例7: getLastNotificationTimeInMillis

import android.content.Context; //導入方法依賴的package包/類
/**
 * Returns the last time that a notification was shown (in UNIX time)
 *
 * @param context Used to access SharedPreferences
 * @return UNIX time of when the last notification was shown
 */
public static long getLastNotificationTimeInMillis(Context context) {
    /* Key for accessing the time at which Sunshine last displayed a notification */
    String lastNotificationKey = context.getString(R.string.pref_last_notification);

    /* As usual, we use the default SharedPreferences to access the user's preferences */
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    /*
     * Here, we retrieve the time in milliseconds when the last notification was shown. If
     * SharedPreferences doesn't have a value for lastNotificationKey, we return 0. The reason
     * we return 0 is because we compare the value returned from this method to the current
     * system time. If the difference between the last notification time and the current time
     * is greater than one day, we will show a notification again. When we compare the two
     * values, we subtract the last notification time from the current system time. If the
     * time of the last notification was 0, the difference will always be greater than the
     * number of milliseconds in a day and we will show another notification.
     */
    long lastNotificationTime = sp.getLong(lastNotificationKey, 0);

    return lastNotificationTime;
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:28,代碼來源:SunshinePreferences.java

示例8: loadTitlePref

import android.content.Context; //導入方法依賴的package包/類
static String loadTitlePref(Context context, int appWidgetId) {
    SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
    String titleValue = prefs.getString(PREF_PREFIX_KEY + appWidgetId, null);
    if (titleValue != null) {
        return titleValue;
    } else {
        return context.getString(R.string.appwidget_text);
    }
}
 
開發者ID:UTN-FRBA-Mobile,項目名稱:Clases-2017c1,代碼行數:10,代碼來源:HiAppWidgetConfigureActivity.java

示例9: getValue

import android.content.Context; //導入方法依賴的package包/類
public String getValue(Context context) {
	if (type == Attribute.TYPE_CHECKBOX) {
		String[] values = listValues != null ? listValues.split(";") : null;
		boolean checked = Boolean.valueOf(value);
		if (values != null && values.length > 1) {
			return values[checked ? 0 : 1];
		}
		return checked ? context.getString(R.string.checkbox_values_yes) : context.getString(R.string.checkbox_values_no);
	} else {
		return value;
	}
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:13,代碼來源:TransactionAttributeInfo.java

示例10: Visoes

import android.content.Context; //導入方法依賴的package包/類
public Visoes(Context c) {

        this.mContext = c;

        vTitulos[0] = c.getString(R.string.d_028);
        vTitulos[1] = c.getString(R.string.c_017);
        vTitulos[2] = c.getString(R.string.a_018);
        vTitulos[3] = c.getString(R.string.p_016);
        vTitulos[4] = c.getString(R.string.a_019);
        vTitulos[5] = c.getString(R.string.a_020);
        vTitulos[6] = c.getString(R.string.m_005);
        vTitulos[7] = c.getString(R.string.m_006);
        vTitulos[8] = c.getString(R.string.m_007);
        vTitulos[9] = c.getString(R.string.v_021);
        vTitulos[10] = c.getString(R.string.a_016);
        vTitulos[11] = c.getString(R.string.r_010);
        vTitulos[12] = c.getString(R.string.s_016);
        vTitulos[13] = c.getString(R.string.m_008);
        vTitulos[14] = c.getString(R.string.m_009);
        vTitulos[15] = c.getString(R.string.m_010);
        vTitulos[16] = c.getString(R.string.c_018);
        vTitulos[17] = c.getString(R.string.a_017);
        vTitulos[18] = c.getString(R.string.p_020);
        vTitulos[19] = c.getString(R.string.s_015);
        vTitulos[20] = c.getString(R.string.p_021);
        vTitulos[21] = c.getString(R.string.p_022);
        vTitulos[22] = c.getString(R.string.c_019);
        vTitulos[23] = c.getString(R.string.v_023);
        vTitulos[24] = c.getString(R.string.p_023);
        vTitulos[25] = c.getString(R.string.p_024);
        vTitulos[26] = c.getString(R.string.c_020);
        vTitulos[27] = c.getString(R.string.v_024);
    }
 
開發者ID:marcelohanel,項目名稱:Cash,代碼行數:34,代碼來源:Visoes.java

示例11: getString

import android.content.Context; //導入方法依賴的package包/類
static String getString(Context ctx, int whichString) {
    whichString = whichString >= 0 && whichString < RES_IDS.length ? whichString : 0;
    int resId = RES_IDS[whichString];
    try {
        return ctx.getString(resId);
    } catch (Exception ex) {
        ex.printStackTrace();
        Log.w(GameHelper.TAG, "*** GameHelper could not found resource id #" + resId + ". " +
            "This probably happened because you included it as a stand-alone JAR. " +
            "BaseGameUtils should be compiled as a LIBRARY PROJECT, so that it can access " +
            "its resources. Using a fallback string.");
        return FALLBACK_STRINGS[whichString];
    }
}
 
開發者ID:MartensCedric,項目名稱:Hexpert,代碼行數:15,代碼來源:GameHelperUtils.java

示例12: getString

import android.content.Context; //導入方法依賴的package包/類
public String getString(Context ctx) {
    if (str == null) {
        if (rStr == 0xffffffff) {
            return "";
        }
        return ctx.getString(rStr);
    } else {
        return str;
    }
}
 
開發者ID:worldiety,項目名稱:homunculus,代碼行數:11,代碼來源:Str.java

示例13: getGoSettingsMessage

import android.content.Context; //導入方法依賴的package包/類
public static String getGoSettingsMessage(Context context, String permission) {
    String message;

    switch (permission) {
        case Manifest.permission.CAMERA:
            message = context.getString(R.string.permission_android_permission_CAMERA);
            break;

        case Manifest.permission.READ_EXTERNAL_STORAGE:
            message = context.getString(R.string.permission_android_permission_READ_EXTERNAL_STORAGE);
            break;

        case Manifest.permission.WRITE_EXTERNAL_STORAGE:
            message = context.getString(R.string.permission_android_permission_WRITE_EXTERNAL_STORAGE);
            break;

        case Manifest.permission.READ_CONTACTS:
            message = context.getString(R.string.permission_android_permission_READ_CONTACTS);
            break;

        case Manifest.permission.WRITE_CONTACTS:
            message = context.getString(R.string.permission_android_permission_WRITE_CONTACTS);
            break;

        case Manifest.permission.READ_CALENDAR:
            message = context.getString(R.string.permission_android_permission_READ_CALENDAR);
            break;

        case Manifest.permission.WRITE_CALENDAR:
            message = context.getString(R.string.permission_android_permission_WRITE_CALENDAR);
            break;

        case Manifest.permission.ACCESS_COARSE_LOCATION:
            message = context.getString(R.string.permission_android_permission_ACCESS_COARSE_LOCATION);
            break;

        case Manifest.permission.ACCESS_FINE_LOCATION:
            message = context.getString(R.string.permission_android_permission_ACCESS_FINE_LOCATION);
            break;

        default:
            message = context.getString(R.string.permission_default_message);
            break;
    }

    return message;
}
 
開發者ID:lolucosmin,項目名稱:PermissionsWrapper,代碼行數:48,代碼來源:PermissionUtils.java

示例14: onCommandResult

import android.content.Context; //導入方法依賴的package包/類
@Override
public void onCommandResult(Context context, MiPushCommandMessage message) {
    Log.v(MyApplication.TAG,
            "onCommandResult is called. " + message.toString());
    String command = message.getCommand();
    List<String> arguments = message.getCommandArguments();
    String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
    String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
    String log;
    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mRegId = cmdArg1;
            log = context.getString(R.string.register_success);
        } else {
            log = context.getString(R.string.register_fail);
        }
    } else if (MiPushClient.COMMAND_SET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
            log = context.getString(R.string.set_alias_success, mAlias);
        } else {
            log = context.getString(R.string.set_alias_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_UNSET_ALIAS.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAlias = cmdArg1;
            log = context.getString(R.string.unset_alias_success, mAlias);
        } else {
            log = context.getString(R.string.unset_alias_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_SET_ACCOUNT.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAccount = cmdArg1;
            log = context.getString(R.string.set_account_success, mAccount);
        } else {
            log = context.getString(R.string.set_account_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_UNSET_ACCOUNT.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mAccount = cmdArg1;
            log = context.getString(R.string.unset_account_success, mAccount);
        } else {
            log = context.getString(R.string.unset_account_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_SUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
            log = context.getString(R.string.subscribe_topic_success, mTopic);
        } else {
            log = context.getString(R.string.subscribe_topic_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_UNSUBSCRIBE_TOPIC.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mTopic = cmdArg1;
            log = context.getString(R.string.unsubscribe_topic_success, mTopic);
        } else {
            log = context.getString(R.string.unsubscribe_topic_fail, message.getReason());
        }
    } else if (MiPushClient.COMMAND_SET_ACCEPT_TIME.equals(command)) {
        if (message.getResultCode() == ErrorCode.SUCCESS) {
            mStartTime = cmdArg1;
            mEndTime = cmdArg2;
            log = context.getString(R.string.set_accept_time_success, mStartTime, mEndTime);
        } else {
            log = context.getString(R.string.set_accept_time_fail, message.getReason());
        }
    } else {
        log = message.getReason();
    }
    MainActivity.logList.add(0, getSimpleDate() + "    " + log);

    Message msg = Message.obtain();
    msg.obj = log;
    MyApplication.getHandler().sendMessage(msg);
}
 
開發者ID:liuyongfeng90,項目名稱:JKCloud,代碼行數:76,代碼來源:MessageReceiver.java

示例15: onBindHolder

import android.content.Context; //導入方法依賴的package包/類
@Override
public void onBindHolder(final PlaylistHolder holder, final int position) {

    final MusicBean bean = mValues.get(position);

    final Context context = holder.tvTitle.getContext();

    String unknown = "未知";
    String count = "首 ";
    if (null != context) {
        unknown = context.getString(R.string.unknown);
        count = context.getString(R.string.songs_count,bean.getAlbum());

        holder.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public void onMenuItemClick(int menuPosition) {
                final PlaylistModel model = new PlaylistModel(context);

                final ArrayList<MusicBean> list = (ArrayList<MusicBean>) model.loadPlaylist((int) bean.getDuration());
                if (menuPosition == 0) {
                    MusicPlayerService.startActionSet(context, list, 0);
                    MusicPlayerService.startActionPlay(context, true);
                } else {
                    AlertUtil.showDeletePlaylistDialog(context, new OnDeleteListener() {
                        @Override
                        public void onDelete(boolean isDeleteOnDisk) {
                            int playlistID = (int) bean.getDuration();
                            if (playlistID > 0) {
                                model.deletePlaylist(playlistID);
                                mValues.remove(position);
                                notifyItemRemoved(position);
                            } else {
                                Snackbar.make(holder.iv,R.string.cannot_delete_favorite,Snackbar.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
            }
        });
    } else {
        count = bean.getAlbum()+count;
    }

    String title = bean.getName() == null ? unknown : bean.getName();

    holder.setTitle(title);

    holder.tvTitle.setText(title);
    holder.tvContent.setText(count);
}
 
開發者ID:piyell,項目名稱:NeteaseCloudMusic,代碼行數:51,代碼來源:PlaylistAdapter.java


注:本文中的android.content.Context.getString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。