예제 #1
0
 // accelerometer
 @Override
 public void onSensorChanged(SensorEvent event) {
   float noisy = ApplicationConstant.ACCELEROMETER_NOISY;
   float x = event.values[0];
   float y = event.values[1];
   float z = event.values[2];
   if (!isInitialized) {
     lastX = x;
     lastY = y;
     lastZ = z;
     isInitialized = true;
   } else {
     float deltaX = Math.abs(lastX - x);
     float deltaY = Math.abs(lastY - y);
     float deltaZ = Math.abs(lastZ - z);
     if (deltaX < noisy) deltaX = (float) 0.0;
     if (deltaY < noisy) deltaY = (float) 0.0;
     if (deltaZ < noisy) deltaZ = (float) 0.0;
     lastX = x;
     lastY = y;
     lastZ = z;
     if (deltaX + deltaY + deltaX > 0 && !suspandTimer) {
       Log.d("acc", "sharp motion");
       if (SuspiciousMotionDetectionHelper.isSuspiciousMotion() && !alertAlreadyTrigged) {
         suspandTimer = true;
         alertAlreadyTrigged = true;
         Intent cameraIntent = new Intent(getBaseContext(), AlertCountDownActivity.class);
         startActivityForResult(
             cameraIntent, ActivityRequestCodeEnum.ALERT_ACTIVITY_REQUEST_CODE.getValue());
       }
     }
   }
 }
예제 #2
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   // Handle item selection. Menu items typically start another
   // activity, start a service, or broadcast another intent.
   switch (item.getItemId()) {
     case R.id.menu_stop:
       finish();
       return true;
     case R.id.menu_send_alert:
       Intent cameraIntent = new Intent(getBaseContext(), AlertCountDownActivity.class);
       startActivityForResult(
           cameraIntent, ActivityRequestCodeEnum.ALERT_ACTIVITY_REQUEST_CODE.getValue());
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }