Back to project page amulet.
The source code is released under:
MIT License
If you think the Android project amulet 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 scamell.michael.amulet; //from www.j a va 2s. c om import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; public class SharedPreferencesWrapper { public static void saveToPrefs(Context context, String key, String value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences.Editor editor = prefs.edit(); editor.putString(key, value); editor.commit(); } public static void saveToPrefs(Context context, String key, boolean value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(key, value); editor.commit(); } public static void saveToPrefs(Context context, String key, int value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences.Editor editor = prefs.edit(); editor.putInt(key, value); editor.commit(); } public static void saveToPrefs(Context context, String key, float value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences.Editor editor = prefs.edit(); editor.putFloat(key, value); editor.commit(); } public static void removeFromPrefs(Context context, String key) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences.Editor editor = prefs.edit(); editor.remove(key); editor.commit(); } public static String getFromPrefs(Context context, String key, String defaultValue) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); try { return sharedPrefs.getString(key, defaultValue); } catch (Exception e) { e.printStackTrace(); Log.i("Wrong_Type", "Wrong value type returned"); return defaultValue; } } public static boolean getFromPrefs(Context context, String key, boolean defaultValue) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); try { return sharedPrefs.getBoolean(key, defaultValue); } catch (Exception e) { e.printStackTrace(); Log.i("Wrong_Type", "Wrong value type returned"); return defaultValue; } } public static int getFromPrefs(Context context, String key, int defaultValue) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); try { return sharedPrefs.getInt(key, defaultValue); } catch (Exception e) { e.printStackTrace(); Log.i("Wrong_Type", "Wrong value type returned"); return defaultValue; } } public static float getFromPrefs(Context context, String key, float defaultValue) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); try { return sharedPrefs.getFloat(key, defaultValue); } catch (Exception e) { e.printStackTrace(); Log.i("Wrong_Type", "Wrong value type returned"); return defaultValue; } } }