169 lines
4.8 KiB
Plaintext
Executable File
169 lines
4.8 KiB
Plaintext
Executable File
package com.example.administrator.ximengjianyu.base;
|
||
|
||
import android.app.Activity;
|
||
import android.app.Application;
|
||
import android.content.Context;
|
||
import android.content.Intent;
|
||
import android.os.Build;
|
||
import android.os.Handler;
|
||
import android.os.Message;
|
||
import android.support.annotation.RequiresApi;
|
||
import android.view.View;
|
||
import android.view.WindowManager;
|
||
import com.example.administrator.ximengjianyu.activity.LoginActivity;
|
||
import java.sql.SQLException;
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
|
||
import de.greenrobot.event.EventBus;
|
||
|
||
/**
|
||
* 全局单例,注意需要在清单文件里面进行配置
|
||
*/
|
||
public class MyApplication extends Application {
|
||
|
||
private static Context mContext;
|
||
private static Handler mMainThreadHandler;
|
||
private static int mMainThreadId;
|
||
private int time = 1000 * 2 * 60 * 60;
|
||
|
||
|
||
|
||
private static MyApplication instance;
|
||
public static long refreshTime = -1;
|
||
|
||
|
||
|
||
|
||
/**
|
||
* 用来得到单例
|
||
*
|
||
* @return
|
||
*/
|
||
public static MyApplication getInstance() {
|
||
return instance;
|
||
}
|
||
|
||
/**
|
||
* OkHttpUtils表单请求数据的部分
|
||
*/
|
||
// private static PostFormBuilder formBuilder;
|
||
|
||
// private static synchronized void syncInitFormBuilder(){
|
||
// if (formBuilder == null){
|
||
// formBuilder = OkHttpUtils.post();
|
||
// }
|
||
// }
|
||
|
||
// public static PostFormBuilder getFormBuilderInstance(){
|
||
// if (formBuilder == null){
|
||
// syncInitFormBuilder();
|
||
// }
|
||
// return formBuilder;
|
||
// }
|
||
|
||
/**
|
||
* 内存缓存的集合
|
||
*/
|
||
private Map<String, String> mMemProtocolCacheMap = new HashMap<>();
|
||
|
||
|
||
private static final int LIANWANG_PANDUAN = 0;
|
||
private Handler mHandler = new Handler() {
|
||
@Override
|
||
public void handleMessage(Message msg) {
|
||
switch (msg.what) {
|
||
case LIANWANG_PANDUAN:
|
||
//进行联网获取数据的操作
|
||
// ConnectInternet();
|
||
break;
|
||
}
|
||
}
|
||
};
|
||
|
||
/**
|
||
* 程序的入口方法
|
||
*/
|
||
public static WindowManager windowManager;
|
||
public static View view;
|
||
public static WindowManager.LayoutParams params;
|
||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||
@Override
|
||
public void onCreate() {
|
||
instance = this;
|
||
/**************************** 来电显示 **********************************/
|
||
windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||
params = new WindowManager.LayoutParams();
|
||
// params.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
|
||
// params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||
// /*设置窗口展示大小*/
|
||
// params.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
||
// params.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||
// params.alpha = 0.8f;
|
||
/**********************************************************************/
|
||
|
||
|
||
//上下文
|
||
mContext = getApplicationContext();
|
||
|
||
|
||
//主线程的Handler
|
||
mMainThreadHandler = new Handler();
|
||
|
||
/**
|
||
* 获取主线程的线程id
|
||
* myTid:Thread
|
||
* myPid:Process
|
||
* myUid:User
|
||
*/
|
||
mMainThreadId = android.os.Process.myTid();
|
||
super.onCreate();
|
||
//获取当前默认未捕获异常的异常处理器
|
||
mHandler.sendEmptyMessageDelayed(LIANWANG_PANDUAN, time);
|
||
|
||
}
|
||
|
||
|
||
|
||
private class MyExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||
//当发现了未捕获异常的时候调用的方法
|
||
@Override
|
||
public void uncaughtException(Thread thread, Throwable ex) {
|
||
//自杀的方法. 早死早超生
|
||
android.os.Process.killProcess(android.os.Process.myPid());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 得到上下文
|
||
*/
|
||
public static Context getContext() {
|
||
return mContext;
|
||
}
|
||
|
||
/**
|
||
* 得到主线程里面的创建的一个hanlder
|
||
*/
|
||
public static Handler getMainThreadHandler() {
|
||
return mMainThreadHandler;
|
||
}
|
||
|
||
/**
|
||
* 得到主线程的线程id
|
||
*/
|
||
public static int getMainThreadId() {
|
||
return mMainThreadId;
|
||
}
|
||
/**
|
||
* 该方法是token失效,重新进入登录页面
|
||
*/
|
||
public static void restartLoginActivity(Activity activity){
|
||
activity.startActivity(new Intent(activity, LoginActivity.class));
|
||
LoginViewEvent event = new LoginViewEvent(); //发布事件,显示登录界面
|
||
event.showWait = false;
|
||
event.closeHomeActivity = true;
|
||
EventBus.getDefault().postSticky(event);
|
||
activity.finish();
|
||
}
|
||
}
|