对activity的提前处理,主要应用于获取本地值,方便acitivity的生成,也用于activity运行时改变某些必须变量。
public class PrefUtil {
private static final String PRE_NAME = "io.github.laucherish.purezhihud_preferences";
private static final String PRE_NIGHT = "night";
private static SharedPreferences getSharedPreferences() {
return App.getContext()
.getSharedPreferences(PRE_NAME, Context.MODE_PRIVATE);
}
public static void setNight(){
getSharedPreferences().edit().putBoolean(PRE_NIGHT, true).commit();
}
public static void setDay(){
getSharedPreferences().edit().putBoolean(PRE_NIGHT, false).commit();
}
public static boolean isNight(){
return getSharedPreferences().getBoolean(PRE_NIGHT, false);
}
public static int getThemeRes(){
if (!isNight()) {
return Constant.RESOURCES_DAYTHEME;
} else {
return Constant.RESOURCES_NIGHTTHEME;
}
}
}