Example usage for android.view OrientationEventListener canDetectOrientation

List of usage examples for android.view OrientationEventListener canDetectOrientation

Introduction

In this page you can find the example usage for android.view OrientationEventListener canDetectOrientation.

Prototype

public boolean canDetectOrientation() 

Source Link

Usage

From source file:com.aimfire.demo.CamcorderActivity.java

public void setCameraRotation() {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "setCameraRotation");
    OrientationEventListener listener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {
        @Override/* w  w w .  j  a va 2 s  .c  o m*/
        public void onOrientationChanged(int orientation) {
            if (orientation == ORIENTATION_UNKNOWN)
                return;

            Camera.CameraInfo info = new Camera.CameraInfo();
            Camera.getCameraInfo(mCameraId, info);
            orientation = (orientation + 45) / 90 * 90;
            int rotation = 0;
            if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                rotation = (info.orientation - orientation + 360) % 360;
            } else { // back-facing camera
                rotation = (info.orientation + orientation) % 360;
            }
            Camera.Parameters parms = mCamera.getParameters();
            parms.setRotation(rotation);
            mCamera.setParameters(parms);
        }
    };

    if (listener.canDetectOrientation()) {
        listener.enable();
    }
}