Example usage for android.view Surface ROTATION_90

List of usage examples for android.view Surface ROTATION_90

Introduction

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

Prototype

int ROTATION_90

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

Click Source Link

Document

Rotation constant: 90 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;
    }//from www .  j a  va2 s  .co  m
    return 0f;
}

From source file:Main.java

/**
 * @return the current display rotation in degrees
 *//*from  www  .  j  a va  2s .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:/* w w  w . j  a v a 2s. 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;
        }/*from w w  w  .  j ava2  s.  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 int getRotationAdjustment(int screenRotation) {
    int degrees = 0;
    switch (screenRotation) {
    case Surface.ROTATION_0:
        degrees = 0;//from ww w  .  j  av 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 ww  w  . ja  v a  2  s .  c  o  m*/
        return 0;
    }
}

From source file:Main.java

/**
 * Returns the rotation of the screen from its "natural" orientation.
 * Notice: ANTICLOCKWISE//from   ww  w.  j a  v  a 2 s.  co 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  www  .  j a  va  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;
}

From source file:Main.java

/**
 * Untested, taken from stack-overflow./*from   w  w w .  j av  a 2s . c om*/
 *
 * @param activity
 */
public static void disableScreenOrientationChange(Activity activity) {
    final int orientation = activity.getResources().getConfiguration().orientation;
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();

    if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
        if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) {
        if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        }
    }
}

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;//from   www  .  java 2s .  co m
    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);
}