@Override public float getFloat (String key) { return sharedPrefs.getFloat(key, 0); }
@Override public float getFloat (String key, float defValue) { return sharedPrefs.getFloat(key, defValue); }
@Override public float getFloat (String key, float defValue) { return sharedPrefs.getFloat(key, defValue); }
@Override public float getFloat (String key) { return sharedPrefs.getFloat(key, 0); }
public float getFloat(String key, float defaultVal) { return this.prefs.getFloat(key, defaultVal); }
public float getFloat(String key) { return this.prefs.getFloat(key, 0f); }
public float getFloat(String key, float defaultValue) { return mPreferences.getFloat(key, defaultValue); }
@Override public Float getOr(Float defaultValue) { try { return sharedPreferences.getFloat(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 Float.parseFloat(value); } catch (Exception e2) { // our recovery bit failed. The problem is elsewhere. Send the // original error throw e; } } }
public float getFloatValue(String key) { if (key != null && !key.equals("")) { return sp.getFloat(key, 0); } return 0; }
public static float getFloat(String key, float defValue) { try { return sSettingsPre.getFloat(key, defValue); } catch (ClassCastException e) { Log.d(TAG, "Get ClassCastException when get " + key + " value", e); return defValue; } }
/** * get float preferences * * @param context * @param key The name of the preference to retrieve * @param defaultValue Value to return if this preference does not exist * @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with * this name that is not a float */ public static float getFloat(Context context, String key, float defaultValue) { return PreferenceManager.getDefaultSharedPreferences(context).getFloat(key, defaultValue); }
/** * get float preferences * * @param context * @param key The name of the preference to retrieve * @param defaultValue Value to return if this preference does not exist * @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with * this name that is not a float */ public static float getFloat(Context context, String key, float defaultValue) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); return settings.getFloat(key, defaultValue); }
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); } }
public static Float getSharedFloatData(Context context, String key) { if (sp == null) { init(context); } return sp.getFloat(key, 0f); }
public static float getFloat(String key, float defValue) { return PreferenceManager.getDefaultSharedPreferences(BilibiliApp.getInstance()).getFloat(key, defValue); }
@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"); }
@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); }
@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"); }
@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"); }