Пример #1
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ECGApplication.getInstance().setScreenW2H(this); // 获取屏幕尺寸

    imgView_msg = (Button) findViewById(R.id.ImgView_msg);
    btRecord = (ImageButton) findViewById(R.id.Btn_record);
    btAdvice = (ImageButton) findViewById(R.id.Btn_advice);
    btConfig = (ImageButton) findViewById(R.id.Btn_config);
    btStart = (ImageButton) findViewById(R.id.Btn_start);
    btEcg = (Button) findViewById(R.id.ImgBtn_ecg);
    btAcc = (Button) findViewById(R.id.ImgBtn_acc);
    btHr = (Button) findViewById(R.id.ImgBtn_hr);
    btTips = (ImageButton) findViewById(R.id.ImgBtn_tips);
    etTips = (EditText) findViewById(R.id.Edit_tips);
    layDraw = (LinearLayout) findViewById(R.id.Layout_draw);
    ivMonitor = (ImageView) findViewById(R.id.ImgView_monitoring);
    ivBT = (ImageView) findViewById(R.id.ImgView_devconn);
    ivBatt = (ImageView) findViewById(R.id.ImgView_batthigh);

    curveChar[0] = (CurveChart) findViewById(R.id.DRAW_ECG); // 创建绘图对象
    //	curveChar[0].setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
    curveChar[1] = (CurveChart) findViewById(R.id.DRAW_ACC_X); // 创建绘图对象
    curveChar[2] = (CurveChart) findViewById(R.id.DRAW_ACC_Y);
    curveChar[3] = (CurveChart) findViewById(R.id.DRAW_ACC_Z);
    curveChar[4] = (CurveChart) findViewById(R.id.DRAW_HR); // 创建绘图对象
    thisActivity = this;
    gWriteRecord = new RecordDB(ECG_Android.this);

    // 单击提示按钮
    btTips.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            try {
              String[] info = new String[listInfo.size()];
              for (int i = 0; i < listInfo.size(); i++) {
                info[i] = i + 1 + "、" + listInfo.get(i);
              }

              new AlertDialog.Builder(ECG_Android.this)
                  .setTitle("提示")
                  .setPositiveButton(
                      "清空",
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                          // TODO Auto-generated method stub
                          listInfo.clear();
                        }
                      })
                  .setItems(
                      info,
                      new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                          // TODO Auto-generated method stub

                        }
                      })
                  .setNegativeButton(
                      "关闭",
                      new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                          // TODO Auto-generated method stub

                        }
                      })
                  .show();

            } catch (Exception e) {

            }
          }
        });

    // 当单击短信图标
    imgView_msg.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            // Auto-generated method stub
            Intent inAdvice = new Intent(ECG_Android.this, Advice.class);
            startActivity(inAdvice);
          }
        });

    // 参数配置
    btConfig.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Intent inConfig = new Intent(ECG_Android.this, Config.class);
            startActivity(inConfig);
          }
        });

    // 健康建议
    btAdvice.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Intent inAdvice = new Intent(ECG_Android.this, Advice.class);
            startActivity(inAdvice);
          }
        });

    // 查看记录
    btRecord.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Intent inRecord = new Intent(ECG_Android.this, Record.class);
            startActivity(inRecord);
          }
        });

    // ECG
    btEcg.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            drawstatus = DrawStatus.ECG;
            btEcg.setBackgroundDrawable(getResources().getDrawable(R.drawable.ecg_down));
            btAcc.setBackgroundDrawable(getResources().getDrawable(R.drawable.acc));
            btHr.setBackgroundDrawable(getResources().getDrawable(R.drawable.hr));

            if (isStart) {
              ecgShapeLine[0].setSuspendDraw(false);
              ecgShapeLine[1].setSuspendDraw(true);
              ecgShapeLine[2].setSuspendDraw(true);
              ecgShapeLine[3].setSuspendDraw(true);
              ecgShapeLine[4].setSuspendDraw(true);

              curveChar[1].setVisibility(View.GONE);
              curveChar[2].setVisibility(View.GONE);
              curveChar[3].setVisibility(View.GONE);
              curveChar[4].setVisibility(View.GONE);
              curveChar[0].setVisibility(View.VISIBLE);
            }
          }
        });
    // Acc
    btAcc.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            drawstatus = DrawStatus.ACC;
            btEcg.setBackgroundDrawable(getResources().getDrawable(R.drawable.ecg));
            btAcc.setBackgroundDrawable(getResources().getDrawable(R.drawable.acc_down));
            btHr.setBackgroundDrawable(getResources().getDrawable(R.drawable.hr));

            if (isStart) {
              ecgShapeLine[1].setSuspendDraw(false);
              ecgShapeLine[2].setSuspendDraw(false);
              ecgShapeLine[3].setSuspendDraw(false);
              ecgShapeLine[4].setSuspendDraw(true);
              ecgShapeLine[0].setSuspendDraw(true);

              curveChar[4].setVisibility(View.GONE);
              curveChar[0].setVisibility(View.GONE);
              curveChar[1].setVisibility(View.VISIBLE);
              curveChar[2].setVisibility(View.VISIBLE);
              curveChar[3].setVisibility(View.VISIBLE);

              // ecgShapeLine[0] = new EcgShapeLine(curveChar[1], DRAW_ACC);//开始绘制曲线图
            }
          }
        });
    // 心率
    btHr.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            drawstatus = DrawStatus.HR;
            btEcg.setBackgroundDrawable(getResources().getDrawable(R.drawable.ecg));
            btAcc.setBackgroundDrawable(getResources().getDrawable(R.drawable.acc));
            btHr.setBackgroundDrawable(getResources().getDrawable(R.drawable.hr_down));
            if (isStart) {
              ecgShapeLine[4].setSuspendDraw(false);
              ecgShapeLine[0].setSuspendDraw(true);
              ecgShapeLine[1].setSuspendDraw(true);
              ecgShapeLine[2].setSuspendDraw(true);
              ecgShapeLine[3].setSuspendDraw(true);

              curveChar[1].setVisibility(View.GONE);
              curveChar[0].setVisibility(View.GONE);
              curveChar[2].setVisibility(View.GONE);
              curveChar[3].setVisibility(View.GONE);
              curveChar[4].setVisibility(View.VISIBLE);
            }
          }
        });

    mainHandler = new MainEventHandler(); // 初始化主线程消息队列

    new Thread(innitThread).start(); // 验证网络,没有配置可用的网络则提示用户进行配置

    // 启动蓝牙控制线程
    BluetoothFactory.startBthThread(mainHandler);

    // 启动业务数据传输控制线程
    BluetoothControl.startControlThread();

    // BluetoothFactory.getInstance().connectBlueTooth(mainHandler);//通知蓝牙模块进行连接

    btStart.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            if (isConnected) {
              // if(true){
              bluetoothControl.startcomm(); // 开始采集
              ivMonitor.setBackgroundDrawable(getResources().getDrawable(R.drawable.monitoring));
              btStart.setVisibility(View.GONE); // 隐藏开始按钮
              isStart = true;
              curveChar[1].setVisibility(View.GONE);
              curveChar[2].setVisibility(View.GONE);
              curveChar[0].setVisibility(View.GONE);
              curveChar[3].setVisibility(View.GONE);
              curveChar[4].setVisibility(View.GONE);

              ecgShapeLine[0] = new EcgShapeLine(curveChar[0], DRAW_ECG); // 开始绘制曲线图
              ecgShapeLine[1] = new EcgShapeLine(curveChar[1], DRAW_ACC_X); // 开始绘制曲线图
              ecgShapeLine[2] = new EcgShapeLine(curveChar[2], DRAW_ACC_Y);
              ecgShapeLine[3] = new EcgShapeLine(curveChar[3], DRAW_ACC_Z);
              ecgShapeLine[4] = new EcgShapeLine(curveChar[4], DRAW_HR); // 开始绘制曲线图

              ecgShapeLine[0].setSuspendDraw(true);
              ecgShapeLine[1].setSuspendDraw(true);
              ecgShapeLine[2].setSuspendDraw(true);
              ecgShapeLine[3].setSuspendDraw(true);
              ecgShapeLine[4].setSuspendDraw(true);

              if (drawstatus.equals(DrawStatus.ECG)) {
                curveChar[0].setVisibility(View.VISIBLE);
                ecgShapeLine[0].setSuspendDraw(false);
              } else if (drawstatus.equals(DrawStatus.ACC)) {
                curveChar[1].setVisibility(View.VISIBLE);
                ecgShapeLine[1].setSuspendDraw(false);
                curveChar[2].setVisibility(View.VISIBLE);
                ecgShapeLine[2].setSuspendDraw(false);
                curveChar[3].setVisibility(View.VISIBLE);
                ecgShapeLine[3].setSuspendDraw(false);
              } else {
                curveChar[4].setVisibility(View.VISIBLE);
                ecgShapeLine[4].setSuspendDraw(false);
              }

              logger.debug("btStart");
              // BluetoothFactory.getInstance().beginGetEcgData();//通知蓝牙开始采集数据
              EcgBusiness.getInstance().startTask(mainHandler); // 通知业务模块进行业务处理
              // etTips.setText("开始采集数据...");
              outputInfo("开始采集数据...");
            } else {
              // etTips.setText("蓝牙未连接,请检查设备!");
              outputInfo("蓝牙未连接,请检查设备!");
            }
          }
        });
  }
Пример #2
0
    public void handleMessage(Message msg) {
      logger.debug("Analysis2shapeline" + msg.what);
      // 可以根据msg.what执行不同的处理,这里没有这么做
      switch (msg.what) {
        case HandlerWhat.Bluetooth2Main: // 通知蓝牙连接情况
          if ((Boolean) msg.obj) {
            // etTips.setText("已连接上蓝牙");
            outputInfo("已连接上蓝牙");
            isConnected = true;
            ivBT.setBackgroundDrawable(getResources().getDrawable(R.drawable.devconn));
            // 判断是否点击了开始按钮,如果已经点击了,则自动开始采集数据。
            try {
              Thread.sleep(500);
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            if (isStart) {

              bluetoothControl.startcomm(); // 开始采集
              ivMonitor.setBackgroundDrawable(getResources().getDrawable(R.drawable.monitoring));
              curveChar[1].setVisibility(View.GONE);
              curveChar[2].setVisibility(View.GONE);
              curveChar[0].setVisibility(View.GONE);
              curveChar[3].setVisibility(View.GONE);
              curveChar[4].setVisibility(View.GONE);

              ecgShapeLine[0] = new EcgShapeLine(curveChar[0], DRAW_ECG); // 开始绘制曲线图
              ecgShapeLine[1] = new EcgShapeLine(curveChar[1], DRAW_ACC_X); // 开始绘制曲线图
              ecgShapeLine[2] = new EcgShapeLine(curveChar[2], DRAW_ACC_Y);
              ecgShapeLine[3] = new EcgShapeLine(curveChar[3], DRAW_ACC_Z);
              ecgShapeLine[4] = new EcgShapeLine(curveChar[4], DRAW_HR); // 开始绘制曲线图

              ecgShapeLine[0].setSuspendDraw(true);
              ecgShapeLine[1].setSuspendDraw(true);
              ecgShapeLine[2].setSuspendDraw(true);
              ecgShapeLine[3].setSuspendDraw(true);
              ecgShapeLine[4].setSuspendDraw(true);

              if (drawstatus.equals(DrawStatus.ECG)) {
                curveChar[0].setVisibility(View.VISIBLE);
                ecgShapeLine[0].setSuspendDraw(false);
              } else if (drawstatus.equals(DrawStatus.ACC)) {
                curveChar[1].setVisibility(View.VISIBLE);
                ecgShapeLine[1].setSuspendDraw(false);
                curveChar[2].setVisibility(View.VISIBLE);
                ecgShapeLine[2].setSuspendDraw(false);
                curveChar[3].setVisibility(View.VISIBLE);
                ecgShapeLine[3].setSuspendDraw(false);
              } else {
                curveChar[4].setVisibility(View.VISIBLE);
                ecgShapeLine[4].setSuspendDraw(false);
              }
              EcgBusiness.getInstance().startTask(mainHandler); // 通知业务模块进行业务处理
            }

            // TODO:通知业务
          } else {
            // etTips.setText("蓝牙断开");
            MediaPlayer play = MediaPlayer.create(ECGApplication.getInstance(), R.raw.disconnected);
            play.start();
            outputInfo("蓝牙断开...");
            ivBT.setBackgroundDrawable(getResources().getDrawable(R.drawable.devdisconn));
            ivMonitor.setBackgroundDrawable(getResources().getDrawable(R.drawable.unmonitoring));
            ivBatt.setBackgroundDrawable(getResources().getDrawable(R.drawable.battunknown));
            isConnected = false;
            if (isStart) {

              ecgShapeLine[0].setSuspendDraw(true);
              ecgShapeLine[1].setSuspendDraw(true);
              ecgShapeLine[2].setSuspendDraw(true);
              ecgShapeLine[3].setSuspendDraw(true);
              ecgShapeLine[4].setSuspendDraw(true);
            }
            // TODO:通知业务
          }

          break;
        case HandlerWhat.Tread2Notify: // 通知消息提示框,如上传失败,保存数据失败
          // Toast.makeText(ECG_Android.this,(String)msg.obj,Toast.LENGTH_SHORT).show();
          // etTips.setText((String)msg.obj);
          outputInfo((String) msg.obj);
          // logger.info("Tread2Notify"+String.valueOf(msg.obj));
          break;
        case HandlerWhat.Analysis2shapeline: // 分析线程通知绘图
          ecgShapeLine[0].pushData(msg.obj); // 根据分析返回的数据进行绘图
          ecgShapeLine[1].pushData(msg.obj); // 根据分析返回的数据进行绘图
          ecgShapeLine[2].pushData(msg.obj); // 根据分析返回的数据进行绘图			
          ecgShapeLine[3].pushData(msg.obj); // 根据分析返回的数据进行绘图
          ecgShapeLine[4].pushData(msg.obj); // 根据分析返回的数据进行绘图
          logger.debug("Analysis2shapeline" + String.valueOf(msg.obj));
          break;
        case HandlerWhat.FileOperate2MainEmpty:
          ivBatt.setBackgroundDrawable(getResources().getDrawable(R.drawable.battempty));
          MediaPlayer play = MediaPlayer.create(ECGApplication.getInstance(), R.raw.lowbatt);
          play.start();
          outputInfo("电量低,请更换电池");
          break;
        case HandlerWhat.FileOperate2MainLow:
          ivBatt.setBackgroundDrawable(getResources().getDrawable(R.drawable.battlow));

          break;
        case HandlerWhat.FileOperate2MainNomal:
          ivBatt.setBackgroundDrawable(getResources().getDrawable(R.drawable.battnormal));
          break;
        case HandlerWhat.FileOperate2MainHight:
          ivBatt.setBackgroundDrawable(getResources().getDrawable(R.drawable.batthigh));
          break;

        default:
          break;
      }
    }