Example usage for android.view Surface ROTATION_270

List of usage examples for android.view Surface ROTATION_270

Introduction

In this page you can find the example usage for android.view Surface ROTATION_270.

Prototype

int ROTATION_270

To view the source code for android.view Surface ROTATION_270.

Click Source Link

Document

Rotation constant: 270 degree rotation.

Usage

From source file:Main.java

public static int setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;//from  w w  w  .ja  va 2  s  .  co  m
        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 (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;
    }
    Log.d(TAG, "camera display orientation: " + result);
    camera.setDisplayOrientation(result);

    return result;
}

From source file:Main.java

public static void sensorRotation2Matrix(float[] gravity, float[] geomagnetic, int rotation, float[] output) {
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180: /* Notice: not supported for ROTATION_180! */
        SensorManager.getRotationMatrix(output, null, gravity, geomagnetic);
        break;//  w w w.ja  va2 s.  com
    case Surface.ROTATION_90:
        SensorManager.getRotationMatrix(mTmp, null, gravity, geomagnetic);
        SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, output);
        break;
    case Surface.ROTATION_270:
        SensorManager.getRotationMatrix(mTmp, null, gravity, geomagnetic);
        SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, output);
        break;
    }
    Matrix.rotateM(output, 0, 90.0F, 1.0F, 0.0F, 0.0F);
}

From source file:Main.java

/**
 * Determine the rotation to apply for the preview for a given camera
 * @param mirror whether to account for profile camera mirroring or not
 *//*from  ww w  .j a va2  s  .c om*/
public static int getRotationDegrees(Activity activity, int cameraId, boolean mirror) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;

    switch (rotation) {
    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;
    }

    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);

    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {

        degrees = (info.orientation + degrees) % 360;
        // compensate for mirrored image, useful for previews on front facing cameras
        if (mirror) {
            degrees = (360 - degrees) % 360;
        }
    } else {
        degrees = (info.orientation - degrees + 360) % 360;
    }

    return degrees;
}

From source file:Main.java

public static void setCameraDisplayOrientation(Context mContext, int cameraId, Camera camera) {
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int rotation = ((Activity) mContext).getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;/*from  w  w  w.j  av a2s.  c om*/
        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 (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;
    }
    camera.setDisplayOrientation(result);
}

From source file:Main.java

public static void setCameraDisplayOrientation(Activity activity, int cameraId,
        android.hardware.Camera camera) {
    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;//  w  w  w . j a  v a  2s  .co m
        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 (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;
    }
    camera.setDisplayOrientation(result);
}

From source file:Main.java

public static void sensorRotationVector2Matrix(SensorEvent event, int rotation, float[] output) {
    float[] values = event.values;
    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180: /* Notice: not supported for ROTATION_180! */
        SensorManager.getRotationMatrixFromVector(output, values);
        break;/*from  w  w  w .  j  av  a 2  s  .  co  m*/
    case Surface.ROTATION_90:
        SensorManager.getRotationMatrixFromVector(mTmp, values);
        SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, output);
        break;
    case Surface.ROTATION_270:
        SensorManager.getRotationMatrixFromVector(mTmp, values);
        SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, output);
        break;
    }
    Matrix.rotateM(output, 0, 90.0F, 1.0F, 0.0F, 0.0F);
}

From source file:Main.java

public static int getCameraDisplayOrientation(@NonNull Activity activity, @NonNull CameraInfo info) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    DisplayMetrics dm = new DisplayMetrics();

    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;//from   w  w  w  . ja va2  s  . com
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        return (360 - ((info.orientation + degrees) % 360)) % 360;
    } else {
        return (info.orientation - degrees + 360) % 360;
    }
}

From source file:Main.java

public static int convertRotationToTiOrientationMode(int rotation) {
    switch (rotation) {
    case Surface.ROTATION_0:
        return ORIENTATION_PORTRAIT;

    case Surface.ROTATION_90:
        return ORIENTATION_LANDSCAPE;

    case Surface.ROTATION_180:
        return ORIENTATION_PORTRAIT_REVERSE;

    case Surface.ROTATION_270:
        return ORIENTATION_LANDSCAPE_REVERSE;

    default://from ww  w .java 2 s  . c  o  m
        return ORIENTATION_UNKNOWN;
    }
}

From source file:Main.java

private static int getCameraDisplayOrientation_1(Activity activity,
        @SuppressWarnings("deprecation") Camera.CameraInfo cameraInfo) {
    // android.hardware.Camera.CameraInfo info =
    // new android.hardware.Camera.CameraInfo();
    // android.hardware.Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;//  ww  w .j  a v a 2  s . com
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    default: {
        Log.e(TAG, "un deal with handler task");
    }
        break;
    }

    int result;
    //noinspection deprecation
    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;
    }

    return result;
}

From source file:Main.java

/**
 * gets the correct rotation of the camera for the surface rotation
 * requested, adjust for front/back camera
 * /*www  . j  ava  2 s. co m*/
 * @param surfaceRotation
 * @param camera
 * @param cameraID
 * @return
 */
@SuppressLint("NewApi")
public static int getCameraRotationForSurfaceRotation(int surfaceRotation, Camera camera, int cameraID) {
    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraID, info);

    int degrees = 0;

    switch (surfaceRotation) {
    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 (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;
    }
    return result;
}