123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package com.wdkl.callingmainnursemanager;
- import android.app.Application;
- import android.content.ComponentName;
- import android.content.Context;
- import android.content.Intent;
- import android.content.ServiceConnection;
- import android.net.wifi.WifiManager;
- import android.os.IBinder;
- import com.wdkl.callingmainnursemanager.entity.PartInfoEntity;
- import com.wdkl.callingmainnursemanager.entity.UdpEntity;
- import com.wdkl.callingmainnursemanager.service.APPService;
- import com.wdkl.callingmainnursemanager.util.ScreenExtinguishUtil;
- import com.wdkl.callingmainnursemanager.util.UdpHelper;
- import com.wdkl.callingmainnursemanager.util.anrfcutil.AnrFcExceptionUtil;
- import com.zhy.http.okhttp.OkHttpUtils;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.TimeUnit;
- import okhttp3.ConnectionPool;
- import okhttp3.OkHttpClient;
- import serialporttest.utils.SerialPortUtil;
- /**
- * Created by 胡博文 on 2017/8/17.
- * # #
- * # _oo0oo_ #
- * # o8888888o #
- * # 88" . "88 #
- * # (| -_- |) #
- * # 0\ = /0 #
- * # ___/`---'\___ #
- * # .' \\| |# '. #
- * # / \\||| : |||# \ #
- * # / _||||| -:- |||||- \ #
- * # | | \\\ - #/ | | #
- * # | \_| ''\---/'' |_/ | #
- * # \ .-\__ '-' ___/-. / #
- * # ___'. .' /--.--\ `. .'___ #
- * # ."" '< `.___\_<|>_/___.' >' "". #
- * # | | : `- \`.;`\ _ /`;.`/ - ` : | | #
- * # \ \ `_. \_ __\ /__ _/ .-` / / #
- * # =====`-.____`.___ \_____/___.-`___.-'===== #
- * # `=---=' #
- * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
- * # #
- * # 佛祖保佑 永无BUG #
- * # #
- */
- public class MyApplication extends Application {
- private static Context sAppContext;
- //全局的呼叫列表
- public volatile static ArrayList<UdpEntity> callEntityList;
- //轮播语音全局控制(20171102)
- public volatile static float PalyPhoneticsVolume = 1.0f;
- //轮播语音全局控制(20171102)
- public volatile static boolean PALYDISMISS = false;
- //是否关闭心跳(20180104)
- public volatile static boolean HEARTBEAT = true;
- //udp
- public static UdpHelper helper;
- //串口工具类
- public static SerialPortUtil serialPortUtil;
- public WifiManager wifiManager;
- public static ScreenExtinguishUtil mScreenExtinguishUtil;
- //全局科室列表
- public static List<PartInfoEntity.PartInfo> partInfoList;
- public MyApplication() {
- sAppContext = getAppContext();
- }
- private void initUdp() {
- wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
- helper = new UdpHelper(wifiManager, sAppContext);
- helper.run();
- }
- // private static RefWatcher refWatcher;
- //
- // public static RefWatcher getRefWatcher(Context context) {
- //
- // return refWatcher;
- // }
- @Override
- public void onCreate() {
- super.onCreate();
- // refWatcher = LeakCanary.install(this);
- //ANR奔溃异常处理
- AnrFcExceptionUtil.getInstance(this).initFCException();
- //屏幕息屏处理
- mScreenExtinguishUtil = ScreenExtinguishUtil.getInstance(this);
- mScreenExtinguishUtil.controlScreenLight();
- sAppContext = getApplicationContext();
- callEntityList = new ArrayList<>();
- partInfoList = new ArrayList<>();
- initUdp();
- initClient();
- serialPortUtil = new SerialPortUtil();
- serialPortUtil.openSerialPort();
- serialPortUtil.getKeyId();
- Intent bindIntent = new Intent(this, APPService.class);
- bindService(bindIntent, connection, BIND_AUTO_CREATE);
- }
- /**
- * 配置OkhttpClient
- */
- public void initClient() {
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .retryOnConnectionFailure(true)
- // .addInterceptor(myOkHttpRetryInterceptor)
- .connectionPool(new ConnectionPool())
- .connectTimeout(8000, TimeUnit.MILLISECONDS)
- .readTimeout(10000, TimeUnit.MILLISECONDS)
- .build();
- OkHttpUtils.initClient(okHttpClient);
- }
- public ServiceConnection connection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
- //APPService.ServiceBinder myBinder = (APPService.ServiceBinder) iBinder;
- }
- @Override
- public void onServiceDisconnected(ComponentName componentName) {
- }
- };
- public static Context getAppContext() {
- return sAppContext;
- }
- @Override
- public void onTerminate() { // 程序终止 (Waderson 20180123)
- super.onTerminate();
- //unbindService(connection);
- }
- }
|