public class PreferencesUtils {
private Context context;
public PreferencesUtils(Context context) {
this.context = context;
}
public boolean putInt(String key, int value) {
boolean flag = context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().putInt(key, value).commit();
return flag;
}
public int getInt(String key, int defValue) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).getInt(key, defValue);
}
public boolean putLong(String key, long value) {
boolean flag = context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().putLong(key, value).commit();
return flag;
}
public long getLong(String key, long defValue) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).getLong(key, defValue);
}
public boolean putString(String key, String value) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().putString(key, value).commit();
}
public String getString(String key, String defValue) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).getString(key, defValue);
}
public boolean putBoolean(String key, boolean value) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().putBoolean(key, value).commit();
}
public boolean getBoolean(String key, boolean defValue) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).getBoolean(key, defValue);
}
public boolean clearAllValue() {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().clear().commit();
}
}
网友评论