android.content.SharedPreferences#edit ( )源码实例Demo

下面列出了android.content.SharedPreferences#edit ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

GameState(GameStarter gs, Context context){
    // This initializes the gameStarter reference
    gameStarter = gs;

    // Get the current high score
    SharedPreferences prefs;
    prefs = context.getSharedPreferences("HiScore",
            Context.MODE_PRIVATE);

    // Initialize the mEditor ready
    mEditor = prefs.edit();

    // Load high score from a entry in the file
    //  labeled "hiscore"
    // if not available highscore set to zero 0
    mHighScore = prefs.getInt("hi_score", 0);
}
 
源代码2 项目: MegviiFacepp-Android-SDK   文件: SharedUtil.java
public void saveStringValue(String key, String value) {
	SharedPreferences sharePre = ctx.getSharedPreferences(FileName,
			Context.MODE_PRIVATE);
	SharedPreferences.Editor editor = sharePre.edit();
	editor.putString(key, value);
	editor.commit();
}
 
源代码3 项目: RxJava2RetrofitDemo   文件: SPUtils.java
/**
 * 移除某个key值已经对应的值
 */
public static void remove(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.remove(key);
    SharedPreferencesCompat.apply(editor);
}
 
synchronized public static void incrementChargingReminderCount(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    int chargingReminders = prefs.getInt(KEY_CHARGING_REMINDER_COUNT, DEFAULT_COUNT);

    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(KEY_CHARGING_REMINDER_COUNT, ++chargingReminders);
    editor.apply();
}
 
源代码5 项目: Cybernet-VPN   文件: ProfileManager.java
public void saveProfileList(Context context) {
    SharedPreferences sharedprefs = context.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE);
    Editor editor = sharedprefs.edit();
    editor.putStringSet("vpnlist", profiles.keySet());
    // For reasing I do not understand at all
    // Android saves my prefs file only one time
    // if I remove the debug code below :(
    int counter = sharedprefs.getInt("counter", 0);
    editor.putInt("counter", counter + 1);
    editor.apply();
}
 
源代码6 项目: android-fido   文件: Fido2DemoActivity.java
private void saveAccountSignInStatus() {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean(Constants.PREF_SIGNED_IN_STATUS, true);
    Log.d(TAG, "Save account sign in status: true");
    editor.apply();
}
 
源代码7 项目: TelePlus-Android   文件: SharedConfig.java
public static void toogleRaiseToSpeak()
{
    raiseToSpeak = !raiseToSpeak;
    SharedPreferences preferences = MessagesController.getGlobalMainSettings();
    SharedPreferences.Editor editor = preferences.edit();
    editor.putBoolean("raise_to_speak", raiseToSpeak);
    editor.commit();
}
 
源代码8 项目: AnotherRSS   文件: PreferencesActivity.java
static public boolean storeArray(boolean[] array, String arrayName, Context mContext) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(arrayName +"_size", array.length);
    for(int i=0;i<array.length;i++)
        editor.putBoolean(arrayName + "_" + i, array[i]);
    return editor.commit();
}
 
源代码9 项目: your-local-weather   文件: StartupReceiver.java
private void removeOldPreferences(Context context) {
    SharedPreferences mSharedPreferences = context.getSharedPreferences(Constants.APP_SETTINGS_NAME,
            Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = mSharedPreferences.edit();
    editor.remove(Constants.APP_SETTINGS_ADDRESS_FOUND);
    editor.remove(Constants.APP_SETTINGS_GEO_CITY);
    editor.remove(Constants.APP_SETTINGS_GEO_COUNTRY_NAME);
    editor.remove(Constants.APP_SETTINGS_GEO_DISTRICT_OF_COUNTRY);
    editor.remove(Constants.APP_SETTINGS_GEO_DISTRICT_OF_CITY);
    editor.remove(Constants.LAST_UPDATE_TIME_IN_MS);
    editor.remove(Constants.APP_SETTINGS_CITY);
    editor.remove(Constants.APP_SETTINGS_COUNTRY_CODE);
    editor.remove(Constants.WEATHER_DATA_WEATHER_ID);
    editor.remove(Constants.WEATHER_DATA_TEMPERATURE);
    editor.remove(Constants.WEATHER_DATA_DESCRIPTION);
    editor.remove(Constants.WEATHER_DATA_PRESSURE);
    editor.remove(Constants.WEATHER_DATA_HUMIDITY);
    editor.remove(Constants.WEATHER_DATA_WIND_SPEED);
    editor.remove(Constants.WEATHER_DATA_CLOUDS);
    editor.remove(Constants.WEATHER_DATA_ICON);
    editor.remove(Constants.WEATHER_DATA_SUNRISE);
    editor.remove(Constants.WEATHER_DATA_SUNSET);
    editor.remove(Constants.APP_SETTINGS_LATITUDE);
    editor.remove(Constants.APP_SETTINGS_LONGITUDE);
    editor.remove(Constants.LAST_FORECAST_UPDATE_TIME_IN_MS);
    editor.remove(Constants.KEY_PREF_UPDATE_DETAIL);
    editor.remove(Constants.APP_SETTINGS_UPDATE_SOURCE);
    editor.remove(Constants.APP_SETTINGS_LOCATION_ACCURACY);
    editor.remove(Constants.LAST_LOCATION_UPDATE_TIME_IN_MS);
    editor.remove(Constants.LAST_WEATHER_UPDATE_TIME_IN_MS);
    editor.remove(Constants.KEY_PREF_LOCATION_UPDATE_STRATEGY);
    editor.remove("daily_forecast");
    editor.commit();
    context.getSharedPreferences(Constants.PREF_WEATHER_NAME,
            Context.MODE_PRIVATE).edit().clear().commit();
}
 
源代码10 项目: habpanelviewer   文件: IntroActivity.java
@Override
public void onDonePressed(Fragment currentFragment) {
    super.onDonePressed(currentFragment);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    if (!prefs.getBoolean(Constants.PREF_INTRO_SHOWN, false)) {
        SharedPreferences.Editor editor1 = prefs.edit();
        editor1.putBoolean(Constants.PREF_INTRO_SHOWN, true);
        editor1.apply();
    }
    finish();
}
 
源代码11 项目: android-robocar   文件: GameControllerActivity.java
@Override
public void onResume() {
    super.onResume();
    SharedPreferences sp = getSharedPreferences("ui-resources", 0);
    SharedPreferences.Editor spe = sp.edit();
    String baseUrl = sp.getString("webserviceUrl", "");
    if (baseUrl != null && !baseUrl.isEmpty())
        this.webserviceUrlTextView.setText(baseUrl);
}
 
源代码12 项目: security-samples   文件: Fido2DemoActivity.java
private void clearAccountSignInStatus() {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean(Constants.PREF_SIGNED_IN_STATUS, false);
    Log.d(TAG, "Clear account sign in status");
    editor.apply();
}
 
源代码13 项目: Paddle-Lite-Demo   文件: SettingsActivity.java
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY))) {
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(getString(R.string.ENABLE_CUSTOM_SETTINGS_KEY), false);
        editor.commit();
    }
    reloadPreferenceAndUpdateUI();
}
 
源代码14 项目: WanAndroid   文件: SharedPreferenceUtils.java
public static boolean putData(String filename, String key, long value) {
    SharedPreferences sharedPreferences = WanAndroidApplication.getMyApplication().getSharedPreferences(filename, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putLong(key, value);
    return editor.commit();
}
 
源代码15 项目: MeetMusic   文件: MyMusicUtil.java
public static void setBingShared(String value){
    SharedPreferences pref = MyApplication.getContext().getSharedPreferences("bing_pic",MyApplication.getContext().MODE_PRIVATE);
    SharedPreferences.Editor editor = pref.edit();
    editor.putString("pic", value);
    editor.commit();
}
 
synchronized private static void setWaterCount(Context context, int glassesOfWater) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(KEY_WATER_COUNT, glassesOfWater);
    editor.apply();
}
 
源代码17 项目: styT   文件: SpUtil.java
/**
 * 保存long值
 *
 * @param context 上下文
 * @param key     键
 * @param value   值
 */
public static void putLong(Context context, String key, long value) {
    SharedPreferences sp = getSp(context);
    Editor editor = sp.edit();
    editor.putLong(key, value);
    editor.apply();
}
 
/**
 * Helper method to handle setting location details in Preferences (city name, latitude,
 * longitude)
 * <p>
 * When the location details are updated, the database should to be cleared.
 *
 * @param context  Context used to get the SharedPreferences
 * @param lat      the latitude of the city
 * @param lon      the longitude of the city
 */
public static void setLocationDetails(Context context, double lat, double lon) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sp.edit();

    editor.putLong(PREF_COORD_LAT, Double.doubleToRawLongBits(lat));
    editor.putLong(PREF_COORD_LONG, Double.doubleToRawLongBits(lon));
    editor.apply();
}
 
源代码19 项目: java-n-IDE-for-Android   文件: PreferenceHelper.java
public static void setWidgetExistsPreference(Context context, int[] appWidgetIds) {

        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

        Editor editor = sharedPrefs.edit();

        for (int appWidgetId : appWidgetIds) {
            String widgetExists = WIDGET_EXISTS_PREFIX.concat(Integer.toString(appWidgetId));
            editor.putBoolean(widgetExists, true);
        }

        editor.commit();


    }
 
源代码20 项目: styT   文件: SpUtil.java
/**
 * 保存int值
 *
 * @param context 上下文
 * @param key     键
 * @param value   值
 */
public static void putInt(Context context, String key, int value) {
    SharedPreferences sp = getSp(context);
    Editor editor = sp.edit();
    editor.putInt(key, value);
    editor.apply();
}