get Orientation - Android User Interface

Android examples for User Interface:Screen Orientation

Description

get Orientation

Demo Code


//package com.java2s;

import android.view.Surface;

public class Main {
    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  av a2 s  .  c  om
        } 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;
    }
}

Related Tutorials