SharedPreferencesUtil


/**
 * 
 */
public class SharedPreferencesUtil {

    private final static String NAME = "settings";

    /**
     * put int value
     * @param context
     * @param key
     * @param value
     */
    public static void putIntValue(Context context,String key,int value){
        SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        Editor edit = sharedPreferences.edit();
        edit.putInt(key, value);
        edit.commit();
    }

    /**
     * put float value
     * @param context
     * @param key
     * @param value
     */
    public static void putFloatValue(Context context,String key,float value){
        SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        Editor edit = sharedPreferences.edit();
        edit.putFloat(key, value);
        edit.commit();
    }

    /**
     * put boolean value
     * @param context
     * @param key
     * @param value
     */
    public static void putBooleanValue(Context context,String key,boolean value){
        SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        Editor edit = sharedPreferences.edit();
        edit.putBoolean(key, value);
        edit.commit();
    }

    /**
     * put long value
     * @param context
     * @param key
     * @param value
     */
    public static void putLongValue(Context context,String key,long value){
        SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        Editor edit = sharedPreferences.edit();
        edit.putLong(key, value);
        edit.commit();
    }

    /**
     * put String value
     * @param context
     * @param key
     * @param value
     */
    public static void setStringValue(Context context,String key,String value){
        SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        Editor edit = sharedPreferences.edit();
        edit.putString(key, value);
        edit.commit();
    }

    public static int getIntValue(Context context,String key,int defValue){
        SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getInt(key, defValue);
    }

    public static float getFloatValue(Context context,String key,float defValue){
        SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getFloat(key, defValue);
    }

    public static long getLongValue(Context context,String key,long defValue){
         SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
         return sharedPreferences.getLong(key, defValue);
    }

    public static String getStringValue(Context context,String key,String defValue){
        SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(key, defValue);
    }

    public static boolean getBooleanValue(Context context,String key,boolean defValue){
        SharedPreferences sharedPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean(key, defValue);
    }

}