InitActivity.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. package com.wdkl.callingbed2.ui;
  2. import android.annotation.SuppressLint;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.content.SharedPreferences;
  6. import android.graphics.drawable.AnimationDrawable;
  7. import android.media.MediaPlayer;
  8. import android.media.MediaRecorder;
  9. import android.net.ConnectivityManager;
  10. import android.net.NetworkInfo;
  11. import android.os.Environment;
  12. import android.os.Handler;
  13. import android.os.Message;
  14. import android.util.Log;
  15. import android.view.View;
  16. import android.widget.ImageView;
  17. import com.google.gson.Gson;
  18. import com.wdkl.callingbed2.MyApplication;
  19. import com.wdkl.callingbed2.R;
  20. import com.wdkl.callingbed2.base.BaseActivity;
  21. import com.wdkl.callingbed2.common.Constants;
  22. import com.wdkl.callingbed2.entity.InitDataEntity;
  23. import com.wdkl.callingbed2.entity.MessageEvent;
  24. import com.wdkl.callingbed2.service.SoundPoolManager;
  25. import com.wdkl.callingbed2.util.AutoRebootUtil;
  26. import com.wdkl.callingbed2.util.CutSerialPortUtil;
  27. import com.wdkl.callingbed2.util.DateUtil;
  28. import com.wdkl.callingbed2.util.DownloadUtil;
  29. import com.wdkl.callingbed2.util.LogUtil;
  30. import com.wdkl.callingbed2.util.NetUtil;
  31. import com.wdkl.callingbed2.util.ScreenManagerUtil;
  32. import com.wdkl.callingbed2.util.StringUtils;
  33. import com.wdkl.callingbed2.util.ToastUtil;
  34. import com.wdkl.callingbed2.util.UdpSendUtil;
  35. import com.wdkl.callingbed2.util.VoiceManagerUtil;
  36. import com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand;
  37. import com.zhy.http.okhttp.OkHttpUtils;
  38. import com.zhy.http.okhttp.callback.StringCallback;
  39. import org.greenrobot.eventbus.Subscribe;
  40. import org.greenrobot.eventbus.ThreadMode;
  41. import org.json.JSONObject;
  42. import java.io.File;
  43. import java.io.IOException;
  44. import butterknife.Bind;
  45. import butterknife.OnClick;
  46. import okhttp3.Call;
  47. import serialporttest.utils.SerialPortUtil;
  48. import static com.wdkl.callingbed2.util.AutoRebootUtil.ethreboot;
  49. import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.closeHeart;
  50. import static com.wdkl.callingbed2.util.sendcommand.CallingBedSendCommand.setNurseBrightness;
  51. /**
  52. * 类名称:InitActivity <br>
  53. * 类描述:APP初始化页面<br>
  54. * 创建人:Waderson <br>
  55. * 创建时间:2018-02-01 <br>
  56. *
  57. * @version V1.0
  58. */
  59. public class InitActivity extends BaseActivity implements SerialPortUtil.ISerialPortBedOnclickEvent, SerialPortUtil.ISerialPortBedOnclickString {
  60. @Bind(R.id.activity_init_layout_rl)
  61. View initView;
  62. @Bind(R.id.activity_init_layout_iv_loading)
  63. ImageView ivLoading;
  64. AnimationDrawable animationDrawable;
  65. ConnectivityManager cm;
  66. /**
  67. * mac地址
  68. */
  69. String macAddress = "";
  70. SerialPortUtil serialPortUtil;
  71. private int countsReboot;//重启计数
  72. @Override
  73. public int getLayoutId() {
  74. return R.layout.activity_init_layout;
  75. }
  76. @Override
  77. protected void initView() {
  78. ivLoading.setVisibility(View.VISIBLE);
  79. animationDrawable = (AnimationDrawable) ivLoading.getBackground();
  80. animationDrawable.start();
  81. SoundPoolManager.getInstance().init();
  82. VoiceManagerUtil.setMusicVoice(MyApplication.getAppContext(), 100);
  83. }
  84. @Override
  85. protected void initUtil() {
  86. serialPortUtil = MyApplication.serialPortUtil;
  87. serialPortUtil.setOnDataReceiveListener(this);
  88. serialPortUtil.setOnDataReceiveStringListener(this);
  89. File file = new File(TEST_AUDIO_FILE_PATH);
  90. if (!file.exists()) {
  91. file.mkdir();
  92. }
  93. }
  94. @Override
  95. protected void initData() {
  96. //刚进来的时候将所有的护理灯全部灭掉
  97. dismissNurseBrightness();
  98. //20190415 waderson
  99. ScreenManagerUtil.setScreenBrightness(context, 210);
  100. dateRefresh();
  101. }
  102. @Override
  103. public View getLoadingTargetView() {
  104. return initView;
  105. }
  106. @OnClick(R.id.activity_init_layout_rl)
  107. public void init(View view) {
  108. isNewWork();
  109. }
  110. /**
  111. * 获取网络请求地址头
  112. */
  113. private void getLocalWayAddress() {
  114. try {
  115. //Constants.URL = "http://" + NetUtil.getLocalElement(NetUtil.getLocalInetAddress().toString());
  116. Constants.URL = "http://" + NetUtil.getLocalElement(3);
  117. } catch (Exception e) {
  118. LogUtil.e("getLocalWayAddress", "Exception==" + e.toString());
  119. CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
  120. showNetErrorView("MAC地址: " + macAddress + "\nError:请检查网络连接是否正常"
  121. + "\n" + AutoRebootUtil.getTextTip());
  122. e.printStackTrace();
  123. }
  124. }
  125. /**
  126. * 获取MAC地址
  127. */
  128. private void getMacAddress() {
  129. if (NetUtil.isethernetConnected(cm)) {
  130. macAddress = NetUtil.getMacAddress();
  131. if (null != macAddress) {
  132. SharedPreferences sharedPreferences = getSharedPreferences(Constants.MSG_SP, Context.MODE_PRIVATE); //私有数据
  133. SharedPreferences.Editor editor = sharedPreferences.edit();
  134. editor.putString("macAddress", macAddress);
  135. editor.commit();//提交修改
  136. }
  137. } else {
  138. SharedPreferences sharedPreferences = getSharedPreferences(Constants.MSG_SP, Context.MODE_PRIVATE); //私有数据
  139. macAddress = sharedPreferences.getString("macAddress", null);
  140. }
  141. LogUtil.d("getMacAddress", "macAddress==" + macAddress);
  142. Constants.MAC_ADDRESS = macAddress;
  143. }
  144. /**
  145. * 判断网络连接
  146. * 无网络显示错误页面
  147. */
  148. public void isNewWork() {
  149. if (cm != null) {
  150. //ethreboot();//wuyq add
  151. String ipStr = NetUtil.getLocalIP();
  152. NetworkInfo networkInfo = cm.getActiveNetworkInfo();
  153. if (networkInfo != null && networkInfo.isConnected()) { //wuyq modify
  154. if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
  155. CallingBedSendCommand.setSipStatus(serialPortUtil, "2");
  156. getInitData();
  157. countsReboot = 0; //wuyq add
  158. } else {
  159. updateHandler.sendEmptyMessageDelayed(404, DATEREFRESH_DELAYMILLIS);
  160. showNetErrorView("MAC地址: " + macAddress + " IP地址: " + ipStr + "\nError:本地网络或wifi连接错误");
  161. ToastUtil.showToast("本地网络或wifi连接错误");
  162. CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
  163. }
  164. } else {
  165. //updateHandler.sendEmptyMessageDelayed(404, DATEREFRESH_DELAYMILLIS);//wuyq remove
  166. updateHandler.sendEmptyMessageDelayed(4444, DATEREFRESH_DELAYMILLIS);//wuyq add
  167. CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
  168. showNetErrorView("MAC地址: " + macAddress + " IP地址: " + ipStr + "\nError:无网络连接;以太网是否连接正常?");//网络信息初始化错误
  169. ToastUtil.showToast("无网络连接;以太网是否连接正常?");//网络信息初始化错误
  170. //autoReboot();//wuyq remove
  171. }
  172. } else {
  173. updateHandler.sendEmptyMessageDelayed(404, DATEREFRESH_DELAYMILLIS);
  174. showNetErrorView("MAC地址: " + macAddress + "\nError:ConnectivityManager初始化失败");
  175. CallingBedSendCommand.setSipStatus(serialPortUtil, "0");
  176. ToastUtil.showToast("ConnectivityManager初始化失败");
  177. }
  178. }
  179. /**
  180. * =================================================(网络不通)15次以上自动重启系统=====================================================
  181. */
  182. private void autoReboot() {
  183. if (countsReboot == 16) {
  184. AutoRebootUtil.calculate(this);
  185. countsReboot = 0;
  186. }
  187. countsReboot++;
  188. }
  189. /**
  190. * 检查APP更新版本
  191. *
  192. */
  193. private void appCheckUpdate() {
  194. if (!StringUtils.notEmpty(Constants.URL)) return;
  195. if (!StringUtils.notEmpty(Constants.PartID)) return;
  196. try {
  197. OkHttpUtils.post().url(Constants.URL + Constants.URL_END + Constants.APP_CHECK_UPDATE)
  198. .addParams("PartID", Constants.PartID)
  199. .build()
  200. .execute(new StringCallback() {
  201. @Override
  202. public void onError(Call call, Exception e, int id) {
  203. Constants.UPDATE_APP_FLAG = false;
  204. }
  205. @Override
  206. public void onResponse(String response, int id) {
  207. String data = response.substring(0, response.length() - 4);
  208. LogUtil.d("appCheckUpdate", "appCheckUpdate==" + data);
  209. try {
  210. JSONObject object = new JSONObject(data);
  211. if (object.getString("Code").equals("OK!")) {
  212. float APPVersion = StringUtils.parseFloat(StringUtils.deleteCharAt(object.getString("APPVersion"), 0));
  213. float APPVersion_Now = StringUtils.parseFloat(StringUtils.getAppVersionName(InitActivity.this));
  214. String downloadURL = object.getString("downloadURL");
  215. if (APPVersion_Now != APPVersion) {//本来是“<”的;但有个别机器老是不升级成功
  216. if (StringUtils.notEmpty(downloadURL)) {
  217. closeHeart();//关闭心跳
  218. DownloadUtil.APP_VERSION = APPVersion;
  219. Intent intent = new Intent(InitActivity.this, APPUpdateActivity.class);
  220. intent.putExtra("downLoadURL", Constants.URL + Constants.URL_END + "/" + downloadURL);
  221. startActivity(intent);
  222. }
  223. }
  224. }
  225. } catch (Exception e) {
  226. e.printStackTrace();
  227. Constants.UPDATE_APP_FLAG = false;
  228. }
  229. }
  230. });
  231. } catch (Exception e) {
  232. Constants.UPDATE_APP_FLAG = false;
  233. e.printStackTrace();
  234. }
  235. }
  236. /**
  237. * 获取初始化信息
  238. */
  239. private void getInitData() {
  240. LogUtil.d("getInitData", "URL==" + Constants.URL + Constants.URL_END + Constants.CALLINGBED_INIT);
  241. final String ipStr = NetUtil.getLocalIP();
  242. if (Constants.URL.length() > 7) {
  243. OkHttpUtils
  244. .post()
  245. .url(Constants.URL + Constants.URL_END + Constants.CALLINGBED_INIT)
  246. .addParams("deviceMAC", macAddress)
  247. .build()
  248. .execute(new StringCallback() {
  249. @Override
  250. public void onError(Call call, Exception e, int id) {
  251. ivLoading.setVisibility(View.INVISIBLE);
  252. dismissNurseBrightness();
  253. showNetErrorView("MAC地址: " + macAddress + " IP地址: " + ipStr + "\nError:" + "初始化数据请求错误[MAC地址是否注册?]");
  254. //updateHandler.sendEmptyMessageDelayed(404, DATEREFRESH_DELAYMILLIS);//wuyq remove
  255. updateHandler.sendEmptyMessageDelayed(4444, DATEREFRESH_DELAYMILLIS);//wuyq add
  256. ToastUtil.showToast("初始化数据请求错误");
  257. }
  258. @Override
  259. public void onResponse(String response, int id) {
  260. String data = response.substring(0, response.length() - 4);
  261. ivLoading.setVisibility(View.INVISIBLE);
  262. LogUtil.d("getInitData", "getInitData==" + data);
  263. try {
  264. showContent();
  265. JSONObject object = new JSONObject(data);
  266. if (object.getString("Code").equals("ERROR!")) {
  267. dismissNurseBrightness();
  268. showNetErrorView("MAC地址: " + macAddress + " IP地址: " + ipStr + "\nError:" + "数据错误异常[ERROR!]");
  269. updateHandler.sendEmptyMessageDelayed(404, DATEREFRESH_DELAYMILLIS);
  270. ToastUtil.showToast("数据请求失败");
  271. } else {
  272. if (object.getString("deviceStatus").equals("1")) {
  273. Gson gson = new Gson();
  274. InitDataEntity initDataEntity = gson.fromJson(data, InitDataEntity.class);
  275. saveData(initDataEntity);
  276. Intent intent = new Intent();
  277. intent.putExtra(Constants.INITENTITY, initDataEntity);
  278. intent.setClass(InitActivity.this, CallingBedActivity.class);
  279. startActivity(intent);
  280. InitActivity.this.finish();
  281. } else {
  282. dismissNurseBrightness();
  283. showNetErrorView("MAC地址: " + macAddress + " IP地址: " + ipStr + "\nError: " + "设备未启用");
  284. updateHandler.sendEmptyMessageDelayed(404, DATEREFRESH_DELAYMILLIS);
  285. ToastUtil.showToast("设备未启用");
  286. }
  287. }
  288. } catch (Exception e) {
  289. LogUtil.d("getInitData", "getInitData==Exception");
  290. showNetErrorView("MAC地址: " + macAddress + "\nError:" + "Response was Exception");
  291. e.printStackTrace();
  292. }
  293. }
  294. });
  295. }
  296. }
  297. private void saveData(InitDataEntity initDataEntity) {
  298. if (null != initDataEntity) {
  299. Constants.SIP_ID = initDataEntity.getDeviceSipId();
  300. Constants.SIP_PASS_WORD = initDataEntity.getDeviceSipPassWord();
  301. Constants.SIP_IP = initDataEntity.getDeviceSipIp();
  302. Constants.DEVICE_WIFI_HOST_NAME = initDataEntity.getDeviceWifiHostName();
  303. Constants.BED_ID = initDataEntity.getId();
  304. Constants.CALLMAIN_ID = initDataEntity.getDeviceHostingID();
  305. Constants.MYSELF_ID = initDataEntity.getId();
  306. Constants.ROOM_ID = initDataEntity.getDeviceRoomId();
  307. Constants.DEVICE_SCREEN_SLEEP = initDataEntity.getDeviceScreamSleep();
  308. Constants.DEVICE_HUMAN_ID = initDataEntity.getDeviceHumanId();
  309. Constants.PartID = initDataEntity.getPartId();
  310. LogUtil.d("saveData", "deviceHostingID==" + initDataEntity.getDeviceHostingID());
  311. if (StringUtils.notEmpty(initDataEntity.getDeviceHostingID())) {
  312. String n = StringUtils.substringByLengh(initDataEntity.getDeviceHostingID(), 0, 1);
  313. if ("#".equals(n)) {//服务器托管状态:处于托管中
  314. String nDis = StringUtils.deleteCharAt(initDataEntity.getDeviceHostingID(), 0);
  315. Constants.DEVICE_HOSTING_ID = nDis.split(",")[0];
  316. Constants.TRUST_NEW_MAIN_ID = nDis.split(",")[1];
  317. } else {//服务器托管状态:处于未托管
  318. Constants.DEVICE_HOSTING_ID = initDataEntity.getDeviceHostingID();
  319. Constants.TRUST_NEW_MAIN_ID = "";
  320. }
  321. }
  322. setSystemTime(initDataEntity);
  323. }
  324. }
  325. /**
  326. * 设置系统时间 (邓喆)
  327. *
  328. * @param initDataEntity
  329. */
  330. private void setSystemTime(InitDataEntity initDataEntity) {
  331. LogUtil.d("setSystemTime", initDataEntity.getCurTime());
  332. String[] time = initDataEntity.getCurTime().trim().split(" ");
  333. String[] day = time[0].split("/");
  334. String[] hour = time[1].split(":");
  335. //=================设置时间(可用)
  336. DateUtil.setSystemTime(this, Integer.valueOf(day[0]), Integer.valueOf(day[1]) - 1, Integer.valueOf(day[2])
  337. , Integer.valueOf(hour[0]), Integer.valueOf(hour[1]), Integer.valueOf(hour[2]));
  338. // if (!TimeUtil.isRoot()) {
  339. // String t = initDataEntity.getCurTime().trim().replaceAll("/", "").replace(":", "").replace(" ", ".");
  340. // if (t != null && t != "") {
  341. // TimeUtil.setSysDate(t);
  342. // }
  343. // }
  344. }
  345. @Override
  346. public void onReload() {
  347. super.onReload();
  348. dateRefresh();
  349. }
  350. public void dateRefresh() {
  351. cm = (ConnectivityManager) MyApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE);
  352. if (null != cm) getMacAddress();
  353. getLocalWayAddress();
  354. isNewWork();
  355. }
  356. @Override
  357. protected void onDestroy() {
  358. super.onDestroy();
  359. animationDrawable.stop();
  360. updateHandler = null;
  361. serialPortUtil = null;//2018-01-10 add by Waderson
  362. }
  363. /**
  364. * 灭掉护理灯
  365. */
  366. public void dismissNurseBrightness() {
  367. //7寸分机无护理灯
  368. /*new Thread(new Runnable() {
  369. @Override
  370. public void run() {
  371. try {
  372. setNurseBrightness(serialPortUtil, 1, "000000", "000000", "000000", "000000", "000000");
  373. } catch (InterruptedException e) {
  374. e.printStackTrace();
  375. }
  376. }
  377. }).start();*/
  378. }
  379. private boolean isRecord = false;
  380. private boolean isPlay = false;
  381. public static final String TEST_AUDIO_FILE_PATH = Environment.getExternalStorageDirectory().getPath() + "/test";
  382. private String audiofilePath;
  383. private MediaRecorder mediaRecorder;
  384. private MediaPlayer mediaPlayer;
  385. /**
  386. * 监听呼叫按钮 buffer[5] 如果按下则 放松注册信息给后台
  387. */
  388. @Override
  389. public void serialPortBedOnclick(byte[] buffer) {
  390. // mScreenExtinguishUtil.touchScreen();//===============================息屏
  391. LogUtil.d("serialPortBedOnclick", "buffer[5]==" + buffer[5] + ", buffer[8]==" + buffer[8]);
  392. //呼叫护士键短按/长按松开
  393. if (buffer[5] == 1 | buffer[5] == 2) {
  394. if (null != Constants.MAC_ADDRESS) {
  395. //有线mac地址,设备出场信息,无线mac地址
  396. final String str = "MGR_REG_A" + Constants.DELIMITER + Constants.MAC_ADDRESS + Constants.DELIMITER + "4" + Constants.DELIMITER + android.os.Build.DISPLAY +"_"+Constants.MCU_VERSION_NUMBER +
  397. Constants.DELIMITER + Constants.MAC_ADDRESS + Constants.DELIMITER + "FF:FF:FF:FF:FF:FF" + Constants.DELIMITER + SerialPortUtil.KEY_ID;
  398. UdpSendUtil.sendManualReboot(str);
  399. runOnUiThread(new Runnable() {
  400. @Override
  401. public void run() {
  402. ToastUtil.showToast("收到按键消息,发送注册信息:" + str);
  403. }
  404. });
  405. }
  406. }
  407. if (buffer[8] == 2) {
  408. SoundPoolManager.getInstance().playSound(3);
  409. new Thread(new Runnable() {
  410. @Override
  411. public void run() {
  412. boolean pingStatus = NetUtil.ping("192.168.101.1", 2, null);
  413. if (pingStatus) {
  414. showTips("连接192.168.101.1成功!");
  415. } else {
  416. showTips("连接192.168.101.1失败, 请检查设备!");
  417. }
  418. }
  419. }).start();
  420. }
  421. //测试麦克风录音
  422. if (buffer[6] == 2) {
  423. if (!isRecord && !isPlay) {
  424. startRecording();
  425. updateHandler.sendEmptyMessageDelayed(111, 3000);
  426. }
  427. }
  428. }
  429. @Override
  430. public void serialPortBedOnclickString(String str) {
  431. try {
  432. String newStr = str.substring(str.indexOf("$") + 1, str.indexOf("#"));
  433. LogUtil.d("serialPortBedOnclickString", "newStr==" + newStr);
  434. if (newStr.startsWith("V")) {
  435. Constants.MCU_VERSION_NUMBER = newStr.substring(newStr.indexOf(",") + 1, 16);
  436. LogUtil.d("serialPortBedOnclick", "Constants.MCU_VERSION_NUMBER==" + Constants.MCU_VERSION_NUMBER);
  437. }
  438. } catch (Exception e) {
  439. e.printStackTrace();
  440. }
  441. }
  442. private void showTips(final String tips) {
  443. runOnUiThread(new Runnable() {
  444. @Override
  445. public void run() {
  446. ToastUtil.showToast(tips);
  447. }
  448. });
  449. }
  450. private void startRecording() {
  451. showTips("开始录音");
  452. new Thread(new Runnable() {
  453. @Override
  454. public void run() {
  455. mediaRecorder = new MediaRecorder();
  456. try {
  457. audiofilePath = TEST_AUDIO_FILE_PATH + "/" + System.currentTimeMillis() + "_test.mp3";
  458. mediaRecorder.setOutputFile(audiofilePath);
  459. mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);// 设置MediaRecorder的音频源为麦克风
  460. mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);// 设置MediaRecorder录制的音频格式
  461. mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);// 设置MediaRecorder录制音频的编码为amr
  462. mediaRecorder.prepare();
  463. mediaRecorder.start();
  464. } catch (IOException e) {
  465. Log.i("error", "call startAmr(File mRecAudioFile) failed!" + e.getMessage());
  466. } finally {
  467. isRecord = false;
  468. }
  469. }
  470. }).start();
  471. }
  472. private void stopRecord() {
  473. showTips("结束录音");
  474. new Thread(new Runnable() {
  475. @Override
  476. public void run() {
  477. try {
  478. mediaRecorder.stop();
  479. mediaRecorder.release();
  480. mediaRecorder = null;
  481. Thread.sleep(200);
  482. mediaPlayer = new MediaPlayer();
  483. mediaPlayer.reset();
  484. mediaPlayer.setDataSource(audiofilePath);
  485. mediaPlayer.setVolume(1.0f, 1.0f);
  486. mediaPlayer.prepare();
  487. mediaPlayer.start();
  488. mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
  489. @Override
  490. public void onCompletion(MediaPlayer player) {
  491. File file = new File(audiofilePath);
  492. if (file.exists()) {
  493. file.delete();
  494. }
  495. mediaPlayer.release();
  496. }
  497. });
  498. mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
  499. @Override
  500. public boolean onError(MediaPlayer player, int what, int extra) {
  501. File file = new File(audiofilePath);
  502. if (file.exists()) {
  503. file.delete();
  504. }
  505. mediaPlayer.release();
  506. return false;
  507. }
  508. });
  509. }catch (Exception e) {
  510. e.printStackTrace();
  511. } finally {
  512. isPlay = false;
  513. }
  514. }
  515. }).start();
  516. }
  517. @SuppressLint("HandlerLeak")
  518. Handler updateHandler = new Handler() {
  519. public void handleMessage(Message msg) {
  520. switch (msg.what) {
  521. case 404:
  522. dateRefresh();
  523. break;
  524. case 4444: // wuyq add
  525. ethreboot();
  526. dateRefresh();
  527. break;
  528. case 111:
  529. if (!isPlay) {
  530. stopRecord();
  531. }
  532. break;
  533. }
  534. }
  535. };
  536. public static final long DATEREFRESH_DELAYMILLIS = 8000;
  537. @Subscribe(threadMode = ThreadMode.MAIN)
  538. public void onMoonEvent(MessageEvent messageEvent) {
  539. switch (messageEvent.getType()) {
  540. case Constants.EVENT_MGR_APP_UPDATE://APP更新
  541. appCheckUpdate();
  542. break;
  543. }
  544. }
  545. }