偏好设置
来源:互联网 发布:软件测试的案例 编辑:程序博客网 时间:2024/04/28 19:22
public class SPUtil {
private static Editor editor;
private SharedPreferences sp;
public SPUtil(String spName){
sp = MyApp.context.getSharedPreferences(spName, Context.MODE_PRIVATE);
editor = sp.edit();
}
/**
* 是否接受通知
* @return
*/
public boolean isAcceptNotify(){
return sp.getBoolean("notify", true);
}
/**
* 是否允许声音
* @return
*/
public boolean isAllowSound(){
return sp.getBoolean("sound", true);
}
/**
* 是否允许震动
* @return
*/
public boolean isAllowVibrate(){
return sp.getBoolean("vibrate", true);
}
/**
* 设置是否允许接受通知
* @param flag
*/
public void setAcceptNotify(boolean flag){
editor.putBoolean("notify", flag);
editor.commit();
}
/**
* 设置是否允许声音
* @param flag
*/
public void setAllowSound(boolean flag){
editor.putBoolean("sound", flag);
editor.commit();
}
/**
* 设置是否允许震动
* @param flag
*/
public void setAllowVibrate(boolean flag){
editor.putBoolean("vibrate", flag);
editor.commit();
}
}
private static Editor editor;
private SharedPreferences sp;
public SPUtil(String spName){
sp = MyApp.context.getSharedPreferences(spName, Context.MODE_PRIVATE);
editor = sp.edit();
}
/**
* 是否接受通知
* @return
*/
public boolean isAcceptNotify(){
return sp.getBoolean("notify", true);
}
/**
* 是否允许声音
* @return
*/
public boolean isAllowSound(){
return sp.getBoolean("sound", true);
}
/**
* 是否允许震动
* @return
*/
public boolean isAllowVibrate(){
return sp.getBoolean("vibrate", true);
}
/**
* 设置是否允许接受通知
* @param flag
*/
public void setAcceptNotify(boolean flag){
editor.putBoolean("notify", flag);
editor.commit();
}
/**
* 设置是否允许声音
* @param flag
*/
public void setAllowSound(boolean flag){
editor.putBoolean("sound", flag);
editor.commit();
}
/**
* 设置是否允许震动
* @param flag
*/
public void setAllowVibrate(boolean flag){
editor.putBoolean("vibrate", flag);
editor.commit();
}
}
0 0
- 偏好设置
- 偏好设置
- 偏好设置
- 偏好设置
- 偏好设置
- 偏好设置
- Android画图板 - 设置偏好
- 偏好设置 (Preferences)
- 应用程序的偏好设置
- Android_SharedPreferences用户偏好设置
- andorid,偏好设置,SharedPreferences
- 归档和偏好设置
- 安卓偏好设置
- IntelliJ IDEA 偏好设置
- SharedPreferences偏好设置
- 偏好设置保存数据
- 偏好设置 NSUserDefaults
- 偏好设置的存储
- URAL 1333
- 双ListView与顶部标题栏滑动事件处理(仿美团外卖商家详情界面滑动效果)
- Android学习之Activity的生命周期
- Spring 1.0
- 机器学习实战(一)
- 偏好设置
- POJ 3628 01背包 OR 状压
- 可变参数:定义方法的时候不知道该定义多少个参数
- 行内元素和块级元素
- LSTM与GRU的一些比较 - 论文笔记
- 捕获2-频率损耗因子
- (七)、选择结构
- android sdk里的各目录作用
- 小四轴DIY日记之DMA和ADC初始化