WMSApplication.java
3.42 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.huaheng.wms;
import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import com.huaheng.wms.https.HttpInterface;
import com.huaheng.wms.https.Subscribers.ProgressSubscriber;
import com.huaheng.wms.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.wms.util.CrashHandler;
import com.huaheng.wms.util.SoundUtils;
import com.huaheng.wms.util.SpeechUtil;
import com.huaheng.wms.util.WMSUtils;
import com.huaheng.wms.wmsgreendao.DaoMaster;
import com.huaheng.wms.wmsgreendao.DaoSession;
import com.huaheng.wms.work.collectgoods.TaskBean;
import org.xutils.x;
import java.util.List;
import rx.Subscriber;
public class WMSApplication extends Application {
private static String cookie;
// greenDao
private DaoMaster.DevOpenHelper mHelper;
private SQLiteDatabase db;
private DaoMaster mDaoMaster;
private DaoSession mDaoSession;
private static Context mContext;
private static WMSApplication instance;
private MyHandler myHandler = new MyHandler();
private boolean send = true;
@Override
public void onCreate() {
super.onCreate();
initData();
}
public static WMSApplication getInstance() {
if(instance == null) {
instance = new WMSApplication();
}
return instance;
}
public void initData() {
mContext = this;
SoundUtils.getInstance(this);
setupDataBase();
CrashHandler.getInstance().init(this);
x.Ext.init(this);
x.Ext.setDebug(BuildConfig.DEBUG); // 是否输出debug日志, 开启debug会影响性能.
SpeechUtil.getInstance(mContext).initSpeech();
myHandler.sendEmptyMessageDelayed(0 , 30 * 1000);
}
public static String getOkhttpCookie() {
return cookie;
}
public static void setOkhttpCookie(String result) {
cookie = result;
}
/**
* 初始化数据库
*/
private void setupDataBase() {
mHelper = new DaoMaster.DevOpenHelper(this, "WMSApplication", null);
db = mHelper.getWritableDatabase();
mDaoMaster = new DaoMaster(db);
mDaoSession = mDaoMaster.newSession();
WMSLog.d("setupDataBase");
}
public DaoSession getDaoSession() {
return mDaoSession;
}
public SQLiteDatabase getDb() {
return db;
}
public static Context getContext() {
return mContext;
}
private void selectTaskOutList() {
if(send) {
send = false;
myHandler.sendEmptyMessageDelayed(0 , 30 * 1000);
}
HttpInterface.getInsstance().selectTaskOutList(new Subscriber<List<TaskBean>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
send = true;
}
@Override
public void onNext(List<TaskBean> taskBeans) {
if(taskBeans != null && taskBeans.size() > 0) {
SoundUtils.getInstance(mContext).dingSound();
}
send = true;
}
});
}
private class MyHandler extends Handler {
@Override
public void handleMessage(Message msg) {
selectTaskOutList();
super.handleMessage(msg);
}
}
}