Ejemplo n.º 1
0
        public void handleMessage(Message msg) {
          switch (msg.what) {
            case CONNECT_DEVICE:
              tv.setText("連線完成,請開始吹氣");
              pd.dismiss();
              sound.play(StartBlow, 1, 1, 0, 0, 1);
              if (location != null) {
                lat = location.getLatitude();
                lng = location.getLongitude();
                Geocoder gc = new Geocoder(MainActivity.this, Locale.TRADITIONAL_CHINESE);
                List<Address> lstAddress;
                try {
                  lstAddress = gc.getFromLocation(lat, lng, 1);
                  // returnAddress=lstAddress.get(0).getAdminArea()+lstAddress.get(0).getLocality()+lstAddress.get(0).getThoroughfare()+lstAddress.get(0).getFeatureName();
                  returnAddress = lstAddress.get(0).getAddressLine(0);
                  System.out.println(lat + "/" + lng + "/" + returnAddress);
                } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
              break;
            case BAS_P:
              tv.setText("系統偵測到正在吹氣");
              sound.play(Blowing, 1, 1, 0, 0, 1);
              break;
            case BAS_F:
              tv.setText("吹氣失敗");
              sound.play(BlowFail, 1, 1, 0, 0, 1);
              break;
            case BAS_A:
              tv.setText("吹氣完成");
              sound.play(BlowDone, 1, 1, 0, 0, 1);
              mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
              break;
            case BAS_T:
              sound.play(ShowBacValue, 1, 1, 0, 0, 1);
              final String str = BAC[0];
              tv.setText("顯示酒測值:" + str.toString() + "/L");

              Bitmap p = BitmapFactory.decodeFile(StorePicturePath);
              File myCaptureFile = new File(StorePicturePath);
              if (myCaptureFile.exists()) myCaptureFile.delete();

              Bitmap cp = createBitmap(p, s.toString(), str.toString());
              Data = new String[2];
              Data = getDateAndBacValue(s.toString(), str.toString());

              BufferedOutputStream bos;
              try {
                bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
                cp.compress(Bitmap.CompressFormat.JPEG, 80, bos);
                bos.flush();
                bos.close();
              } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }

              mPreview.setVisibility(View.GONE);
              if (haveInternet()) Poimg(cp);
              iv.setVisibility(View.VISIBLE);
              iv.setImageBitmap(cp);
              float Bacvalue = Float.valueOf(Data[1].substring(0, 5));
              if ((Bacvalue > 0.000)) {
                if (SendSmsNum != null) {
                  String Msg = "提醒您,受測者:" + UserName + "酒測時間:" + Data[0] + "酒測值" + Data[1] + "/L";
                  String Smsurl = SendSmsByInternet(Msg);
                  SendSmsThred(Smsurl);
                }
                sound.play(Alarm, 1, 1, 0, 0, 1);
              }
              /*酒測完成倒數十秒跳出*/
              Thread t =
                  new Thread(
                      new Runnable() {

                        @Override
                        public void run() {
                          // TODO Auto-generated method stub
                          try {

                            Thread.sleep(10000);
                            finish();
                          } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                          }
                        }
                      });
              t.start();
              break;
            case BAS_Z:
              sound.play(WaitBacZero, 1, 1, 0, 0, 1);
              tv.setText("酒測器正在歸零");
              break;
            case BAS_B:
              sound.play(StartBlow, 1, 1, 0, 0, 1);
              tv.setText("酒測器已歸零,請開始吹氣");
              break;
            case CONNECT_DEVICE_TIMEOUT:
              sound.play(FailConnect, 1, 1, 0, 0, 1);
              CheckBluetoothConenct = true;
              tv.setText("與酒測器連結失敗,請確認酒測器是否已備妥");
              pd.dismiss();
              break;
            case CONNECT_DEVICE_SUCCESS:
              CheckBluetoothConenct = true;
              break;
            case PDBAR:
              pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
              pd.setTitle("與酒測器連線中");
              pd.setMessage("請稍候");
              pd.setCancelable(false);
              pd.show();
              break;
          }
        };