android.content.SharedPreferences.Editor Java Examples
The following examples show how to use
android.content.SharedPreferences.Editor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrecacheUMA.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Record the precache event. The event is persisted in shared preferences if the native library * is not loaded. If library is loaded, the event will be recorded as UMA metric, and any prior * persisted events are recorded to UMA as well. * @param event the precache event. */ public static void record(int event) { SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences(); long persistent_metric = sharedPreferences.getLong(PREF_PERSISTENCE_METRICS, 0); Editor preferencesEditor = sharedPreferences.edit(); if (LibraryLoader.isInitialized()) { RecordHistogram.recordEnumeratedHistogram( EVENTS_HISTOGRAM, Event.getBitPosition(event), Event.EVENT_END); for (int e : Event.getEventsFromBitMask(persistent_metric)) { RecordHistogram.recordEnumeratedHistogram( EVENTS_HISTOGRAM, Event.getBitPosition(e), Event.EVENT_END); } preferencesEditor.remove(PREF_PERSISTENCE_METRICS); } else { // Save the metric in preferences. persistent_metric = Event.addEventToBitMask(persistent_metric, event); preferencesEditor.putLong(PREF_PERSISTENCE_METRICS, persistent_metric); } preferencesEditor.apply(); }
Example #2
Source File: UninstalledObserver.java From letv with Apache License 2.0 | 6 votes |
private static String getUrlAddParamer(String url, Context context) { SharedPreferences setting = context.getSharedPreferences(TAG, 0); if (!setting.getBoolean("isInit", false)) { try { Editor edit = setting.edit(); edit.putString(VERSION_NAME, context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName); edit.putString(MODEL, Build.MODEL); edit.putString("version", VERSION.RELEASE); edit.putString("url", url); edit.putBoolean("isInit", true); edit.commit(); } catch (Exception e) { e.printStackTrace(); } } StringBuilder builder = new StringBuilder(url); builder.append("&model=" + setting.getString(MODEL, "")); builder.append("&os=android" + setting.getString("version", "")); builder.append("&version=" + setting.getString(VERSION_NAME, "")); return builder.toString(); }
Example #3
Source File: SPUtil.java From FastLib with Apache License 2.0 | 6 votes |
/** * 存放object * * @param context * @param fileName * @param key * @param object * @return */ public static boolean put(Context context, String fileName, String key, Object object) { SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); Editor editor = sp.edit(); if (object instanceof String) { editor.putString(key, (String) object); } else if (object instanceof Integer) { editor.putInt(key, ((Integer) object).intValue()); } else if (object instanceof Boolean) { editor.putBoolean(key, ((Boolean) object).booleanValue()); } else if (object instanceof Float) { editor.putFloat(key, ((Float) object).floatValue()); } else if (object instanceof Long) { editor.putLong(key, ((Long) object).longValue()); } else if (object instanceof Set) { editor.putStringSet(key, (Set<String>) object); } else { editor.putStringSet(key, (Set<String>) object); } return editor.commit(); }
Example #4
Source File: SPUtil.java From UIWidget with Apache License 2.0 | 6 votes |
/** * 存放object * * @param context * @param fileName * @param key * @param object * @return */ public static boolean put(Context context, String fileName, String key, Object object) { SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); Editor editor = sp.edit(); if (object instanceof String) { editor.putString(key, (String) object); } else if (object instanceof Integer) { editor.putInt(key, ((Integer) object).intValue()); } else if (object instanceof Boolean) { editor.putBoolean(key, ((Boolean) object).booleanValue()); } else if (object instanceof Float) { editor.putFloat(key, ((Float) object).floatValue()); } else if (object instanceof Long) { editor.putLong(key, ((Long) object).longValue()); } else if (object instanceof Set) { editor.putStringSet(key, (Set<String>) object); } else { editor.putStringSet(key, (Set<String>) object); } return editor.commit(); }
Example #5
Source File: SharedPreUtils.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
public static void setString(Context context, String key, String value) { SharedPreferences sp = context.getSharedPreferences( SHARED_PREFERANCE_NAME, Context.MODE_PRIVATE); Editor editor = sp.edit(); editor.putString(key, value); editor.commit(); }
Example #6
Source File: Prefs.java From PS4-Payload-Sender-Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param key The name of the preference to modify. * @param value The new value for the preference. * @see Editor#putFloat(String, float) */ public static void putFloat(final String key, final float value) { final Editor editor = getPreferences().edit(); editor.putFloat(key, value); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { editor.commit(); } else { editor.apply(); } }
Example #7
Source File: PreferenceUtils.java From LeisureRead with Apache License 2.0 | 5 votes |
public static void putStringProcess(String key, String value) { SharedPreferences sharedPreferences = LeisureReadApp.getAppContext() .getSharedPreferences("preference_mu", Context.MODE_MULTI_PROCESS); Editor editor = sharedPreferences.edit(); editor.putString(key, value); editor.commit(); }
Example #8
Source File: SpUtil.java From styT with Apache License 2.0 | 5 votes |
public static boolean rray(Context context, List<String> list) { SharedPreferences sp = context.getSharedPreferences("ingoreList", Context.MODE_PRIVATE); SharedPreferences.Editor mEdit1 = sp.edit(); mEdit1.putInt("Status_size", list.size()); for (int i = 0; i < list.size(); i++) { mEdit1.remove("Status_" + i); mEdit1.putString("Status_" + i, list.get(i)); } return mEdit1.commit(); }
Example #9
Source File: PreferencesHelper.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
/** save session time */ public void setAppStartDate() { SharedPreferences preferences2sessiontime = context.getSharedPreferences("mobclick_agent_state_" + packageName, preferenceMode); Editor editor = preferences2sessiontime.edit(); Date date = new Date(); SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateStr = localSimpleDateFormat.format(date); editor.putString("app_start_date", dateStr); editor.commit(); }
Example #10
Source File: IRVideo.java From letv with Apache License 2.0 | 5 votes |
public void init(Context context, String str) { if (str == null || str.trim().length() <= 0) { throw new RuntimeException("please fill the value"); } Context applicationContext = context.getApplicationContext(); a(applicationContext); Editor edit = applicationContext.getSharedPreferences("VV_Tracker", 0).edit(); edit.putString("vv_uaid", str); try { edit.apply(); } catch (Exception e) { edit.commit(); e.printStackTrace(); } }
Example #11
Source File: SharedPreUtils.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
public static void setInteger(Context context, String key, int value) { SharedPreferences sp = context.getSharedPreferences( SHARED_PREFERANCE_NAME, Context.MODE_PRIVATE); Editor editor = sp.edit(); editor.putInt(key, value); editor.commit(); }
Example #12
Source File: ApplicationContext.java From azure-notificationhubs-android with Apache License 2.0 | 5 votes |
public static void clearNotificationHubStorageData() { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); Editor editor = sharedPreferences.edit(); Set<String> keys = sharedPreferences.getAll().keySet(); for (String key : keys) { if (key.startsWith("__NH_")) { editor.remove(key); } } editor.commit(); }
Example #13
Source File: PreferenceUtil.java From dcs-sdk-java with Apache License 2.0 | 5 votes |
private static void editSubmit(Editor editor) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { editor.apply(); } else { editor.commit(); } }
Example #14
Source File: ZulipApp.java From zulip-android with Apache License 2.0 | 5 votes |
public void setLoggedInApiKey(String apiKey, String email) { this.api_key = apiKey; Editor ed = this.settings.edit(); ed.putString(EMAIL, email); ed.putString(API_KEY, apiKey); ed.apply(); afterLogin(); }
Example #15
Source File: CommonUtils.java From product-emm with Apache License 2.0 | 5 votes |
/** * Clear client credentials. * @param context - Application context. */ public static void clearClientCredentials(Context context) { SharedPreferences mainPref = context.getSharedPreferences(Constants.PACKAGE_NAME, Context.MODE_PRIVATE); Editor editor = mainPref.edit(); editor.putString(Constants.CLIENT_ID, null); editor.putString(Constants.CLIENT_SECRET, null); editor.apply(); }
Example #16
Source File: Main.java From JotaTextEditor with Apache License 2.0 | 5 votes |
private void saveHistory() { if (mInstanceState.filename != null) { int selstart = mEditor.getSelectionStart(); int selend = mEditor.getSelectionEnd(); SharedPreferences sp = getSharedPreferences(SettingsActivity.PREF_HISTORY, MODE_PRIVATE); Editor editor = sp.edit(); editor.putString(mInstanceState.filename, String.format("%d,%d,%d", selstart, selend, System.currentTimeMillis())); editor.commit(); } }
Example #17
Source File: IdentityKeyUtil.java From bcm-android with GNU General Public License v3.0 | 5 votes |
private static void save(@NonNull AccountContext accountContext, String key, String value) { Context context = AppContextHolder.APP_CONTEXT; SharedPreferences preferences = context.getSharedPreferences(MasterSecretUtil.getPreferencesName(accountContext), 0); Editor preferencesEditor = preferences.edit(); preferencesEditor.putString(key, value); if (!preferencesEditor.commit()) { throw new AssertionError("failed to save identity key/value to shared preferences"); } }
Example #18
Source File: UserRepository.java From OpenYOLO-Android with Apache License 2.0 | 5 votes |
private void setCurrentUserEmail(@Nullable String email) { Editor editor = mSharedPrefs.edit(); if (email == null) { editor.remove(KEY_CURRENT_USER); } else { editor.putString(KEY_CURRENT_USER, email); } editor.apply(); }
Example #19
Source File: SimpleSharedPreferences.java From MVPAndroidBootstrap with Apache License 2.0 | 5 votes |
@Override public Editor putBoolean(String key, boolean value) { initAndEdit(); mEditor.putBoolean(key, value); commit(); return this; }
Example #20
Source File: PreferenceHelper.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
public static void setLogLinePeriodPreference(Context context, int value) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = sharedPrefs.edit(); editor.putString(context.getText(R.string.pref_log_line_period).toString(), Integer.toString(value)); editor.commit(); }
Example #21
Source File: PreferenceHelper.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
public static void setIncludeDeviceInfoPreference(Context context, boolean value) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = sharedPrefs.edit(); editor.putBoolean(context.getString(R.string.pref_include_device_info), value); editor.apply(); }
Example #22
Source File: BaseApplication.java From Cotable with Apache License 2.0 | 5 votes |
/** * Save the display size of Activity. * * @param activity an activity */ public static void saveDisplaySize(Activity activity) { DisplayMetrics displaymetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay() .getMetrics(displaymetrics); Editor editor = getPreferences().edit(); editor.putInt("screen_width", displaymetrics.widthPixels); editor.putInt("screen_height", displaymetrics.heightPixels); editor.putFloat("density", displaymetrics.density); apply(editor); TLog.log("", "Resolution:" + displaymetrics.widthPixels + " x " + displaymetrics.heightPixels + " DisplayMetrics:" + displaymetrics.density + " " + displaymetrics.densityDpi); }
Example #23
Source File: SimpleSharedPreferences.java From MVPAndroidBootstrap with Apache License 2.0 | 5 votes |
@Override public Editor putString(String key, String value) { initAndEdit(); mEditor.putString(key, value); commit(); return this; }
Example #24
Source File: Prefs.java From PS4-Payload-Sender-Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param key The name of the preference to modify. * @param value The new value for the preference. * @see Editor#putBoolean(String, boolean) */ public static void putBoolean(final String key, final boolean value) { final Editor editor = getPreferences().edit(); editor.putBoolean(key, value); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { editor.commit(); } else { editor.apply(); } }
Example #25
Source File: PreferencesManager.java From letv with Apache License 2.0 | 5 votes |
public boolean saveLatestLaunchTime() { long t = System.currentTimeMillis(); String date = StringUtils.timeString(t); String minutes = StringUtils.timeStringByMinutes(t); SharedPreferences sp = context.getSharedPreferences(FORCE_ALERT, 0); if (sp.getLong(PREF_CURRENTTIMEMILLIS, 0) != 0 && t - sp.getLong(PREF_CURRENTTIMEMILLIS, 0) < 300000) { return false; } Editor editor = sp.edit(); editor.putLong(PREF_CURRENTTIMEMILLIS, t); editor.putString(PREF_LAUNCH_DATE, date); editor.putString(PREF_LAUNCH_MINUTE, minutes); editor.commit(); return true; }
Example #26
Source File: PreferenceHelper.java From IslamicLibraryAndroid with GNU General Public License v3.0 | 5 votes |
/** * Clear data in shared preferences.<br/> * * @param context context */ static void resetLaunchTimes(Context context) { SharedPreferences.Editor editor = getPreferencesEditor(context); editor.remove(PREF_KEY_LAUNCH_TIMES); editor.apply(); }
Example #27
Source File: SimpleSharedPreferences.java From MVPAndroidBootstrap with Apache License 2.0 | 5 votes |
@Override public Editor clear() { initAndEdit(); mEditor.clear(); commit(); return this; }
Example #28
Source File: TextFrag.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
private void saveHistory() { if (mInstanceState.filename != null) { int selstart = mEditor.getSelectionStart(); int selend = mEditor.getSelectionEnd(); SharedPreferences sp = fragActivity.getSharedPreferences(SettingsActivity.PREF_HISTORY, Activity.MODE_PRIVATE); Editor editor = sp.edit(); editor.putString(mInstanceState.filename, String.format("%d,%d,%d", selstart, selend, System.currentTimeMillis())); editor.commit(); } }
Example #29
Source File: Prefs.java From PS4-Payload-Sender-Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param key The name of the preference to modify. * @param value The new value for the preference. * @see Editor#putLong(String, long) */ public static void putLong(final String key, final long value) { final Editor editor = getPreferences().edit(); editor.putLong(key, value); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { editor.commit(); } else { editor.apply(); } }
Example #30
Source File: Preference.java From product-emm with Apache License 2.0 | 5 votes |
/** * Put data to shared preferences in private mode. * @param context - The context of activity which is requesting to put data. * @param key - Used to identify the value. * @param value - The actual value to be saved. */ public static void putFloat(Context context, String key, float value) { SharedPreferences mainPref = context.getSharedPreferences(context.getResources() .getString(R.string.shared_pref_package), Context.MODE_PRIVATE ); Editor editor = mainPref.edit(); editor.putFloat(key, value); editor.commit(); }