Back to project page ihatecolor_and.
The source code is released under:
Copyright (c) 2013, Sewon Ann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * ...
If you think the Android project ihatecolor_and 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 kr.pe.kingori.ihatecolor.util; //from ww w. j a v a 2 s. c o m import android.content.Context; import android.content.SharedPreferences; import kr.pe.kingori.ihatecolor.Application; import java.util.HashMap; public class SharedPreferenceUtil { private static HashMap<String, Object> memoryCache = new HashMap<String, Object>(); private static final String SHARED_PREFERENCE_NAME = "game_app"; private SharedPreferenceUtil() { } public static void put(String key, int value) { memoryCache.put(key, value); getSharedPreference().edit().putInt(key, value).commit(); } public static void put(String key, String value) { memoryCache.put(key, value); getSharedPreference().edit().putString(key, value).commit(); } public static void put(String key, long value) { memoryCache.put(key, value); getSharedPreference().edit().putLong(key, value).commit(); } public static int getInt(String key) { Integer result = getValueFromCache(key); if (result == null) { result = getSharedPreference().getInt(key, 0); memoryCache.put(key, result); } return result; } public static long getLong(String key) { Long result = getValueFromCache(key); if (result == null) { result = getSharedPreference().getLong(key, 0L); memoryCache.put(key, result); } return result; } public static String getString(String key) { String result = getValueFromCache(key); if (result == null) { result = getSharedPreference().getString(key, null); memoryCache.put(key, result); } return result; } public static <T> T getValueFromCache(String key) { if (memoryCache.containsKey(key)) { return (T) memoryCache.get(key); } else { return null; } } private static SharedPreferences getSharedPreference() { return Application.context .getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); } }