Ejemplo n.º 1
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
      case R.id.switch_cam:
        // Release this camera -> mCameraCurrentlyLocked
        if (mCamera != null) {
          mCamera.stopPreview();
          mPreview.setCamera(null);
          mCamera.release();
          mCamera = null;
        }

        // Acquire the next camera and request Preview to reconfigure
        // parameters.
        mCamera = Camera.open((mCameraCurrentlyLocked + 1) % mNumberOfCameras);
        mCameraCurrentlyLocked = (mCameraCurrentlyLocked + 1) % mNumberOfCameras;
        mPreview.switchCamera(mCamera);

        // Start the preview
        mCamera.startPreview();
        return true;
      case android.R.id.home:
        Intent intent = new Intent(this.getActivity(), MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);

      default:
        return super.onOptionsItemSelected(item);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void onResume() {
    super.onResume();

    // Open the default i.e. the first rear facing camera.
    mCamera = Camera.open(mDefaultCameraId);
    mCameraCurrentlyLocked = mDefaultCameraId;
    mPreview.setCamera(mCamera);
  }
Ejemplo n.º 3
0
  @Override
  public void onPause() {
    super.onPause();

    // Because the Camera object is a shared resource, it's very
    // important to release it when the activity is paused.
    if (mCamera != null) {
      mPreview.setCamera(null);
      mCamera.release();
      mCamera = null;
    }
  }