package com.linju.android_property.utils; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; public class PreferencesUtils { public static void setStringPreferences(Context context, String preference, String key, String value){ SharedPreferences sharedPreferences = context.getSharedPreferences(preference, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putString(key, value); editor.commit(); } public static String getStringPreference(Context context, String preference, String key, String defaultValue){ SharedPreferences sharedPreferences = context.getSharedPreferences(preference, Context.MODE_PRIVATE); return sharedPreferences.getString(key, defaultValue); } public static void setLongPreference(Context context, String preference, String key, long value) { SharedPreferences sharedPreferences = context.getSharedPreferences(preference, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putLong(key, value); editor.commit(); } public static long getLongPreference(Context context, String preference, String key, long defaultValue) { SharedPreferences sharedPreferences = context.getSharedPreferences(preference, Context.MODE_PRIVATE); return sharedPreferences.getLong(key, defaultValue); } public static void setBooleanPreference(Context context, String preference, String key, boolean value){ SharedPreferences sharedPreferences = context.getSharedPreferences(preference, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putBoolean(key, value); editor.commit(); } public static boolean getBooleanPreference(Context context, String preference, String key, boolean defaultValue){ SharedPreferences sharedPreferences = context.getSharedPreferences(preference, Context.MODE_PRIVATE); return sharedPreferences.getBoolean(key, defaultValue); } }