Java Code Examples for android.content.SharedPreferences#getFloat()
The following examples show how to use
android.content.SharedPreferences#getFloat() .
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: SPUtils.java From TestChat with Apache License 2.0 | 6 votes |
/** * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 * * @param key * @param defaultObject * @return */ public static Object get(String key, Object defaultObject) { SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); if (defaultObject instanceof String) { return sp.getString(key, (String) defaultObject); } else if (defaultObject instanceof Integer) { return sp.getInt(key, (Integer) defaultObject); } else if (defaultObject instanceof Boolean) { return sp.getBoolean(key, (Boolean) defaultObject); } else if (defaultObject instanceof Float) { return sp.getFloat(key, (Float) defaultObject); } else if (defaultObject instanceof Long) { return sp.getLong(key, (Long) defaultObject); } return null; }
Example 2
Source File: XPreferencesUtils.java From XFrame with Apache License 2.0 | 6 votes |
/** * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 * @param key * @param defaultObject * @return */ public static Object get(String key, Object defaultObject) { SharedPreferences sp = XFrame.getContext().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); if (defaultObject instanceof String) { return sp.getString(key, (String) defaultObject); } else if (defaultObject instanceof Integer) { return sp.getInt(key, (Integer) defaultObject); } else if (defaultObject instanceof Boolean) { return sp.getBoolean(key, (Boolean) defaultObject); } else if (defaultObject instanceof Float) { return sp.getFloat(key, (Float) defaultObject); } else if (defaultObject instanceof Long) { return sp.getLong(key, (Long) defaultObject); } return null; }
Example 3
Source File: SPUtil.java From UIWidget with Apache License 2.0 | 6 votes |
/** * 获取存放object * * @param context * @param fileName * @param key * @param def * @return */ public static Object get(Context context, String fileName, String key, Object def) { SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); if (def instanceof String) { return sp.getString(key, def.toString()); } else if (def instanceof Integer) { return sp.getInt(key, ((Integer) def).intValue()); } else if (def instanceof Boolean) { return sp.getBoolean(key, ((Boolean) def).booleanValue()); } else if (def instanceof Float) { return sp.getFloat(key, ((Float) def).floatValue()); } else if (def instanceof Long) { return sp.getLong(key, ((Long) def).longValue()); } else if (def instanceof Set) { return sp.getStringSet(key, (Set<String>) def); } return def; }
Example 4
Source File: SPUtils.java From ToDoList with Apache License 2.0 | 6 votes |
/** * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 * * @param context * @param key * @param defaultObject * @return */ public static Object get(Context context, String key, Object defaultObject) { SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); if (defaultObject instanceof String) { return sp.getString(key, (String) defaultObject); } else if (defaultObject instanceof Integer) { return sp.getInt(key, (Integer) defaultObject); } else if (defaultObject instanceof Boolean) { return sp.getBoolean(key, (Boolean) defaultObject); } else if (defaultObject instanceof Float) { return sp.getFloat(key, (Float) defaultObject); } else if (defaultObject instanceof Long) { return sp.getLong(key, (Long) defaultObject); } return null; }
Example 5
Source File: SPUtils.java From MvpRxJavaRetrofitOkhttp with MIT License | 6 votes |
/** * 获取数据的方法,根据默认值得到数据的类型,然后调用对应方法获取值 * * @param key * @param defaultObject * @return */ public static Object get(String key, Object defaultObject) { SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); if (defaultObject instanceof String) { return sp.getString(key, (String) defaultObject); } else if (defaultObject instanceof Integer) { return sp.getInt(key, (Integer) defaultObject); } else if (defaultObject instanceof Boolean) { return sp.getBoolean(key, (Boolean) defaultObject); } else if (defaultObject instanceof Float) { return sp.getFloat(key, (Float) defaultObject); } else if (defaultObject instanceof Long) { return sp.getLong(key, (Long) defaultObject); } return null; }
Example 6
Source File: SPUtils.java From AccountBook with GNU General Public License v3.0 | 6 votes |
/** * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 */ public static Object getSP(Context context, String key, Object defaultObject) { SharedPreferences sp = context.getSharedPreferences(getSpName(context), Context.MODE_PRIVATE); if (defaultObject instanceof String) { return sp.getString(key, (String) defaultObject); } else if (defaultObject instanceof Integer) { return sp.getInt(key, (Integer) defaultObject); } else if (defaultObject instanceof Boolean) { return sp.getBoolean(key, (Boolean) defaultObject); } else if (defaultObject instanceof Float) { return sp.getFloat(key, (Float) defaultObject); } else if (defaultObject instanceof Long) { return sp.getLong(key, (Long) defaultObject); } else { return null; } }
Example 7
Source File: SPUtils.java From SmartChart with Apache License 2.0 | 6 votes |
/** * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 * * @param context * @param key * @param defaultObject * @return */ public static Object get(Context context, String key, Object defaultObject) { SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); if (defaultObject instanceof String) { return sp.getString(key, (String) defaultObject); } else if (defaultObject instanceof Integer) { return sp.getInt(key, (Integer) defaultObject); } else if (defaultObject instanceof Boolean) { return sp.getBoolean(key, (Boolean) defaultObject); } else if (defaultObject instanceof Float) { return sp.getFloat(key, (Float) defaultObject); } else if (defaultObject instanceof Long) { return sp.getLong(key, (Long) defaultObject); } return null; }
Example 8
Source File: MainApplication.java From WhereYouGo with GNU General Public License v3.0 | 6 votes |
private void legacySupport4PreferencesFloat(int prefId) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); String key = getString(prefId); try { sharedPref.getString(key, ""); } catch (Exception e) { try { Log.d(TAG, "legacySupport4PreferencesFloat() - LEGACY SUPPORT: convert float to string"); Float value = sharedPref.getFloat(key, 0.0f); sharedPref.edit().remove(key).commit(); sharedPref.edit().putString(key, String.valueOf(value)).commit(); } catch (Exception ee) { Log.e(TAG, "legacySupport4PreferencesFloat() - panic remove", ee); sharedPref.edit().remove(key).commit(); } } }
Example 9
Source File: SPUtil.java From Ency with Apache License 2.0 | 6 votes |
/** * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 * * @param context * @param key * @param defaultObject * @return */ public static Object get(Context context, String key, Object defaultObject) { SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); if (defaultObject instanceof String) { return sp.getString(key, (String) defaultObject); } else if (defaultObject instanceof Integer) { return sp.getInt(key, (Integer) defaultObject); } else if (defaultObject instanceof Boolean) { return sp.getBoolean(key, (Boolean) defaultObject); } else if (defaultObject instanceof Float) { return sp.getFloat(key, (Float) defaultObject); } else if (defaultObject instanceof Long) { return sp.getLong(key, (Long) defaultObject); } return null; }
Example 10
Source File: SharedPreferencesUtil.java From MarketAndroidApp with Apache License 2.0 | 6 votes |
/** * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 * * @param fileName sp文件名,可指定载入哪个sp文件 * @param context * @param key * @param defaultObject * @return */ public static Object get(Context context, String fileName, String key, Object defaultObject) { SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); if (defaultObject instanceof String) { return sp.getString(key, (String) defaultObject); } else if (defaultObject instanceof Integer) { return sp.getInt(key, (Integer) defaultObject); } else if (defaultObject instanceof Boolean) { return sp.getBoolean(key, (Boolean) defaultObject); } else if (defaultObject instanceof Float) { return sp.getFloat(key, (Float) defaultObject); } else if (defaultObject instanceof Long) { return sp.getLong(key, (Long) defaultObject); } return null; }
Example 11
Source File: SharedPreferencesUtil.java From DanDanPlayForAndroid with MIT License | 6 votes |
/** * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值 * * @param context * @param key * @param defaultObject * @return */ public static Object getParam(Context context, String key, Object defaultObject) { String type = defaultObject.getClass().getSimpleName(); SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); if ("String".equals(type)) { return sp.getString(key, (String) defaultObject); } else if ("Integer".equals(type)) { return sp.getInt(key, (Integer) defaultObject); } else if ("Boolean".equals(type)) { return sp.getBoolean(key, (Boolean) defaultObject); } else if ("Float".equals(type)) { return sp.getFloat(key, (Float) defaultObject); } else if ("Long".equals(type)) { return sp.getLong(key, (Long) defaultObject); } return null; }
Example 12
Source File: FloatingModMenuService.java From FloatingModMenu with GNU General Public License v3.0 | 5 votes |
private void loadPrefs() { SharedPreferences preferences = getApplicationContext().getSharedPreferences("mod_menu", 0); editor = preferences.edit(); background_color = preferences.getInt("background_color", -14606047); curent_icon = preferences.getFloat("current_background", 1); alpha = preferences.getInt("current_progress_alpha", 255); red = preferences.getInt("current_progress_red", 33); green = preferences.getInt("current_progress_green", 33); blue = preferences.getInt("current_progress_blue", 33); mProgress_icon = preferences.getInt("current_progress_icon", 10); }
Example 13
Source File: PreferencesWrapper.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
private static Float gPrefFloatValue(SharedPreferences aPrefs, String key) { if(aPrefs == null) { return FLOAT_PREFS.get(key); } if(FLOAT_PREFS.containsKey(key)) { return aPrefs.getFloat(key, FLOAT_PREFS.get(key)); } if(aPrefs.contains(key)) { return aPrefs.getFloat(key, 0.0f); } return null; }
Example 14
Source File: Settings.java From LokiBoard-Android-Keylogger with Apache License 2.0 | 5 votes |
public static float readKeypressSoundVolume(final SharedPreferences prefs, final Resources res) { final float volume = prefs.getFloat( PREF_KEYPRESS_SOUND_VOLUME, UNDEFINED_PREFERENCE_VALUE_FLOAT); return (volume != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? volume : readDefaultKeypressSoundVolume(res); }
Example 15
Source File: Settings.java From openboard with GNU General Public License v3.0 | 5 votes |
public static float readKeypressSoundVolume(final SharedPreferences prefs, final Resources res) { final float volume = prefs.getFloat( PREF_KEYPRESS_SOUND_VOLUME, UNDEFINED_PREFERENCE_VALUE_FLOAT); return (volume != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? volume : readDefaultKeypressSoundVolume(res); }
Example 16
Source File: Settings.java From simple-keyboard with Apache License 2.0 | 5 votes |
public static float readKeypressSoundVolume(final SharedPreferences prefs, final Resources res) { final float volume = prefs.getFloat( PREF_KEYPRESS_SOUND_VOLUME, UNDEFINED_PREFERENCE_VALUE_FLOAT); return (volume != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? volume : readDefaultKeypressSoundVolume(res); }
Example 17
Source File: SharePreferenceUtils.java From KotlinMVPRxJava2Dagger2GreenDaoRetrofitDemo with Apache License 2.0 | 4 votes |
public static float getPrefFloat(Context context, final String key, final float defaultValue) { final SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(context); return settings.getFloat(key, defaultValue); }
Example 18
Source File: Settings.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 4 votes |
public static float readKeyPreviewAnimationScale(final SharedPreferences prefs, final String prefKey, final float defaultValue) { final float fraction = prefs.getFloat(prefKey, UNDEFINED_PREFERENCE_VALUE_FLOAT); return (fraction != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? fraction : defaultValue; }
Example 19
Source File: SharedUtil.java From giffun with Apache License 2.0 | 2 votes |
/** * 从SharedPreferences文件当中读取参数传入键相应的float类型的值。 * @param key * 读取的键 * @param defValue * 如果读取不到值,返回的默认值 * @return float类型的值,如果读取不到,则返回默认值 */ public static float read(String key, float defValue) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GifFun.getContext()); return prefs.getFloat(key, defValue); }
Example 20
Source File: SharedPrefer.java From FastAndroid with Apache License 2.0 | 2 votes |
/** * 获取float * * @param key * @return */ public float getFloat(@NonNull Context context, @NonNull String key) { SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); return sp.getFloat(key, (float) 0.00); }