Example usage for android.view Surface ROTATION_0

List of usage examples for android.view Surface ROTATION_0

Introduction

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

Prototype

int ROTATION_0

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

Click Source Link

Document

Rotation constant: 0 degree rotation (natural orientation)

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;/* w w  w  .j a va  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;
    }
    Log.d(TAG, "camera display orientation: " + result);
    camera.setDisplayOrientation(result);

    return result;
}

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   w w  w  . jav  a2  s . c o m
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 ww. j  ava2 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 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;/*from   w w w.  j a v 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 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;//ww  w  . j a  v  a 2  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;
    }

    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://  w w w. j  a v a  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;//from w ww . j a  v  a2s .  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;
    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

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//www  .  j  a  v a  2 s. com
            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

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