Back to project page HelloWebView.
The source code is released under:
Apache License
If you think the Android project HelloWebView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mengdd.hellowebview.utils; //from w ww . jav a2 s . c o m import java.util.Map; import java.util.Map.Entry; import java.util.Set; import android.content.Context; import android.content.SharedPreferences; public class PreferencesUtils { private static SharedPreferences.Editor mEditer = null; private final static String PREFERENCE_NAME = "hello_webview_preferences"; private static SharedPreferences getSharedPreferences(Context context) { return context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); } /** * ??boolean??? * * @param key * ??????? * @return ??key??, ??????false */ public static boolean loadBoolean(Context context, String key) { return loadBoolean(context, key, false); } /** * ??boolean??? * * @param key * ??????? * @param defValue * ??key??????? * @return ??key?boolean? */ public static boolean loadBoolean(Context context, String key, boolean defValue) { return getSharedPreferences(context).getBoolean(key, defValue); } /** * ??int??? * * @param key * ??????? * @return ??key??, ??????0 */ public static int loadInt(Context context, String key) { return loadInt(context, key, 0); } /** * ??int??? * * @param key * ??????? * @param defValue * ??key??????? * @return ??key?int? */ public static int loadInt(Context context, String key, int defValue) { return getSharedPreferences(context).getInt(key, defValue); } /** * ??float??? * * @param key * ??????? * @return ??key??, ??????0.0f */ public static float loadFloat(Context context, String key) { return loadFloat(context, key, 0.0f); } /** * ??float??? * * @param key * ??????? * @param defValue * ??key??????? * @return ??key?float? */ public static float loadFloat(Context context, String key, float defValue) { return getSharedPreferences(context).getFloat(key, defValue); } /** * ??long??? * * @param key * ??????? * @return ??key??, ??????0L */ public static long loadLong(Context context, String key) { return loadLong(context, key, 0L); } /** * ????? * * @param key * ??????? * @param defValue * ??key??????? * @return ??key?? */ public static long loadLong(Context context, String key, long defValue) { return getSharedPreferences(context).getLong(key, defValue); } /** * ??String??? * * @param key * ??????? * @return ??key??, ??????null */ public static String loadString(Context context, String key) { return loadString(context, key, null); } /** * ??String??? * * @param key * ??????? * @param defValue * ??key??????? * @return ??key?String? */ public static String loadString(Context context, String key, String defValue) { return getSharedPreferences(context).getString(key, defValue); } /** * ?????key?boolean??? * * @param key * ???????? * @param value * ?????boolean? */ public static void saveBoolean(Context context, String key, boolean value) { if (mEditer == null) { mEditer = getSharedPreferences(context).edit(); } mEditer.putBoolean(key, value); mEditer.commit(); } /** * ?????key?int??? * * @param key * ???????? * @param value * ?????int? */ public static void saveInt(Context context, String key, int value) { if (mEditer == null) { mEditer = getSharedPreferences(context).edit(); } mEditer.putInt(key, value); mEditer.commit(); } /** * ?????key?float??? * * @param key * ???????? * @param value * ?????float? */ public static void saveFloat(Context context, String key, float value) { if (mEditer == null) { mEditer = getSharedPreferences(context).edit(); } mEditer.putFloat(key, value); mEditer.commit(); } /** * ?????key?long??? * * @param key * ???????? * @param value * ?????long? */ public static void saveLong(Context context, String key, long value) { if (mEditer == null) { mEditer = getSharedPreferences(context).edit(); } mEditer.putLong(key, value); mEditer.commit(); } /** * ?????key?String??? * * @param key * ???????? * @param value * ?????String? */ public static void saveString(Context context, String key, String value) { if (mEditer == null) { mEditer = getSharedPreferences(context).edit(); } mEditer.putString(key, value); mEditer.commit(); } /** * ?????key?String???????? * * @param string * ?????????????? */ public static void saveStrings(Context context, Map<String, String> strings) { if (strings == null || strings.isEmpty()) { return; } if (mEditer == null) { mEditer = getSharedPreferences(context).edit(); } Set<Entry<String, String>> datas = strings.entrySet(); for (Entry<String, String> entry : datas) { mEditer.putString(entry.getKey(), entry.getValue()); } mEditer.commit(); } }