Java Code Examples for android.content.SharedPreferences.Editor#putLong()
The following examples show how to use
android.content.SharedPreferences.Editor#putLong() .
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: SharedPreferencesUtil.java From a with GNU General Public License v3.0 | 6 votes |
/** * 保存数据到文件 * * @param key * @param data */ public static void saveData(String key, Object data) { String type = data.getClass().getSimpleName(); Editor editor = sharedPreferences.edit(); if ("Integer".equals(type)) { editor.putInt(key, (Integer) data); } else if ("Boolean".equals(type)) { editor.putBoolean(key, (Boolean) data); } else if ("String".equals(type)) { editor.putString(key, (String) data); } else if ("Float".equals(type)) { editor.putFloat(key, (Float) data); } else if ("Long".equals(type)) { editor.putLong(key, (Long) data); } editor.apply(); }
Example 2
Source File: CallHandlerPlugin.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
/** * Retrieve internal id of call handler as saved in databases It should be * some negative < SipProfile.INVALID_ID number * * @param ctxt Application context * @param packageName name of the call handler package * @return the id of this call handler in databases */ public static Long getAccountIdForCallHandler(Context ctxt, String packageName) { SharedPreferences prefs = ctxt.getSharedPreferences("handlerCache", Context.MODE_PRIVATE); long accountId = SipProfile.INVALID_ID; try { accountId = prefs.getLong(VIRTUAL_ACC_PREFIX + packageName, SipProfile.INVALID_ID); } catch (Exception e) { Log.e(THIS_FILE, "Can't retrieve call handler cache id - reset"); } if (accountId == SipProfile.INVALID_ID) { // We never seen this one, add a new entry for account id int maxAcc = prefs.getInt(VIRTUAL_ACC_MAX_ENTRIES, 0x0); int currentEntry = maxAcc + 1; accountId = SipProfile.INVALID_ID - (long) currentEntry; Editor edt = prefs.edit(); edt.putLong(VIRTUAL_ACC_PREFIX + packageName, accountId); edt.putInt(VIRTUAL_ACC_MAX_ENTRIES, currentEntry); edt.commit(); } return accountId; }
Example 3
Source File: e.java From letv with Apache License 2.0 | 6 votes |
private static void a(String str, Object obj) { Editor edit = c.edit(); if (obj.getClass() == Boolean.class) { edit.putBoolean(str, ((Boolean) obj).booleanValue()); } if (obj.getClass() == String.class) { edit.putString(str, (String) obj); } if (obj.getClass() == Integer.class) { edit.putInt(str, ((Integer) obj).intValue()); } if (obj.getClass() == Float.class) { edit.putFloat(str, (float) ((Float) obj).intValue()); } if (obj.getClass() == Long.class) { edit.putLong(str, (long) ((Long) obj).intValue()); } edit.commit(); }
Example 4
Source File: PreferenceUtil.java From dcs-sdk-java with Apache License 2.0 | 6 votes |
public static void put(Context context, String spName, String key, Object object) { SharedPreferences sp = context.getSharedPreferences(spName, 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); } else if (object instanceof Boolean) { editor.putBoolean(key, (Boolean) object); } else if (object instanceof Float) { editor.putFloat(key, (Float) object); } else if (object instanceof Long) { editor.putLong(key, (Long) object); } else { editor.putString(key, object.toString()); } editSubmit(editor); }
Example 5
Source File: SharedPreferencesUtil.java From HaoReader with GNU General Public License v3.0 | 6 votes |
/** * 保存数据到文件 * * @param context * @param key * @param data */ public static void saveData(Context context, String key, Object data) { SharedPreferences sharedPreferences = context .getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); if (data instanceof Integer) { editor.putInt(key, (Integer) data); } else if (data instanceof Boolean) { editor.putBoolean(key, (Boolean) data); } else if (data instanceof String) { editor.putString(key, (String) data); } else if (data instanceof Float) { editor.putFloat(key, (Float) data); } else if(data instanceof Double) { editor.putFloat(key, Float.valueOf(data + "")); }else if (data instanceof Long) { editor.putLong(key, (Long) data); } editor.apply(); }
Example 6
Source File: z.java From letv with Apache License 2.0 | 5 votes |
public void f(Context context) { SharedPreferences a = x.a(context); if (a != null) { String b = b(context); Editor edit = a.edit(); edit.putString(c, b); edit.putLong(a, System.currentTimeMillis()); edit.putLong(b, 0); edit.putLong("a_start_time", System.currentTimeMillis()); edit.putLong("a_end_time", 0); edit.commit(); bv.d("Restart session: " + b); } }
Example 7
Source File: PreferenceUtils.java From LeisureRead with Apache License 2.0 | 5 votes |
public static void putLong(String key, long value) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences( LeisureReadApp.getAppContext()); Editor editor = sharedPreferences.edit(); editor.putLong(key, value); editor.commit(); }
Example 8
Source File: PreferencesHelper.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
/** save the time of post log */ public void setLastReportTime(long time) { SharedPreferences preferences = context.getSharedPreferences("mobclick_agent_state_" + packageName, preferenceMode); Editor edit = preferences.edit(); edit.putLong("last_report_time", time); edit.commit(); }
Example 9
Source File: AccessTokenKeeper.java From AssistantBySDK with Apache License 2.0 | 5 votes |
/** * 保存 Token 对象到 SharedPreferences。 * * @param context 应用程序上下文环境 * @param token Token 对象 */ public static void writeAccessToken(Context context, Oauth2AccessToken token) { if (null == context || null == token) { return; } SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND); Editor editor = pref.edit(); editor.putString(KEY_UID, token.getUid()); editor.putString(KEY_ACCESS_TOKEN, token.getToken()); editor.putLong(KEY_EXPIRES_IN, token.getExpiresTime()); editor.commit(); }
Example 10
Source File: PreferencesUtils.java From mytracks with Apache License 2.0 | 5 votes |
/** * Sets a long preference value. * * @param context the context * @param keyId the key id * @param value the value */ @SuppressLint("CommitPrefEdits") public static void setLong(Context context, int keyId, long value) { SharedPreferences sharedPreferences = context.getSharedPreferences( Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putLong(getKey(context, keyId), value); ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor); }
Example 11
Source File: AccessTokenKeeper.java From BiliShare with Apache License 2.0 | 5 votes |
/** * 保存 Token 对象到 SharedPreferences。 * * @param context 应用程序上下文环境 * @param token Token 对象 */ public static void writeAccessToken(Context context, Oauth2AccessToken token) { if (null == context || null == token) { return; } SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND); Editor editor = pref.edit(); editor.putString(KEY_UID, token.getUid()); editor.putString(KEY_ACCESS_TOKEN, token.getToken()); editor.putString(KEY_REFRESH_TOKEN, token.getRefreshToken()); editor.putLong(KEY_EXPIRES_IN, token.getExpiresTime()); editor.commit(); }
Example 12
Source File: Prefs.java From PS4-Payload-Sender-Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Saves the double as a long raw bits inside the preferences. * * @param key The name of the preference to modify. * @param value The double value to be save in the preferences. * @see Editor#putLong(String, long) */ public static void putDouble(final String key, final double value) { final Editor editor = getPreferences().edit(); editor.putLong(key, Double.doubleToRawLongBits(value)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { editor.commit(); } else { editor.apply(); } }
Example 13
Source File: PreferenceUtil.java From HeroVideo-master with Apache License 2.0 | 5 votes |
public static void putLong(String key, long value) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(HeroVideoApp.getInstance()); Editor editor = sharedPreferences.edit(); editor.putLong(key, value); editor.apply(); }
Example 14
Source File: AccessTokenKeeper.java From QiQuYing with Apache License 2.0 | 5 votes |
/** * 保存 Token 对象到 SharedPreferences。 * * @param context 应用程序上下文环境 * @param token Token 对象 */ public static void writeAccessToken(Context context, Oauth2AccessToken token) { if (null == context || null == token) { return; } SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND); Editor editor = pref.edit(); editor.putString(KEY_UID, token.getUid()); editor.putString(KEY_ACCESS_TOKEN, token.getToken()); editor.putString(KEY_REFRESH_TOKEN, token.getRefreshToken()); editor.putLong(KEY_EXPIRES_IN, token.getExpiresTime()); editor.commit(); }
Example 15
Source File: PreferencesHelper.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
/** save session time */ public void setSessionTime() { SharedPreferences preferences2sessiontime = context.getSharedPreferences("mobclick_agent_state_" + packageName, preferenceMode); Editor editor = preferences2sessiontime.edit(); long currenttime = System.currentTimeMillis(); editor.putLong("session_save_time", currenttime); editor.commit(); }
Example 16
Source File: PreferenceBackupHelper.java From mytracks with Apache License 2.0 | 4 votes |
/** * Reads a single preference and sets it into the given editor. * * @param name the name of the preference to read * @param typeId the type ID of the preference to read * @param reader the reader to read from * @param editor the editor to set the preference in * @throws IOException if there are errors while reading */ private void readAndSetPreference(String name, byte typeId, DataInputStream reader, Editor editor) throws IOException { boolean save = true; if (doNotBackup.contains(name)) { save = false; } switch (typeId) { case ContentTypeIds.BOOLEAN_TYPE_ID: boolean booleanValue = reader.readBoolean(); if (save) { editor.putBoolean(name, booleanValue); } return; case ContentTypeIds.LONG_TYPE_ID: long longValue = reader.readLong(); if (save) { editor.putLong(name, longValue); } return; case ContentTypeIds.FLOAT_TYPE_ID: float floatValue = reader.readFloat(); if (save) { editor.putFloat(name, floatValue); } return; case ContentTypeIds.INT_TYPE_ID: int intValue = reader.readInt(); if (save) { editor.putInt(name, intValue); } return; case ContentTypeIds.STRING_TYPE_ID: String utfValue = reader.readUTF(); if (save) { editor.putString(name, utfValue); } return; } }
Example 17
Source File: f.java From letv with Apache License 2.0 | 4 votes |
protected static void a(String str, long j) { Editor edit = a.edit(); edit.putLong(str, j); edit.apply(); }
Example 18
Source File: Event.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
public void loadSharedPreferences(SharedPreferences preferences) { Editor editor = preferences.edit(); editor.putLong(PREF_EVENT_ID, this._id); editor.putString(PREF_EVENT_NAME, this._name); editor.putString(PREF_EVENT_PROFILE_START, Long.toString(this._fkProfileStart)); editor.putString(PREF_EVENT_PROFILE_END, Long.toString(this._fkProfileEnd)); editor.putBoolean(PREF_EVENT_ENABLED, this._status != ESTATUS_STOP); editor.putString(PREF_EVENT_NOTIFICATION_SOUND_START, this._notificationSoundStart); editor.putBoolean(PREF_EVENT_NOTIFICATION_VIBRATE_START, this._notificationVibrateStart); editor.putBoolean(PREF_EVENT_NOTIFICATION_REPEAT_START, this._repeatNotificationStart); editor.putString(PREF_EVENT_NOTIFICATION_REPEAT_INTERVAL_START, String.valueOf(this._repeatNotificationIntervalStart)); editor.putString(PREF_EVENT_NOTIFICATION_SOUND_END, this._notificationSoundEnd); editor.putBoolean(PREF_EVENT_NOTIFICATION_VIBRATE_END, this._notificationVibrateEnd); editor.putBoolean(PREF_EVENT_FORCE_RUN, this._forceRun); //editor.putBoolean(PREF_EVENT_UNDONE_PROFILE, this._undoneProfile); editor.putString(PREF_EVENT_PRIORITY_APP_SETTINGS, Integer.toString(this._priority)); editor.putString(PREF_EVENT_PRIORITY, Integer.toString(this._priority)); editor.putString(PREF_EVENT_DELAY_START, Integer.toString(this._delayStart)); editor.putString(PREF_EVENT_AT_END_DO, Integer.toString(this._atEndDo)); editor.putBoolean(PREF_EVENT_MANUAL_PROFILE_ACTIVATION, this._manualProfileActivation); editor.putString(PREF_EVENT_START_WHEN_ACTIVATED_PROFILE, this._startWhenActivatedProfile); editor.putString(PREF_EVENT_DELAY_END, Integer.toString(this._delayEnd)); editor.putBoolean(PREF_EVENT_NO_PAUSE_BY_MANUAL_ACTIVATION, this._noPauseByManualActivation); this._eventPreferencesTime.loadSharedPreferences(preferences); this._eventPreferencesBattery.loadSharedPreferences(preferences); this._eventPreferencesCall.loadSharedPreferences(preferences); this._eventPreferencesPeripherals.loadSharedPreferences(preferences); this._eventPreferencesCalendar.loadSharedPreferences(preferences); this._eventPreferencesWifi.loadSharedPreferences(preferences); this._eventPreferencesScreen.loadSharedPreferences(preferences); this._eventPreferencesBluetooth.loadSharedPreferences(preferences); this._eventPreferencesSMS.loadSharedPreferences(preferences); this._eventPreferencesNotification.loadSharedPreferences(preferences); this._eventPreferencesApplication.loadSharedPreferences(preferences); this._eventPreferencesLocation.loadSharedPreferences(preferences); this._eventPreferencesOrientation.loadSharedPreferences(preferences); this._eventPreferencesMobileCells.loadSharedPreferences(preferences); this._eventPreferencesNFC.loadSharedPreferences(preferences); this._eventPreferencesRadioSwitch.loadSharedPreferences(preferences); this._eventPreferencesAlarmClock.loadSharedPreferences(preferences); this._eventPreferencesDeviceBoot.loadSharedPreferences(preferences); editor.apply(); }
Example 19
Source File: Notifications.java From zulip-android with Apache License 2.0 | 4 votes |
private void storeRegistrationId(Context context, String regId) { Editor ed = app.getSettings().edit(); ed.putString("gcm_reg_id", regId); ed.putLong("gcm_reg_last_version", app.getAppVersion()); ed.apply(); }
Example 20
Source File: SpUtil.java From styT with Apache License 2.0 | 3 votes |
/** * 保存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(); }