@Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.start_speech_button:
       startListening();
       break;
     case R.id.stop_speech_button:
       mSpeechRecognizer.stopListening();
       break;
     case R.id.start_camera_button:
       if (Build.VERSION.SDK_INT >= CAMERA_2_API_LIMIT) {
         lawg.d("Has camera permission? " + hasPermission(Manifest.permission.CAMERA));
         if (hasPermission(Manifest.permission.CAMERA)) {
           startCamera2(mTextureView.getWidth(), mTextureView.getHeight());
         } else {
           ActivityCompat.requestPermissions(
               CameraActivity.this,
               new String[] {Manifest.permission.CAMERA},
               CAMERA_PERMISSIONS_REQUEST);
         }
       }
       break;
     case R.id.stop_camera_button:
       stopCamera2();
       break;
     case R.id.capture_camera_button:
       captureStillPicture();
       break;
   }
 }
  @Override
  public void onResume() {
    super.onResume();
    startBackgroundThread();

    // When the screen is turned off and turned back on, the SurfaceTexture is already
    // available, and "onSurfaceTextureAvailable" will not be called. In that case, we can open
    // a camera and start preview from here (otherwise, we wait until the surface is ready in
    // the SurfaceTextureListener).
    if (mTextureView.isAvailable()) {
      openCamera(mCameraId, mTextureView.getWidth(), mTextureView.getHeight());
    } else {
      mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
    }
  }
  @Override
  protected void onResume() {
    super.onResume();
    startBackgroundThread();
    startSpeechRecognizer();

    // When the screen is turned off and turned back on, the SurfaceTexture is already
    // available, and "onSurfaceTextureAvailable" will not be called. In that case, we can open
    // a camera and start preview from here (otherwise, we wait until the surface is ready in
    // the SurfaceTextureListener).
    if (mTextureView.isAvailable()) {
      lawg.d("Has camera permission? " + hasPermission(Manifest.permission.CAMERA));
      if (hasPermission(Manifest.permission.CAMERA)) {
        startCamera2(mTextureView.getWidth(), mTextureView.getHeight());
      } else {
        ActivityCompat.requestPermissions(
            CameraActivity.this,
            new String[] {Manifest.permission.CAMERA},
            CAMERA_PERMISSIONS_REQUEST);
      }
    } else {
      mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
    }
  }