From b4f0e07335e97d66d5a40c396f15a772619066b0 Mon Sep 17 00:00:00 2001
From: 张海江 <181069201@qq.com>
Date: Mon, 26 Mar 2018 13:23:07 +0800
Subject: [PATCH] 提交代码,准备改版

---
 app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java |  108 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 86 insertions(+), 22 deletions(-)

diff --git a/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java b/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java
index 6680050..6f1b46a 100644
--- a/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java
+++ b/app/src/main/java/com/moral/yunfushao/fragment/FragmentMonitor.java
@@ -5,8 +5,11 @@
 import android.bluetooth.BluetoothGattService;
 import android.content.Context;
 import android.content.Intent;
+import android.content.res.AssetManager;
+import android.media.MediaPlayer;
 import android.os.Bundle;
 import android.os.Handler;
+import android.os.Message;
 import android.support.annotation.Nullable;
 import android.text.TextUtils;
 import android.util.Log;
@@ -38,6 +41,7 @@
 import com.moral.yunfushao.model.EventMessage;
 import com.moral.yunfushao.model.RecData;
 import com.moral.yunfushao.model.UpLoadParam;
+import com.moral.yunfushao.model.VoiceBean;
 import com.moral.yunfushao.ui.PanelView;
 
 import org.greenrobot.eventbus.EventBus;
@@ -56,6 +60,13 @@
  */
 
 public class FragmentMonitor extends BaseFragment {
+    /**
+     * ������������
+     */
+    private ArrayList<VoiceBean> voiceList = new ArrayList<>();
+    AssetManager am;
+    MediaPlayer mp;
+
     private LinearLayout ll_status;
     private TextView tv_ljjl, tv_tishi, tv_desc, tv_shishi, tv_status;
     private PanelView pv;
@@ -140,10 +151,6 @@
 
                         });
                 /**
-                 * ������������������������
-                 */
-                heart();
-                /**
                  * ������������������
                  */
                 handler.postDelayed(new Runnable() {
@@ -152,6 +159,17 @@
                         checkTime();
                     }
                 }, 2000);
+                /**
+                 * ������������������������
+                 */
+                if (mBluetoothService == null) {
+                    return;
+                }
+                if (mBluetoothService.getWirteCharacteristic() == null) {
+                    return;
+                }
+                mBluetoothService.write(mBluetoothService.getWirteCharacteristic().getService().getUuid().toString(), mBluetoothService.getWirteCharacteristic().getUuid().toString(), BLECommon.BLE_HEART, null);
+                heart();
             }
         } else if (msg.getType() == AppConfig.GET_BLE_DISCONNECT) {
             pv.setStatusStr("���������");
@@ -173,6 +191,17 @@
     public void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         EventBus.getDefault().register(this);
+        VoiceBean voiceBean = new VoiceBean();
+        voiceBean.setId(0);
+        voiceBean.setRes(R.raw.music);
+        voiceBean.setName("music");
+        voiceList.add(voiceBean);
+        voiceBean = new VoiceBean();
+        voiceBean.setId(1);
+        voiceBean.setRes(R.raw.music1);
+        voiceBean.setName("music1");
+        voiceList.add(voiceBean);
+
     }
 
     @Override
@@ -192,6 +221,7 @@
             timer.cancel();
             timer = null;
         }
+        stop();
     }
 
     @Override
@@ -281,21 +311,34 @@
     /**
      * ���������������������3������
      */
+    Handler heartHandler = new Handler(){
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case 1:
+                    //������������
+                    if (mBluetoothService == null) {
+                        return;
+                    }
+                    if (mBluetoothService.getWirteCharacteristic() == null) {
+                        return;
+                    }
+                    mBluetoothService.write(mBluetoothService.getWirteCharacteristic().getService().getUuid().toString(), mBluetoothService.getWirteCharacteristic().getUuid().toString(), BLECommon.BLE_HEART, null);
+                    break;
+            }
+            super.handleMessage(msg);
+        }
+
+    };
     private void heart() {
         heartTimer = new Timer();
         heartTimer.schedule(new TimerTask() {
             @Override
             public void run() {
-                //������������
-                if (mBluetoothService == null) {
-                    return;
-                }
-                if (mBluetoothService.getWirteCharacteristic() == null) {
-                    return;
-                }
-                mBluetoothService.write(mBluetoothService.getWirteCharacteristic().getService().getUuid().toString(), mBluetoothService.getWirteCharacteristic().getUuid().toString(), BLECommon.BLE_HEART, null);
+                Message message = new Message();
+                message.what = 1;
+                heartHandler.sendMessage(message);
             }
-        }, 0, 1000 * 60 * 3);
+        }, 0, 1000 * 60*3);
     }
 
     private long timeComplete = 0;
@@ -446,30 +489,34 @@
             data.setTime(TimeUtil.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
             submitResult.add(data);
 
-            if (level >= 0 && level < 15) {
-                pv.setPercent(level / 50);
+            if (shishiValue<0.25) {
+                pv.setPercent((float) (shishiValue / 2.0));
                 tv_tishi.setText("������������������");
                 tv_desc.setText("���������������������������\n���������������������������������������������");
                 showStatus(true);
-            } else if (level >= 15 && level < 26) {
-                pv.setPercent(level / 50);
+                stop();
+            } else if (shishiValue >= 0.25 && shishiValue < 0.8) {
+                pv.setPercent((float) (shishiValue / 2.0));
                 tv_tishi.setText("������������������");
                 tv_desc.setText("���������������������������\n���������������������������������������������������");
                 showStatus(true);
-            } else if (level >= 26 && level < 65) {
+                play();
+            } else if (shishiValue >=0.8 && shishiValue < 2) {
                 showStatus(false);
                 tv_tishi.setText("������������������");
                 tv_desc.setText("���������������������������\n���������������������������������������������������");
-                if (level <= 45) {
-                    pv.setPercent(level / 50);
-                } else {
+                if(shishiValue>1.8){
                     pv.setPercent(0.9f);
+                }else{
+                    pv.setPercent((float) (shishiValue / 2.0));
                 }
-            } else if (level >= 65) {
+                play();
+            } else if (shishiValue >= 2) {
                 showStatus(false);
                 tv_tishi.setText("������������������");
                 tv_desc.setText("���������������������������\n���������������������������������������������������");
                 pv.setPercent(1.0f);
+                play();
             }
             realResult.clear();
         }
@@ -529,4 +576,21 @@
             return s;
         }
     }
+
+    public void play(){
+        if(mp!=null){
+            stop();
+        }
+        int index = MainApp.theApp.sharedPreferencesUtil.getLoginInfo().getVideo();
+        mp = MediaPlayer.create(getActivity(), voiceList.get(index).getRes());
+        mp.start();
+    }
+    public void stop(){
+        if(mp!=null&&mp.isPlaying()){
+            mp.stop();
+            mp.release();
+            mp = null;
+        }
+    }
+
 }

--
Gitblit v1.8.0