Example usage for android.view Surface ROTATION_180

List of usage examples for android.view Surface ROTATION_180

Introduction

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

Prototype

int ROTATION_180

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

Click Source Link

Document

Rotation constant: 180 degree rotation.

Usage

From source file:Main.java

private static float getDegreesForRotation(int value) {
    switch (value) {
    case Surface.ROTATION_90:
        return 360f - 90f;
    case Surface.ROTATION_180:
        return 360f - 180f;
    case Surface.ROTATION_270:
        return 360f - 270f;
    }//  w w w.ja  v a  2 s  .  c om
    return 0f;
}

From source file:Main.java

/**
 * @return the current display rotation in degrees
 *///from w  w  w . j  a v a2 s.  c o  m
public static float getDegreesForRotation(int value) {
    switch (value) {
    case Surface.ROTATION_90:
        return 90f;
    case Surface.ROTATION_180:
        return 180f;
    case Surface.ROTATION_270:
        return 270f;
    }
    return 0f;
}

From source file:Main.java

public static int getScreenRotation(Activity activity) {
    switch (activity.getWindowManager().getDefaultDisplay().getRotation()) {
    default:/*from  w  w w  . jav  a 2  s  .  com*/
    case Surface.ROTATION_0:
        return 0;
    case Surface.ROTATION_90:
        return 90;
    case Surface.ROTATION_180:
        return 180;
    case Surface.ROTATION_270:
        return 270;
    }
}

From source file:Main.java

public static int getOrientation(int rotation, boolean upsideDown) {
    if (upsideDown) {
        switch (rotation) {
        case Surface.ROTATION_0:
            return 270;
        case Surface.ROTATION_90:
            return 180;
        case Surface.ROTATION_180:
            return 90;
        case Surface.ROTATION_270:
            return 0;
        }/* w  w  w  .j  a v a  2s.  c  o m*/
    } else {
        switch (rotation) {
        case Surface.ROTATION_0:
            return 90;
        case Surface.ROTATION_90:
            return 0;
        case Surface.ROTATION_180:
            return 270;
        case Surface.ROTATION_270:
            return 180;
        }
    }

    return 0;
}

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. j  av a 2  s .c  om*/
    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

public static int getRotationAdjustment(int screenRotation) {
    int degrees = 0;
    switch (screenRotation) {
    case Surface.ROTATION_0:
        degrees = 0;/*from  ww w  . ja v  a2  s .  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 cameraOrientation = getCameraOrientation();
    return (cameraOrientation - degrees + 360) % 360;
}

From source file:Main.java

@SuppressLint("SwitchIntDef")
public static int getRotationOffset(@NonNull WindowManager windowManager) {
    switch (windowManager.getDefaultDisplay().getRotation()) {
    case Surface.ROTATION_90:
        return 90;
    case Surface.ROTATION_180:
        return 180;
    case Surface.ROTATION_270:
        return 270;
    default://from   w ww. j  ava2s.  c o  m
        return 0;
    }
}

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 .ja  v a2 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

/**
 * Returns the rotation of the screen from its "natural" orientation.
 * Notice: ANTICLOCKWISE// w  ww  . j a va  2 s.  c o m
 * @param rotation "getRotation()"
 */
public static String getRotationStr(int rotation) {
    switch (rotation) {
    //Natural orientation
    case Surface.ROTATION_0://0
        return "ROTATION_0";
    case Surface.ROTATION_90://1
        return "ROTATION_90";
    case Surface.ROTATION_180://2
        return "ROTATION_180";
    case Surface.ROTATION_270://3
        return "ROTATION_270";
    default:
        return UNKNOWN;
    }
}

From source file:Main.java

public static int setCameraDisplayOrientation(int cameraId, Camera camera, int displayRotation) {
    CameraInfo info = new CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int degrees = 0;
    switch (displayRotation) {
    case Surface.ROTATION_0:
        degrees = 0;//from ww w .  ja v  a 2  s .  c  o m
        break;
    case Surface.ROTATION_90:
        degrees = 90;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        break;
    case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    int camRotationDegree = 0;
    if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
        camRotationDegree = (info.orientation + degrees) % 360;
        camRotationDegree = (360 - camRotationDegree) % 360; // compensate the mirror
    } else {
        camRotationDegree = (info.orientation - degrees + 360) % 360;
    }

    if (camera != null) {
        camera.setDisplayOrientation(camRotationDegree);
    }
    return camRotationDegree;
}