当前位置: 首页>>代码示例>>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;未经允许,请勿转载。