package com.wanggjie.weishi.utils;
import android.content.Context;
import android.content.SharedPreferences;
import com.wanggjie.weishi.conf.Containts;
/**
* @author 王杰
* @time 2017/2/10 13:07
* @desc SharedPreferences保存和获取数据的工具
*/
public class SpUtils {
//获取到SharedPreferences对象
public static SharedPreferences getSp(String key, Context c) {
return c.getSharedPreferences( Containts.SPFILENAME, Context.MODE_APPEND);
}
//设置一个boolean值到Sp
public static void setSpBoolean(Context c, String key, boolean flag) {
SharedPreferences.Editor edit = SpUtils.getSp( Containts.SPFILENAME, c).edit();
edit.putBoolean(key, flag);
edit.commit();
}
//从Sp中获取一个boolean值
public static boolean getSpBoolean(Context c, String key){
return SpUtils.getSp( Containts.SPFILENAME, c).getBoolean(key,false);
}
//从Sp中获取一个String值
public static String getSpString(Context c, String key){
return SpUtils.getSp( Containts.PASSWORD, c).getString(key,"");
}
//设置一个String值到Sp
public static void setSpString(Context c, String key, String value) {
SharedPreferences.Editor edit = SpUtils.getSp( Containts.PASSWORD, c).edit();
edit.putString(key,value);
edit.commit();
}
import android.content.Context;
import android.content.SharedPreferences;
import com.wanggjie.weishi.conf.Containts;
/**
* @author 王杰
* @time 2017/2/10 13:07
* @desc SharedPreferences保存和获取数据的工具
*/
public class SpUtils {
//获取到SharedPreferences对象
public static SharedPreferences getSp(String key, Context c) {
return c.getSharedPreferences( Containts.SPFILENAME, Context.MODE_APPEND);
}
//设置一个boolean值到Sp
public static void setSpBoolean(Context c, String key, boolean flag) {
SharedPreferences.Editor edit = SpUtils.getSp( Containts.SPFILENAME, c).edit();
edit.putBoolean(key, flag);
edit.commit();
}
//从Sp中获取一个boolean值
public static boolean getSpBoolean(Context c, String key){
return SpUtils.getSp( Containts.SPFILENAME, c).getBoolean(key,false);
}
//从Sp中获取一个String值
public static String getSpString(Context c, String key){
return SpUtils.getSp( Containts.PASSWORD, c).getString(key,"");
}
//设置一个String值到Sp
public static void setSpString(Context c, String key, String value) {
SharedPreferences.Editor edit = SpUtils.getSp( Containts.PASSWORD, c).edit();
edit.putString(key,value);
edit.commit();
}
}
package com.wanggjie.weishi.conf;
/**
* @author 王杰
* @time 2017/2/10 13:11
* @desc 自定义的常量类,用于保存数据
*/
public interface Containts {
String SPFILENAME = "config";
String AUTOUPDATE = "autoupdate";
String BASE_URL = "http://192.168.140.2:8080";
String UPDATE_RRL = BASE_URL + "/info.json";
String PASSWORD = "password";
String FINISHSETUP = "finishsetup";
String SIM = "sim";
String SAFEPHONE = "safephone";
String SAFEONOFF = "safe_on_off";
String BlackNumberDb = "blacknumberinfo.db";
String DBNAME = "blacknumber";
String DB_PHONE = "phone";
String DB_MODE = "mode";
}