android.content.SharedPreferences.getLong()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(314)

本文整理了Java中android.content.SharedPreferences.getLong()方法的一些代码示例,展示了SharedPreferences.getLong()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SharedPreferences.getLong()方法的具体详情如下:
包路径:android.content.SharedPreferences
类名称:SharedPreferences
方法名:getLong

SharedPreferences.getLong介绍

[英]Retrieve a long value from the preferences.
[中]

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
public long getLong (String key, long defValue) {
  return sharedPrefs.getLong(key, defValue);
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getLong (String key) {
  return sharedPrefs.getLong(key, 0);
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getLong (String key, long defValue) {
  return sharedPrefs.getLong(key, defValue);
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getLong (String key) {
  return sharedPrefs.getLong(key, 0);
}

代码示例来源:origin: MindorksOpenSource/android-mvp-architecture

@Override
public Long getCurrentUserId() {
  long userId = mPrefs.getLong(PREF_KEY_CURRENT_USER_ID, AppConstants.NULL_INDEX);
  return userId == AppConstants.NULL_INDEX ? null : userId;
}

代码示例来源:origin: jgilfelt/chuck

private long getLastCleanup(long fallback) {
  if (lastCleanup == 0) {
    lastCleanup = prefs.getLong(KEY_LAST_CLEANUP, fallback);
  }
  return lastCleanup;
}

代码示例来源:origin: stackoverflow.com

double getDouble(final SharedPreferences prefs, final String key, final double defaultValue) {
if ( !prefs.contains(key))
    return defaultValue;

return Double.longBitsToDouble(prefs.getLong(key, 0));
}

代码示例来源:origin: android10/Android-CleanArchitecture

/**
  * Get a value from a user preferences file.
  *
  * @param context {@link android.content.Context} to retrieve android user preferences.
  * @param preferenceFileName A file name representing where data will be get from.
  * @param key A key that will be used to retrieve the value from the preference file.
  * @return A long representing the value retrieved from the preferences file.
  */
 long getFromPreferences(Context context, String preferenceFileName, String key) {
  final SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceFileName,
    Context.MODE_PRIVATE);
  return sharedPreferences.getLong(key, 0);
 }
}

代码示例来源:origin: stackoverflow.com

Editor putDouble(final Editor edit, final String key, final double value) {
  return edit.putLong(key, Double.doubleToRawLongBits(value));
}

double getDouble(final SharedPreferences prefs, final String key, final double defaultValue) {
return Double.longBitsToDouble(prefs.getLong(key, Double.doubleToLongBits(defaultValue)));
}

代码示例来源:origin: androidannotations/androidannotations

@Override
public Long getOr(Long defaultValue) {
  try {
    return sharedPreferences.getLong(key, defaultValue);
  } catch (ClassCastException e) {
    // The pref could be a String, if that is the case try this
    // recovery bit
    try {
      String value = sharedPreferences.getString(key, "" + defaultValue);
      return Long.parseLong(value);
    } catch (Exception e2) {
      // our recovery bit failed. The problem is elsewhere. Send the
      // original error
      throw e;
    }
  }
}

代码示例来源:origin: lipangit/JiaoZiVideoPlayer

public static long getSavedProgress(Context context, Object url) {
  if (!Jzvd.SAVE_PROGRESS) return 0;
  SharedPreferences spn = context.getSharedPreferences("JZVD_PROGRESS",
      Context.MODE_PRIVATE);
  return spn.getLong("newVersion:" + url.toString(), 0);
}

代码示例来源:origin: TeamNewPipe/NewPipe

private static float getScreenBrightness(@NonNull final Context context, final float screenBrightness) {
  SharedPreferences sp = getPreferences(context);
  long timestamp = sp.getLong(context.getString(R.string.screen_brightness_timestamp_key), 0);
  // hypothesis: 4h covers a viewing block, eg evening. External lightning conditions will change in the next
  // viewing block so we fall back to the default brightness
  if ((System.currentTimeMillis() - timestamp) > TimeUnit.HOURS.toMillis(4)) {
    return screenBrightness;
  } else {
    return sp.getFloat(context.getString(R.string.screen_brightness_key), screenBrightness);
  }
}

代码示例来源:origin: TommyLemon/APIJSON

/**获取最后一次登录的用户
 * @return
 */
public User getLastUser() {
  SharedPreferences sdf = context.getSharedPreferences(PATH_USER, Context.MODE_PRIVATE);
  return sdf == null ? null : getUser(sdf.getLong(KEY_LAST_USER_ID, 0));
}

代码示例来源:origin: TommyLemon/APIJSON

/**获取当前用户
 * @return
 */
public User getCurrentUser() {
  SharedPreferences sdf = context.getSharedPreferences(PATH_USER, Context.MODE_PRIVATE);
  return sdf == null ? null : getUser(sdf.getLong(KEY_CURRENT_USER_ID, 0));
}

代码示例来源:origin: TommyLemon/Android-ZBLibrary

/**获取最后一次登录的用户
 * @param context
 * @return
 */
public User getLastUser() {
  SharedPreferences sdf = context.getSharedPreferences(PATH_USER, Context.MODE_PRIVATE);
  return sdf == null ? null : getUser(sdf.getLong(KEY_LAST_USER_ID, 0));
}

代码示例来源:origin: markzhai/AndroidPerformanceMonitor

/**
 * Is monitor duration end, compute from recordStartTime end provideMonitorDuration.
 *
 * @return true if ended
 */
public boolean isMonitorDurationEnd() {
  long startTime =
      PreferenceManager.getDefaultSharedPreferences(BlockCanaryContext.get().provideContext())
          .getLong("BlockCanary_StartTime", 0);
  return startTime != 0 && System.currentTimeMillis() - startTime >
      BlockCanaryContext.get().provideMonitorDuration() * 3600 * 1000;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldReturnDefaultValues() throws Exception {
 SharedPreferences anotherSharedPreferences = context.getSharedPreferences("bazBang", Context.MODE_PRIVATE);
 assertFalse(anotherSharedPreferences.getBoolean("boolean", false));
 assertThat(anotherSharedPreferences.getFloat("float", 666f)).isEqualTo(666f);
 assertThat(anotherSharedPreferences.getInt("int", 666)).isEqualTo(666);
 assertThat(anotherSharedPreferences.getLong("long", 666L)).isEqualTo(666L);
 assertThat(anotherSharedPreferences.getString("string", "wacka wa")).isEqualTo("wacka wa");
}

代码示例来源:origin: robolectric/robolectric

@Test
public void commit_shouldRemoveValuesThenSetValues() throws Exception {
 editor.putString("deleteMe", "foo").commit();
 editor.remove("deleteMe");
 editor.putString("dontDeleteMe", "baz");
 editor.remove("dontDeleteMe");
 editor.commit();
 SharedPreferences anotherSharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
 assertThat(anotherSharedPreferences.getBoolean("boolean", false)).isTrue();
 assertThat(anotherSharedPreferences.getFloat("float", 666f)).isEqualTo(1.1f);
 assertThat(anotherSharedPreferences.getInt("int", 666)).isEqualTo(2);
 assertThat(anotherSharedPreferences.getLong("long", 666L)).isEqualTo(3L);
 assertThat(anotherSharedPreferences.getString("string", "wacka wa")).isEqualTo("foobar");
 assertThat(anotherSharedPreferences.getString("deleteMe", "awol")).isEqualTo("awol");
 assertThat(anotherSharedPreferences.getString("dontDeleteMe", "oops")).isEqualTo("oops");
}

代码示例来源:origin: robolectric/robolectric

@Test
public void commit_shouldStoreValues() throws Exception {
 editor.commit();
 SharedPreferences anotherSharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
 assertTrue(anotherSharedPreferences.getBoolean("boolean", false));
 assertThat(anotherSharedPreferences.getFloat("float", 666f)).isEqualTo(1.1f);
 assertThat(anotherSharedPreferences.getInt("int", 666)).isEqualTo(2);
 assertThat(anotherSharedPreferences.getLong("long", 666L)).isEqualTo(3L);
 assertThat(anotherSharedPreferences.getString("string", "wacka wa")).isEqualTo("foobar");
 assertThat(anotherSharedPreferences.getStringSet("stringSet", null)).isEqualTo(stringSet);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void commit_shouldClearThenSetValues() throws Exception {
 editor.putString("deleteMe", "foo");
 editor.clear();
 editor.putString("dontDeleteMe", "baz");
 editor.commit();
 SharedPreferences anotherSharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
 assertTrue(anotherSharedPreferences.getBoolean("boolean", false));
 assertThat(anotherSharedPreferences.getFloat("float", 666f)).isEqualTo(1.1f);
 assertThat(anotherSharedPreferences.getInt("int", 666)).isEqualTo(2);
 assertThat(anotherSharedPreferences.getLong("long", 666L)).isEqualTo(3L);
 assertThat(anotherSharedPreferences.getString("string", "wacka wa")).isEqualTo("foobar");
 // Android always calls clear before put on any open editor, so here "foo" is preserved rather than cleared.
 assertThat(anotherSharedPreferences.getString("deleteMe", "awol")).isEqualTo("foo");
 assertThat(anotherSharedPreferences.getString("dontDeleteMe", "oops")).isEqualTo("baz");
}

相关文章