private void setPreviewCallback() {
    if (mCamera == null) {
      android.util.Log.e("MOSYNC INTERNAL", "No Preview set");
      return;
    }

    try {
      // We have to use and static instance of the camera in the reflection here
      mSetPreviewCallbackWithBuffer =
          mCamera
              .getClass()
              .getMethod("setPreviewCallbackWithBuffer", Camera.PreviewCallback.class);

      Camera.Parameters parameters = getCurrentParameters();
      Camera.Size size = parameters.getPreviewSize();

      mCallbackBuffer = new byte[size.width * size.height * 4];

      mCamera.addCallbackBuffer(mCallbackBuffer);

      mIsUsingPreviewCallbackBuffer = true;

      mCamera.setPreviewCallbackWithBuffer(previewCallback);

    } catch (NoSuchMethodException nsme) {
      mIsUsingPreviewCallbackBuffer = false;

      mCamera.setPreviewCallback(previewCallback);
    }
  }
  /**
   * An equivalent to maCameraNumber syscall that queries the number of available cameras
   *
   * @return number of cameras on the device
   */
  public int numberOfCameras() {
    if (mNumCameras != 0) {
      // Do not do the costly operation of reflection again
      return mNumCameras;
    }
    try {
      if (mCamera == null) {
        tempCamera = Camera.open();
      } else {
        mCamera.release();
        tempCamera = Camera.open(mCurrentCameraIndex);
      }

      // We have to use and static instance of the camera in the reflection here
      mGetNumberofCameras = tempCamera.getClass().getMethod("getNumberOfCameras");
      tempCamera.release();
      if (mCamera != null) {
        mCamera = Camera.open(mCurrentCameraIndex);
      }
      return Camera.getNumberOfCameras();

    } catch (NoSuchMethodException nsme) {
      tempCamera.release();
      SYSLOG("ANDROID Version is less than 2.3!!");
      // before 2.3 only one camera is supported
      return 1;
    } catch (RuntimeException e) {
      SYSLOG("Failed to set camera Parameters");
      return MAAPI_consts.MA_CAMERA_RES_FAILED;
    }
  }
 public void onSurfaceTextureAvailable(
     SurfaceTexture paramSurfaceTexture, int paramInt1, int paramInt2) {
   if (VideoCaptureFragment.h(a) == null) {
     VideoCaptureFragment.a(a, Camera.open());
     Object localObject1 = VideoCaptureFragment.h(a).getParameters();
     Object localObject2 = VideoCaptureFragment.i(a);
     Camera localCamera = VideoCaptureFragment.h(a);
     localCamera.getClass();
     localObject2 = new Camera.Size(localCamera, videoFrameWidth, videoFrameHeight);
     if (((Camera.Parameters) localObject1).getSupportedPreviewSizes().contains(localObject2)) {
       ((Camera.Parameters) localObject1).setPreviewSize(width, height);
       VideoCaptureFragment.h(a).setParameters((Camera.Parameters) localObject1);
     }
     localObject1 = ((Camera.Parameters) localObject1).getPreviewSize();
     VideoCaptureFragment.a(a, width, height);
     VideoCaptureFragment.h(a).setDisplayOrientation(VideoCaptureFragment.j(a));
     try {
       VideoCaptureFragment.h(a).setPreviewTexture(paramSurfaceTexture);
       VideoCaptureFragment.h(a).startPreview();
       paramSurfaceTexture = VideoCaptureFragment.h(a).getParameters().getSupportedFocusModes();
       if (CameraWrangler.a(VideoCaptureFragment.h(a))) {
         VideoCaptureFragment.h(a).autoFocus(null);
         return;
       }
       if (paramSurfaceTexture.contains("continuous-video")) {
         paramSurfaceTexture = VideoCaptureFragment.h(a).getParameters();
         paramSurfaceTexture.setFocusMode("continuous-video");
         VideoCaptureFragment.h(a).setParameters(paramSurfaceTexture);
         return;
       }
     } catch (IOException paramSurfaceTexture) {
       YelpLog.error(paramSurfaceTexture);
     }
   }
 }
 /**
  * compatible 1.6
  *
  * @param camera
  * @param angle
  */
 protected void setDisplayOrientation(Camera camera, int angle) {
   Method downPolymorphic;
   try {
     downPolymorphic =
         camera.getClass().getMethod("setDisplayOrientation", new Class[] {int.class});
     if (downPolymorphic != null) downPolymorphic.invoke(camera, new Object[] {angle});
   } catch (Exception e1) {
   }
 }
 protected void setDisplayOrientation(Camera paramCamera, int paramInt) {
   try {
     Class localClass = paramCamera.getClass();
     Class[] arrayOfClass = new Class[1];
     arrayOfClass[0] = Integer.TYPE;
     Method localMethod = localClass.getMethod("setDisplayOrientation", arrayOfClass);
     if (localMethod != null) {
       Object[] arrayOfObject = new Object[1];
       arrayOfObject[0] = Integer.valueOf(paramInt);
       localMethod.invoke(paramCamera, arrayOfObject);
     }
     return;
   } catch (Exception localException) {
   }
 }
Esempio n. 6
0
  /** sets the Orientation of the camera Preview o be the same as MoSyncApp */
  private void setCameraDisplayOrientation() {
    // Use reflection to correct the preview on 2.2 and higher versions
    try {
      mCameraDisplayOrientation =
          mCamera.getClass().getMethod("setDisplayOrientation", Integer.TYPE);

      // Set the orientation of the picture on old Android phones
      Camera.Parameters parameters = mCamera.getParameters();

      if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        parameters.set("orientation", "portrait");
        // default camera orientation on android is landscape
        // So we need to rotate the preview
        parameters.setRotation(90);
        mCamera.setDisplayOrientation(90);
      } else if (getResources().getConfiguration().orientation
          == Configuration.ORIENTATION_LANDSCAPE) {
        parameters.set("orientation", "landscape");
        parameters.setRotation(0);
        mCamera.setDisplayOrientation(0);
      }
      mCamera.setParameters(parameters);
    } catch (NoSuchMethodException nsme) {
      SYSLOG("ANDROID Version is less than 2.2!!");
      // Set the orientation of the picture on old Android phones
      Camera.Parameters parameters = mCamera.getParameters();

      // an Ugly hack to make HTC wildfire work
      if (Build.MANUFACTURER.equals("HTC")) {
        parameters.set("orientation", "landscape");
        parameters.setRotation(90);
      }
      // rest of the phones work fine with the standard settings
      else if (getResources().getConfiguration().orientation
          == Configuration.ORIENTATION_PORTRAIT) {
        parameters.set("orientation", "portrait");
        parameters.setRotation(90);
      } else if (getResources().getConfiguration().orientation
          == Configuration.ORIENTATION_LANDSCAPE) {
        parameters.set("orientation", "landscape");
        parameters.setRotation(0);
      }
      mCamera.setParameters(parameters);
    } catch (RuntimeException e) {
      SYSLOG("Failed to set camera Parameters");
    }
  }