-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBaseApplication.java
More file actions
97 lines (83 loc) · 2.73 KB
/
BaseApplication.java
File metadata and controls
97 lines (83 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package common.base;
import android.app.Activity;
import android.app.Application;
import androidx.annotation.CallSuper;
import androidx.annotation.DimenRes;
import common.base.utils.CommonLog;
import common.base.utils.PreferVisitor;
/**
* User: fee(1176610771@qq.com)
* Date: 2016-07-02
* Time: 12:00
* DESC: APP程序上下文基类,一些通用的操作类 <E>指代BaseApplication子类自身,方便链式调用
*/
public class BaseApplication<E extends BaseApplication<E>> extends Application{
protected final String TAG = getClass().getSimpleName();
/**
* 将使用 DataStore替代
*/
@Deprecated
protected PreferVisitor preferVisitor;
protected String appPreferFileName = "def_app_config";
@CallSuper
@Override
public void onCreate() {
super.onCreate();
preferVisitor = PreferVisitor.getInstance(this);
}
public E prefer(String preferKey, Object value) {
preferVisitor.saveValue(appPreferFileName, preferKey, value);
return (E) this;
}
public <T> T getPrefer(String preferKey,T defValue) {
return preferVisitor.getValue(appPreferFileName, preferKey, defValue);
}
/***
* 批量将首选项数据存入首选项文件中
* @param keys
* @param valueDatas
*/
public E batchPrefer(String[] keys, Object... valueDatas) {
preferVisitor.batchSaveValues(appPreferFileName,keys,valueDatas);
return (E) this;
}
/**
* 栈入一个当前启动的Activity
* @param curActivity
*/
public E stackActivity(Activity curActivity) {
AppManager.getMe().addActivity(curActivity);
return (E) this;
}
/**
* 当一个Activity结束时也从管理的栈内踢出当前的Activity
* @param curActivity
*/
public E kickOutActivity(Activity curActivity) {
// AppManager.getMe().finishActivity(curActivity);
//changed by fee 2018-04-26: 更改为从栈中移出当前关闭的Activity
AppManager.getMe().removeStackedActivity(curActivity);
return (E) this;
}
public E clearAllStackedActivities() {
AppManager.getMe().finishAllActivity();
return self();
}
protected E self() {
return (E) this;
}
@Override
public void onTerminate() {
super.onTerminate();
AppManager.getMe().exitWholeApp(this);
}
protected void i(String logTag, Object... logInfo) {
CommonLog.i(logTag == null ? TAG : logTag, logInfo);
}
protected void e(String logTag, Object... logInfo) {
CommonLog.e(logTag == null ? TAG : logTag, logInfo);
}
public int dimenResPxValue(@DimenRes int dimenResId){
return getResources().getDimensionPixelSize(dimenResId);
}
}