Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is what I am currently doing for orientation:
- private void startPreview() throws CameraHardwareException
- {
- if(mPausing || isFinishing())
- return;
- ensureCamera();
- if(mStatus!=PREVIEW_STOPPED)
- stopPreview();
- setPreviewDisplay(surfaceHolder);
- mUpdateSet=INIT_PARAMS;
- setCameraParameters(INIT_PARAMS);
- setDisplayOrientation();
- try
- {
- Log.d(TAG, "Trying to start the preview");
- mCamera.startPreview();
- }
- catch(Throwable ex)
- {
- closeCamera();
- throw new RuntimeException("Could not start camera preview");
- }
- mPreviewing=true;
- }
- private void setDisplayOrientation()
- {
- mDisplayRotation=getDisplayRotation(this);
- mDisplayOrientation=getDisplayOrientation(mDisplayRotation, CameraInfo.CAMERA_FACING_BACK);
- if(mCamera!=null)
- {
- mCamera.setDisplayOrientation(mDisplayOrientation);
- if(mParameters!=null)
- {
- mParameters.setRotation(mDisplayOrientation);
- }
- else
- {
- Camera.Parameters params=mCamera.getParameters();
- params.setRotation(mDisplayOrientation);
- mCamera.setParameters(params);
- }
- }
- }
- //I guess you have seen these before:
- private int getDisplayOrientation(int degrees, int cameraId) {
- // See android.hardware.Camera.setDisplayOrientation for
- // documentation.
- Camera.CameraInfo info = new Camera.CameraInfo();
- Camera.getCameraInfo(cameraId, info);
- int result;
- if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
- result = (info.orientation + degrees) % 360;
- result = (360 - result) % 360; // compensate the mirror
- } else { // back-facing
- result = (info.orientation - degrees + 360) % 360;
- }
- //add it here??? mCamera.setDisplayOrientation(result);
- return result;
- }
- private int getDisplayRotation(Activity activity) {
- int rotation = activity.getWindowManager().getDefaultDisplay()
- .getRotation();
- switch (rotation) {
- case Surface.ROTATION_0: return 0;
- case Surface.ROTATION_90: return 90;
- case Surface.ROTATION_180: return 180;
- case Surface.ROTATION_270: return 270;
- }
- return 0;
- }
- class MainHandler extends Handler
- {
- @Override
- public void handleMessage(Message msg)
- {
- switch(msg.what)
- {
- case FIRST_TIME_INIT:
- initializeFirstTime();
- break;
- case CLEAR_SCREEN_DELAY:
- getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
- break;
- case UPDATE_PARAMS_WHEN_IDLE:
- setCameraParametersWhenIdle(0);
- break;
- case CHECK_DISPLAY_ROTATION:
- if(getDisplayRotation(CameraActivity.this)!=mDisplayRotation)
- setDisplayOrientation();
- if(SystemClock.uptimeMillis()-mResumeTime<5000)
- handler.sendEmptyMessageDelayed(CHECK_DISPLAY_ROTATION,100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement