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

public static void lockOrientation(Activity activity) {
    Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();
    int tempOrientation = activity.getResources().getConfiguration().orientation;
    int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    switch (tempOrientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90)
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        else//ww  w .  ja  v  a2  s .c om
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
        break;
    case Configuration.ORIENTATION_PORTRAIT:
        if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270)
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        else
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
    }

    activity.setRequestedOrientation(orientation);
}

From source file:Main.java

@SuppressLint("NewApi")
public static void lockScreenOrientation(Activity activity) {
    switch (activity.getResources().getConfiguration().orientation) {
    case Configuration.ORIENTATION_PORTRAIT:
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {//from  www  . j a v a  2  s .  c  o m
            int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_180) {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            } else {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
        }
        break;

    case Configuration.ORIENTATION_LANDSCAPE:
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            } else {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            }
        }
        break;
    }
}

From source file:Main.java

/**
 * gets the correct rotation of the camera for the surface rotation
 * requested, adjust for front/back camera
 * /*from www.j a v  a  2s  . c  o  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;
}

From source file:Main.java

public static int getPortraitCamearaDisplayOrientation(Context context, int cameraId, boolean isFrontCamera) {
    if (cameraId < 0 || cameraId > getCameraNumber()) {
        return -1;
    }/*from  w w  w .  j a  va 2s  . com*/
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, cameraInfo);

    int rotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).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;
    }

    int result;
    if (isFrontCamera) {
        result = (cameraInfo.orientation + degrees) % 360;
        result = (360 - result) % 360;
    } else {
        result = (cameraInfo.orientation - degrees + 360) % 360;
    }
    return result;
}

From source file:Main.java

static int calculateOrientation(Activity activity, int cameraId) {
    if (cameraId == NO_CAMERA)
        return 0;

    DisplayMetrics dm = new DisplayMetrics();
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int cameraRotationOffset = info.orientation;

    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation();

    int degrees = 0;
    switch (currentScreenRotation) {
    case Surface.ROTATION_0:
        degrees = 0;//from   ww  w . ja  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 orientation;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        orientation = (cameraRotationOffset + degrees) % 360;
        orientation = (360 - orientation) % 360;
    } else {
        orientation = (cameraRotationOffset - degrees + 360) % 360;
    }

    return orientation;
}

From source file:Main.java

public static int getDisplayRotation(Activity activity) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    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 ww  w .ja  va2 s . c  om
    return 0;
}

From source file:Main.java

private static int getDeviceOrientationDegree(Context context) {

    int degrees = 0;
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    int rotation = windowManager.getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;/*from   ww w  .  jav  a 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;
    }

    return degrees;

}

From source file:Main.java

public static int getOrientationInDegree(Activity activity) {

    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;

    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;/*from w w w  .  ja  v a  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;
    }

    return degrees;
}

From source file:Main.java

/**
 * @Thach Feb 21, 2014//from   w w w .  j a va 2s .  co  m
 * @Desc lock Orientation
 * @param b
 */
@SuppressWarnings("deprecation")
public static void lockOrientation(Activity act, boolean isLock) {
    if (act == null) {
        return;
    }
    if (isLock) {
        Display display = act.getWindowManager().getDefaultDisplay();
        int rotation = display.getRotation();
        int height;
        int width;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
            height = display.getHeight();
            width = display.getWidth();
        } else {
            Point size = new Point();
            display.getSize(size);
            height = size.y;
            width = size.x;
        }
        switch (rotation) {
        case Surface.ROTATION_90:
            if (width > height)
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            else
                act.setRequestedOrientation(9/* reversePortait */);
            break;
        case Surface.ROTATION_180:
            if (height > width)
                act.setRequestedOrientation(9/* reversePortait */);
            else
                act.setRequestedOrientation(8/* reverseLandscape */);
            break;
        case Surface.ROTATION_270:
            if (width > height)
                act.setRequestedOrientation(8/* reverseLandscape */);
            else
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        default:
            if (height > width)
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            else
                act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    } else {
        act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
    }
}

From source file:Main.java

public static int setCameraDisplayOrientation(int cameraId, android.hardware.Camera camera,
        int displayRotation) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int degrees = 0;
    switch (displayRotation) {
    case Surface.ROTATION_0:
        degrees = 0;/*  w  w w .ja  va2  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 camRotationDegree = 0;
    if (info.facing == Camera.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;
}