You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
4.9 KiB
Java
173 lines
4.9 KiB
Java
|
2 years ago
|
package com.rehome.zhdcoa;
|
||
|
|
|
||
|
|
import android.app.ActivityManager;
|
||
|
|
import android.content.ComponentName;
|
||
|
|
import android.content.Context;
|
||
|
|
import android.content.Intent;
|
||
|
|
import android.os.Process;
|
||
|
|
import android.text.TextUtils;
|
||
|
|
import android.util.Log;
|
||
|
|
|
||
|
|
import androidx.multidex.BuildConfig;
|
||
|
|
import androidx.multidex.MultiDex;
|
||
|
|
|
||
|
|
//import com.blankj.utilcode.util.Utils;
|
||
|
|
import com.github.mikephil.charting.utils.Utils;
|
||
|
|
import com.hjq.http.EasyConfig;
|
||
|
|
import com.hjq.http.config.IRequestInterceptor;
|
||
|
|
import com.hjq.http.config.IRequestServer;
|
||
|
|
import com.hjq.http.model.HttpHeaders;
|
||
|
|
import com.hjq.http.model.HttpParams;
|
||
|
|
import com.rehome.zhdcoa.bean.UserInfoBean;
|
||
|
|
import com.rehome.zhdcoa.utils.SPUtils;
|
||
|
|
//import com.squareup.leakcanary.LeakCanary;
|
||
|
|
//import com.squareup.leakcanary.RefWatcher;
|
||
|
|
import com.tencent.bugly.crashreport.CrashReport;
|
||
|
|
import com.xiaomi.channel.commonutils.logger.LoggerInterface;
|
||
|
|
import com.xiaomi.mipush.sdk.Logger;
|
||
|
|
import com.xiaomi.mipush.sdk.MiPushClient;
|
||
|
|
import com.xuexiang.xui.XUI;
|
||
|
|
import com.yolanda.nohttp.NoHttp;
|
||
|
|
import com.zhy.autolayout.config.AutoLayoutConifg;
|
||
|
|
|
||
|
|
import org.litepal.LitePalApplication;
|
||
|
|
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
import okhttp3.OkHttpClient;
|
||
|
|
|
||
|
|
public class App extends LitePalApplication {
|
||
|
|
|
||
|
|
private UserInfoBean.UserInfo userInfo;
|
||
|
|
|
||
|
|
private String DateSave;
|
||
|
|
|
||
|
|
public String getDateSave() {
|
||
|
|
return DateSave;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setDateSave(String dateSave) {
|
||
|
|
DateSave = dateSave;
|
||
|
|
}
|
||
|
|
|
||
|
|
private static App mInstance;
|
||
|
|
//public static boolean mIsInitTBSSuccess = false;
|
||
|
|
public static boolean mqttIsInit = false;
|
||
|
|
private int activityAount = 0;
|
||
|
|
private boolean isForeground = false;
|
||
|
|
|
||
|
|
|
||
|
|
public static App getInstance() {
|
||
|
|
return mInstance;
|
||
|
|
}
|
||
|
|
|
||
|
|
//private RefWatcher refWatcher;
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void onCreate() {
|
||
|
|
super.onCreate();
|
||
|
|
|
||
|
|
mInstance = this;
|
||
|
|
|
||
|
|
// if (LeakCanary.isInAnalyzerProcess(this)) { //1
|
||
|
|
// // This process is dedicated to LeakCanary for heap analysis.
|
||
|
|
// // You should not init your app in this process.
|
||
|
|
// return;
|
||
|
|
// }
|
||
|
|
|
||
|
|
//refWatcher = LeakCanary.install(this);
|
||
|
|
|
||
|
|
NoHttp.initialize(this);
|
||
|
|
MultiDex.install(this);
|
||
|
|
NoHttp.setDefaultConnectTimeout(6 * 1000);
|
||
|
|
NoHttp.setDefaultReadTimeout(60 * 1000);
|
||
|
|
initUser();
|
||
|
|
AutoLayoutConifg.getInstance().useDeviceSize();
|
||
|
|
Utils.init(this);
|
||
|
|
XUI.init(this); //初始化UI框架
|
||
|
|
CrashReport.initCrashReport(getApplicationContext(), "13d735012a", true);
|
||
|
|
LoggerInterface newLogger = new LoggerInterface() {
|
||
|
|
@Override
|
||
|
|
public void setTag(String tag) {
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void log(String content, Throwable t) {
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void log(String content) {
|
||
|
|
}
|
||
|
|
};
|
||
|
|
Logger.setLogger(this, newLogger);
|
||
|
|
|
||
|
|
|
||
|
|
// 网络请求框架初始化
|
||
|
|
IRequestServer server;
|
||
|
|
if (BuildConfig.DEBUG) {
|
||
|
|
server = new TestServer();
|
||
|
|
} else {
|
||
|
|
server = new ReleaseServer();
|
||
|
|
}
|
||
|
|
|
||
|
|
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||
|
|
.build();
|
||
|
|
|
||
|
|
EasyConfig.with(okHttpClient)
|
||
|
|
// 是否打印日志
|
||
|
|
//.setLogEnabled(BuildConfig.DEBUG)
|
||
|
|
// 设置服务器配置
|
||
|
|
.setServer(server)
|
||
|
|
// 设置请求处理策略
|
||
|
|
.setHandler(new RequestHandler(this))
|
||
|
|
// 设置请求参数拦截器
|
||
|
|
.setInterceptor(new IRequestInterceptor() {
|
||
|
|
@Override
|
||
|
|
public void intercept(String url, String tag, HttpParams params, HttpHeaders headers) {
|
||
|
|
headers.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
||
|
|
}
|
||
|
|
})
|
||
|
|
// 设置请求重试次数
|
||
|
|
.setRetryCount(1)
|
||
|
|
// 设置请求重试时间
|
||
|
|
.setRetryTime(1000)
|
||
|
|
// 添加全局请求参数
|
||
|
|
.addParam("token", "6666666")
|
||
|
|
// 添加全局请求头
|
||
|
|
//.addHeader("time", "20191030")
|
||
|
|
.into();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void initUser() {
|
||
|
|
this.userInfo = SPUtils.getUser(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public UserInfoBean.UserInfo getUserInfo() {
|
||
|
|
return userInfo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void setUserInfo(UserInfoBean.UserInfo userInfo) {
|
||
|
|
this.userInfo = userInfo;
|
||
|
|
SPUtils.putUser(this, userInfo);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
protected void attachBaseContext(Context base) {
|
||
|
|
super.attachBaseContext(base);
|
||
|
|
MultiDex.install(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void clearUser() {
|
||
|
|
this.userInfo = null;
|
||
|
|
SPUtils.clearUser(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
// public static RefWatcher getRefWatcher(Context context) {
|
||
|
|
// App application = (App) context.getApplicationContext();
|
||
|
|
// return application.refWatcher;
|
||
|
|
// }
|
||
|
|
|
||
|
|
|
||
|
|
}
|