only 270 and 90 need to be swapped, and only those - Android User Interface

Android examples for User Interface:Screen Orientation

Description

only 270 and 90 need to be swapped, and only those

Demo Code


//package com.java2s;

import android.app.Activity;

import android.view.Surface;

public class Main {

    public static int getCamera2PreviewRotation(Activity activity) {
        int screenOrientation = activity.getWindowManager()
                .getDefaultDisplay().getRotation();

        // Translate rotation constants into degrees
        if (screenOrientation == Surface.ROTATION_0) {
            screenOrientation = 0;// w  w w  .  j  a  va2s  . co  m
        } else if (screenOrientation == Surface.ROTATION_90) {
            screenOrientation = 270;
        } else if (screenOrientation == Surface.ROTATION_180) {
            screenOrientation = 180;
        } else {
            screenOrientation = 90;
        }

        return screenOrientation;
    }
}

Related Tutorials