MyApplication.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package com.wdkl.callingmainnursemanager;
  2. import android.app.Application;
  3. import android.content.ComponentName;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.ServiceConnection;
  7. import android.net.wifi.WifiManager;
  8. import android.os.IBinder;
  9. import com.wdkl.callingmainnursemanager.entity.PartInfoEntity;
  10. import com.wdkl.callingmainnursemanager.entity.UdpEntity;
  11. import com.wdkl.callingmainnursemanager.service.APPService;
  12. import com.wdkl.callingmainnursemanager.util.ScreenExtinguishUtil;
  13. import com.wdkl.callingmainnursemanager.util.UdpHelper;
  14. import com.wdkl.callingmainnursemanager.util.anrfcutil.AnrFcExceptionUtil;
  15. import com.zhy.http.okhttp.OkHttpUtils;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import java.util.concurrent.TimeUnit;
  19. import okhttp3.ConnectionPool;
  20. import okhttp3.OkHttpClient;
  21. import serialporttest.utils.SerialPortUtil;
  22. /**
  23. * Created by 胡博文 on 2017/8/17.
  24. * # #
  25. * # _oo0oo_ #
  26. * # o8888888o #
  27. * # 88" . "88 #
  28. * # (| -_- |) #
  29. * # 0\ = /0 #
  30. * # ___/`---'\___ #
  31. * # .' \\| |# '. #
  32. * # / \\||| : |||# \ #
  33. * # / _||||| -:- |||||- \ #
  34. * # | | \\\ - #/ | | #
  35. * # | \_| ''\---/'' |_/ | #
  36. * # \ .-\__ '-' ___/-. / #
  37. * # ___'. .' /--.--\ `. .'___ #
  38. * # ."" '< `.___\_<|>_/___.' >' "". #
  39. * # | | : `- \`.;`\ _ /`;.`/ - ` : | | #
  40. * # \ \ `_. \_ __\ /__ _/ .-` / / #
  41. * # =====`-.____`.___ \_____/___.-`___.-'===== #
  42. * # `=---=' #
  43. * # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
  44. * # #
  45. * # 佛祖保佑 永无BUG #
  46. * # #
  47. */
  48. public class MyApplication extends Application {
  49. private static Context sAppContext;
  50. //全局的呼叫列表
  51. public volatile static ArrayList<UdpEntity> callEntityList;
  52. //轮播语音全局控制(20171102)
  53. public volatile static float PalyPhoneticsVolume = 1.0f;
  54. //轮播语音全局控制(20171102)
  55. public volatile static boolean PALYDISMISS = false;
  56. //是否关闭心跳(20180104)
  57. public volatile static boolean HEARTBEAT = true;
  58. //udp
  59. public static UdpHelper helper;
  60. //串口工具类
  61. public static SerialPortUtil serialPortUtil;
  62. public WifiManager wifiManager;
  63. public static ScreenExtinguishUtil mScreenExtinguishUtil;
  64. //全局科室列表
  65. public static List<PartInfoEntity.PartInfo> partInfoList;
  66. public MyApplication() {
  67. sAppContext = getAppContext();
  68. }
  69. private void initUdp() {
  70. wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
  71. helper = new UdpHelper(wifiManager, sAppContext);
  72. helper.run();
  73. }
  74. // private static RefWatcher refWatcher;
  75. //
  76. // public static RefWatcher getRefWatcher(Context context) {
  77. //
  78. // return refWatcher;
  79. // }
  80. @Override
  81. public void onCreate() {
  82. super.onCreate();
  83. // refWatcher = LeakCanary.install(this);
  84. //ANR奔溃异常处理
  85. AnrFcExceptionUtil.getInstance(this).initFCException();
  86. //屏幕息屏处理
  87. mScreenExtinguishUtil = ScreenExtinguishUtil.getInstance(this);
  88. mScreenExtinguishUtil.controlScreenLight();
  89. sAppContext = getApplicationContext();
  90. callEntityList = new ArrayList<>();
  91. partInfoList = new ArrayList<>();
  92. initUdp();
  93. initClient();
  94. serialPortUtil = new SerialPortUtil();
  95. serialPortUtil.openSerialPort();
  96. serialPortUtil.getKeyId();
  97. Intent bindIntent = new Intent(this, APPService.class);
  98. bindService(bindIntent, connection, BIND_AUTO_CREATE);
  99. }
  100. /**
  101. * 配置OkhttpClient
  102. */
  103. public void initClient() {
  104. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  105. .retryOnConnectionFailure(true)
  106. // .addInterceptor(myOkHttpRetryInterceptor)
  107. .connectionPool(new ConnectionPool())
  108. .connectTimeout(8000, TimeUnit.MILLISECONDS)
  109. .readTimeout(10000, TimeUnit.MILLISECONDS)
  110. .build();
  111. OkHttpUtils.initClient(okHttpClient);
  112. }
  113. public ServiceConnection connection = new ServiceConnection() {
  114. @Override
  115. public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
  116. //APPService.ServiceBinder myBinder = (APPService.ServiceBinder) iBinder;
  117. }
  118. @Override
  119. public void onServiceDisconnected(ComponentName componentName) {
  120. }
  121. };
  122. public static Context getAppContext() {
  123. return sAppContext;
  124. }
  125. @Override
  126. public void onTerminate() { // 程序终止 (Waderson 20180123)
  127. super.onTerminate();
  128. //unbindService(connection);
  129. }
  130. }