get Angle from Surface rotation - Android java.lang

Android examples for java.lang:Math Trigonometric Function

Description

get Angle from Surface rotation

Demo Code


//package com.java2s;
import android.content.Context;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;

public class Main {
    static float getAngle(Context context, float pitch_angle,
            float roll_angle) {
        Display display = ((WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();/*from  ww w . j a  v  a  2s .c  o m*/
        float angle = 0;
        switch (display.getRotation()) {
        case Surface.ROTATION_90:
        case Surface.ROTATION_270:
            angle = roll_angle;
            break;
        case Surface.ROTATION_0:
        case Surface.ROTATION_180:
            angle = pitch_angle;
            break;
        }
        return angle;
    }
}

Related Tutorials