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

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

源代码1 项目: a   文件: SharedPreferencesUtil.java
/**
 * 保存数据到文件
 *
 * @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();
}
 
源代码2 项目: HaoReader   文件: SharedPreferencesUtil.java
/**
 * 保存数据到文件
 *
 * @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();
}
 
源代码3 项目: dcs-sdk-java   文件: PreferenceUtil.java
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);
}
 
源代码4 项目: letv   文件: e.java
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();
}
 
源代码5 项目: CSipSimple   文件: CallHandlerPlugin.java
/**
 * 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;
}
 
源代码6 项目: LeisureRead   文件: PreferenceUtils.java
public static void putLong(String key, long value) {

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(
        LeisureReadApp.getAppContext());
    Editor editor = sharedPreferences.edit();
    editor.putLong(key, value);
    editor.commit();
  }
 
源代码7 项目: BigApp_Discuz_Android   文件: PreferencesHelper.java
/** 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();
}
 
源代码8 项目: QiQuYing   文件: AccessTokenKeeper.java
/**
 * 保存 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();
}
 
源代码9 项目: HeroVideo-master   文件: PreferenceUtil.java
public static void putLong(String key, long value)
{

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(HeroVideoApp.getInstance());
    Editor editor = sharedPreferences.edit();
    editor.putLong(key, value);
    editor.apply();
}
 
源代码10 项目: PS4-Payload-Sender-Android   文件: Prefs.java
/**
 * 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();
    }
}
 
源代码11 项目: BiliShare   文件: AccessTokenKeeper.java
/**
 * 保存 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();
}
 
源代码12 项目: mytracks   文件: PreferencesUtils.java
/**
 * 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);
}
 
源代码13 项目: AssistantBySDK   文件: AccessTokenKeeper.java
/**
 * 保存 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();
}
 
源代码14 项目: BigApp_Discuz_Android   文件: PreferencesHelper.java
/** 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();
}
 
源代码15 项目: letv   文件: z.java
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);
    }
}
 
源代码16 项目: zulip-android   文件: Notifications.java
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();
}
 
源代码17 项目: PhoneProfilesPlus   文件: Event.java
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();
}
 
源代码18 项目: mytracks   文件: PreferenceBackupHelper.java
/**
 * 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;
  }
}
 
源代码19 项目: letv   文件: f.java
protected static void a(String str, long j) {
    Editor edit = a.edit();
    edit.putLong(str, j);
    edit.apply();
}
 
源代码20 项目: 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();
}