|
|
|
|
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.annotation.Nullable;
|
|
|
|
|
import androidx.emoji.bundled.BundledEmojiCompatConfig;
|
|
|
|
|
import androidx.emoji.text.EmojiCompat;
|
|
|
|
|
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);
|
|
|
|
|
loadEmojiFromBundled();
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadEmojiFromBundled() {
|
|
|
|
|
EmojiCompat.Config config = new BundledEmojiCompatConfig(getApplicationContext());
|
|
|
|
|
|
|
|
|
|
config.setReplaceAll(true)
|
|
|
|
|
.registerInitCallback(new EmojiCompat.InitCallback()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public void onInitialized()
|
|
|
|
|
{
|
|
|
|
|
Log.i("app", "loadEmojiFromBundled()->onInitialized()");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFailed(@Nullable Throwable throwable)
|
|
|
|
|
{
|
|
|
|
|
Log.e("app", "loadEmojiFromBundled()->onFailed()", throwable);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
EmojiCompat.init(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// public static RefWatcher getRefWatcher(Context context) {
|
|
|
|
|
// App application = (App) context.getApplicationContext();
|
|
|
|
|
// return application.refWatcher;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|