MyApplication.java 5.4 KB

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