331 lines
10 KiB
Plaintext
331 lines
10 KiB
Plaintext
package com.novelbook.android.utils;
|
||
|
||
import android.content.Context;
|
||
import android.content.SharedPreferences;
|
||
import android.graphics.Typeface;
|
||
import android.text.style.BulletSpan;
|
||
|
||
import com.novelbook.android.BuildConfig;
|
||
import com.novelbook.android.MyApp;
|
||
import com.novelbook.android.R;
|
||
|
||
|
||
public class Config {
|
||
private final static String SP_NAME = "config";
|
||
private final static String BOOK_BG_KEY = "bookbg";
|
||
private final static String FONT_TYPE_KEY = "fonttype";
|
||
private final static String FONT_SIZE_KEY = "fontsize";
|
||
private final static String LINE_SPACE_KEY = "linespace";
|
||
private final static String NIGHT_KEY = "night";
|
||
private final static String LIGHT_KEY = "light";
|
||
private final static String SYSTEM_LIGHT_KEY = "systemlight";
|
||
private final static String PAGE_MODE_KEY = "pagemode";
|
||
private final static String KEY_BASE_URY = "baseurl";
|
||
private final static String KEY_ROOT_URL = "rooturl";
|
||
public final static String FONTTYPE_DEFAULT = "";
|
||
public final static String FONTTYPE_QIHEI = "font/qihei.ttf";
|
||
public final static String FONTTYPE_WAWA = "font/font1.ttf";
|
||
|
||
public final static String FONTTYPE_FZXINGHEI = "font/fzxinghei.ttf";
|
||
public final static String FONTTYPE_FZKATONG = "font/fzkatong.ttf";
|
||
public final static String FONTTYPE_BYSONG = "font/bysong.ttf";
|
||
|
||
public final static int BOOK_BG_DEFAULT = 0;
|
||
public final static int BOOK_BG_1 = 1;
|
||
public final static int BOOK_BG_2 = 2;
|
||
public final static int BOOK_BG_3 = 3;
|
||
public final static int BOOK_BG_4 = 4;
|
||
|
||
public final static int PAGE_MODE_SIMULATION = 0;
|
||
public final static int PAGE_MODE_COVER = 1;
|
||
public final static int PAGE_MODE_SLIDE = 2;
|
||
public final static int PAGE_MODE_NONE = 3;
|
||
public final static boolean SHOW_AD = false;
|
||
private final static String DECLARE_KEY = "declarekey";
|
||
private final static String SHOW_CHAPT_URL_KEY = "chapturlkey";
|
||
private static final String PRE_LOAD_CHAPT_KEY ="preloadchapt" ;
|
||
|
||
private final static String AD_KEY = "adkey";
|
||
|
||
//sexoption
|
||
private final static String SEX_OPTION_KEY="sexoption";
|
||
private int sexOption =1;
|
||
|
||
private final static String SHELF_ORDER_OPTION_KEY="shelforderoption";
|
||
private int shelfOrderOption =1;
|
||
|
||
private final String APP_START_TIMES_KEY ="appstarttime";
|
||
private final int APP_START_TIMES =0;
|
||
|
||
|
||
|
||
private Context mContext;
|
||
private static Config config;
|
||
private SharedPreferences sp;
|
||
//字体
|
||
private Typeface typeface;
|
||
//字体大小
|
||
private float mFontSize = 0;
|
||
|
||
//行间距
|
||
private float mLineSpace =0;
|
||
//亮度值
|
||
private float light = 0;
|
||
private int bookBG;
|
||
|
||
public int getSexOption() {
|
||
return sp.getInt(SEX_OPTION_KEY,sexOption);
|
||
}
|
||
|
||
public void setSexOption(int sexOption) {
|
||
sp.edit().putInt(SEX_OPTION_KEY,sexOption).commit();
|
||
}
|
||
|
||
|
||
|
||
private Config(Context mContext){
|
||
this.mContext = mContext.getApplicationContext();
|
||
sp = this.mContext.getSharedPreferences(SP_NAME,Context.MODE_PRIVATE);
|
||
}
|
||
|
||
public static synchronized Config getInstance(){
|
||
return config;
|
||
}
|
||
|
||
public static synchronized Config createConfig(Context context){
|
||
if (config == null){
|
||
config = new Config(context);
|
||
}
|
||
|
||
return config;
|
||
}
|
||
|
||
public int getPageMode(){
|
||
return sp.getInt(PAGE_MODE_KEY,PAGE_MODE_SIMULATION);
|
||
}
|
||
|
||
public void setPageMode(int pageMode){
|
||
sp.edit().putInt(PAGE_MODE_KEY,pageMode).commit();
|
||
}
|
||
|
||
public int getBookBgType(){
|
||
return sp.getInt(BOOK_BG_KEY,BOOK_BG_DEFAULT);
|
||
}
|
||
|
||
public void setBookBg(int type){
|
||
sp.edit().putInt(BOOK_BG_KEY,type).commit();
|
||
}
|
||
|
||
public Typeface getTypeface(){
|
||
if (typeface == null) {
|
||
String typePath = sp.getString(FONT_TYPE_KEY,FONTTYPE_QIHEI);
|
||
typeface = getTypeface(typePath);
|
||
}
|
||
return typeface;
|
||
}
|
||
|
||
public String getTypefacePath(){
|
||
String path = sp.getString(FONT_TYPE_KEY,FONTTYPE_QIHEI);
|
||
return path;
|
||
}
|
||
|
||
public Typeface getTypeface(String typeFacePath){
|
||
return Typeface.DEFAULT;
|
||
/* Typeface mTypeface;
|
||
if (typeFacePath.equals(FONTTYPE_DEFAULT)){
|
||
mTypeface = Typeface.DEFAULT;
|
||
}else{
|
||
mTypeface = Typeface.createFromAsset(mContext.getAssets(),typeFacePath);
|
||
}
|
||
return mTypeface;*/
|
||
}
|
||
|
||
public void setTypeface(String typefacePath){
|
||
typeface = getTypeface(typefacePath);
|
||
sp.edit().putString(FONT_TYPE_KEY,typefacePath).commit();
|
||
}
|
||
|
||
public float getFontSize(){
|
||
if (mFontSize == 0){
|
||
mFontSize = sp.getFloat(FONT_SIZE_KEY, mContext.getResources().getDimension(R.dimen.reading_default_text_size));
|
||
}
|
||
return mFontSize;
|
||
}
|
||
|
||
public void setFontSize(float fontSize){
|
||
mFontSize = fontSize;
|
||
sp.edit().putFloat(FONT_SIZE_KEY,fontSize).commit();
|
||
}
|
||
public float getLineSpace(){
|
||
if (mLineSpace == 0){
|
||
mLineSpace = sp.getFloat(LINE_SPACE_KEY, mContext.getResources().getDimension(R.dimen.reading_line_spacing));
|
||
}
|
||
return mLineSpace;
|
||
}
|
||
|
||
public void setLineSpace(float lineSpace){
|
||
mLineSpace = lineSpace;
|
||
sp.edit().putFloat(LINE_SPACE_KEY,lineSpace).commit();
|
||
}
|
||
/**
|
||
* 获取夜间还是白天阅读模式,true为夜晚,false为白天
|
||
*/
|
||
public boolean getDayOrNight() {
|
||
return sp.getBoolean(NIGHT_KEY, false);
|
||
}
|
||
|
||
public void setDayOrNight(boolean isNight){
|
||
sp.edit().putBoolean(NIGHT_KEY,isNight).commit();
|
||
}
|
||
|
||
public Boolean isSystemLight(){
|
||
return sp.getBoolean(SYSTEM_LIGHT_KEY,true);
|
||
}
|
||
|
||
public void setSystemLight(Boolean isSystemLight){
|
||
sp.edit().putBoolean(SYSTEM_LIGHT_KEY,isSystemLight).commit();
|
||
}
|
||
|
||
public float getLight(){
|
||
if (light == 0){
|
||
light = sp.getFloat(LIGHT_KEY,0.1f);
|
||
}
|
||
return light;
|
||
}
|
||
/**
|
||
* 记录配置文件中亮度值
|
||
*/
|
||
public void setLight(float light) {
|
||
this.light = light;
|
||
sp.edit().putFloat(LIGHT_KEY,light).commit();
|
||
}
|
||
|
||
|
||
|
||
public void setBaseUrl(String baseUrl){
|
||
sp.edit().putString(KEY_BASE_URY,baseUrl).commit();
|
||
}
|
||
public String getBaseUrl(){
|
||
// String defaultHost ="{\"master\":[\"http:\\/\\/xiaoshuofenxiang.com\"],\"page\":[\"http:\\/\\/p.xiaoshuofenxiang.com\"],\"report\":[\"http:\\/\\/r.xiaoshuofenxiang.com\"],\"search\":[\"http:\\/\\/s.xiaoshuofenxiang.com\"],\"novel\":[\"http:\\/\\/n.xiaoshuofenxiang.com\"],\"novelsbydot\":[\"http:\\/\\/nbd.xiaoshuofenxiang.com\"],\"user\":[\"http:\\/\\/u.xiaoshuofenxiang.com\"]}";
|
||
// String defaultHost =CommonUtil.getMeta(MyApp.applicationContext,"DEFAULTHOST");
|
||
|
||
String defaultHost =BuildConfig.API_HOST;
|
||
return sp.getString(KEY_BASE_URY,defaultHost);
|
||
}
|
||
|
||
|
||
public String getRootUrl(){
|
||
//String defaultHost =CommonUtil.getMeta(MyApp.applicationContext,"MAINHOST");
|
||
|
||
String defaultHost = BuildConfig.MAIN_HOST;
|
||
// String rt =sp.getString(KEY_ROOT_URL,defaultHost);
|
||
return sp.getString(KEY_ROOT_URL,defaultHost);
|
||
}
|
||
|
||
public void setRootUrl(String baseUrl){
|
||
sp.edit().putString(KEY_ROOT_URL,baseUrl).commit();
|
||
}
|
||
|
||
|
||
public Boolean isPreLoadChapter(){
|
||
return sp.getBoolean(PRE_LOAD_CHAPT_KEY,false);
|
||
}
|
||
public void setPreLoadChapter(boolean isPreloadChapt){
|
||
sp.edit().putBoolean(PRE_LOAD_CHAPT_KEY,isPreloadChapt).commit();
|
||
}
|
||
|
||
|
||
public String getAdSetting(){
|
||
return sp.getString(AD_KEY,"" );
|
||
}
|
||
|
||
public void setAdSetting(String adSetting){
|
||
sp.edit().putString (AD_KEY,adSetting).commit();
|
||
}
|
||
|
||
/*
|
||
public Boolean isShowAd(){
|
||
return sp.getBoolean(SHOW_AD_KEY,true);
|
||
}
|
||
public void setShowAd(boolean isShowAd){
|
||
sp.edit().putBoolean(SHOW_AD_KEY,isShowAd).commit();
|
||
}
|
||
public int getAdTopBannerRate(){
|
||
return sp.getInt(AD_TOP_BANNER_SEEDS_KEY,0);
|
||
}
|
||
|
||
public void setAdTopBannerRate(int pageCnt){
|
||
sp.edit().putInt(AD_TOP_BANNER_SEEDS_KEY,pageCnt).commit();
|
||
}
|
||
private final static String AD_NATIVE_BANNER_SOURCE_KEY = "AD_NATIVE_BANNER_SOURCE_KEY";
|
||
private final static String AD_BANNER_SOURCE_KEY = "AD_BANNER_SOURCE_KEY";
|
||
private final static String AD_UNIFIED_RECYCLE_SOURCE_KEY = "AD_UNIFIED_RECYCLE_SOURCE_KEY";
|
||
private final static String AD_SPLASH_SOURCE_KEY = "AD_SPLASH_SOURCE_KEY";
|
||
|
||
|
||
public int getAdNativeBannerSource(){
|
||
return sp.getInt(AD_NATIVE_BANNER_SOURCE_KEY,Constants.AD_TENCENT_QQ);
|
||
}
|
||
|
||
public void setAdNativeBannerSource(int source){
|
||
sp.edit().putInt(AD_NATIVE_BANNER_SOURCE_KEY,source).commit();
|
||
}
|
||
|
||
public int getAdBannerSource(){
|
||
return sp.getInt(AD_BANNER_SOURCE_KEY,Constants.AD_TENCENT_QQ);
|
||
}
|
||
|
||
public void setAdBannerSource(int source){
|
||
sp.edit().putInt(AD_BANNER_SOURCE_KEY,source).commit();
|
||
}
|
||
|
||
public int getAdUnifiedRecycleSource(){
|
||
return sp.getInt(AD_UNIFIED_RECYCLE_SOURCE_KEY,Constants.AD_TENCENT_QQ);
|
||
}
|
||
|
||
public void setAdUnifiedRecycleSource(int source){
|
||
sp.edit().putInt(AD_UNIFIED_RECYCLE_SOURCE_KEY,source).commit();
|
||
}
|
||
|
||
public int getAdSplashSource(){
|
||
return sp.getInt(AD_SPLASH_SOURCE_KEY,Constants.AD_TENCENT_QQ);
|
||
}
|
||
|
||
public void setAdSplashSource(int source){
|
||
sp.edit().putInt(AD_SPLASH_SOURCE_KEY,source).commit();
|
||
}
|
||
*/
|
||
|
||
public String getDeclare(){
|
||
return sp.getString(DECLARE_KEY,"" );
|
||
}
|
||
|
||
public void setDeclare(String declare){
|
||
sp.edit().putString(DECLARE_KEY,declare).commit();
|
||
}
|
||
public Boolean isShowChatpUrl(){
|
||
return sp.getBoolean(SHOW_CHAPT_URL_KEY,false);
|
||
}
|
||
public void setShowChaptUrl(boolean isShowChatpUrl){
|
||
sp.edit().putBoolean(SHOW_CHAPT_URL_KEY,isShowChatpUrl).commit();
|
||
}
|
||
|
||
|
||
public int getShelfOrderOption() {
|
||
return sp.getInt(SHELF_ORDER_OPTION_KEY,shelfOrderOption );
|
||
}
|
||
|
||
public void setShelfOrderOption(int option) {
|
||
sp.edit().putInt(SHELF_ORDER_OPTION_KEY,option).commit();
|
||
}
|
||
|
||
public int getAppStartTimes() {
|
||
return sp.getInt(APP_START_TIMES_KEY,APP_START_TIMES );
|
||
}
|
||
|
||
public void setAppStartTimes(int cnt) {
|
||
sp.edit().putInt(APP_START_TIMES_KEY,cnt).commit();
|
||
}
|
||
|
||
}
|