| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | */ |
| | | |
| | | 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; |
| | |
| | | |
| | | }); |
| | | /** |
| | | * 一连上先发数据包 |
| | | */ |
| | | heart(); |
| | | /** |
| | | * 发送时间校准 |
| | | */ |
| | | handler.postDelayed(new Runnable() { |
| | |
| | | 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("未连接"); |
| | |
| | | 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 |
| | |
| | | timer.cancel(); |
| | | timer = null; |
| | | } |
| | | stop(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | /** |
| | | * 发送心跳包,每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; |
| | |
| | | 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(); |
| | | } |
| | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | } |