Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use an <a href="http://developer.android.com/reference/android/view/OrientationEventListener.html" rel="nofollow noreferrer"><code>OrientationEventListener</code></a></p> <p>In your SurfaceHolder.Callback</p> <pre><code> orientationListener = createOrientationListener(); private OrientationEventListener createOrientationListener() { return new OrientationEventListener(getActivity()) { public void onOrientationChanged(int orientation) { try { if (orientation != OrientationEventListener.ORIENTATION_UNKNOWN) { setCameraDisplayOrientation(getActivity().getWindowManager().getDefaultDisplay().getRotation()); } } catch (Exception e) { Log.w(TAG, "Error while onOrientationChanged", e); } } }; } @Override public void surfaceCreated(SurfaceHolder holder) { orientationListener.enable(); } @Override public void surfaceDestroyed(SurfaceHolder holder) { orientationListener.disable(); } </code></pre> <p>Your change rotation method has to manage unneeded double rotations</p> <pre><code>public void setCameraDisplayOrientation(int displayRotation) { int degrees = 0; switch (displayRotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (cameraInfo.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (cameraInfo.orientation - degrees + 360) % 360; } if(result != currentSetRotation) { currentSetRotation = result; camera.setDisplayOrientation(result); Log.d(TAG,"For displayRotation "+displayRotation+" we set a camera rotation of "+result); } } </code></pre> <p>See also: <a href="https://stackoverflow.com/questions/19532599/rotating-phone-quickly-180-degrees-camera-preview-turns-upside-down">Rotating phone quickly 180 degrees, camera preview turns upside down</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload