get Display Rotation via Context - Android User Interface

Android examples for User Interface:Display

Description

get Display Rotation via Context

Demo Code


import java.util.List;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.view.Surface;
import android.view.WindowManager;

public class Main{
    private final static String TAG = "CameraUtils";
    private static int getDisplayRotation(Context ctx) {
        WindowManager wm = (WindowManager) ctx
                .getSystemService(Context.WINDOW_SERVICE);

        int rotation;

        switch (wm.getDefaultDisplay().getOrientation()) {

        case Surface.ROTATION_90:
            rotation = 90;//w w  w. j av  a2  s  .  c  o m
            break;

        case Surface.ROTATION_180:
            rotation = 180;
            break;

        case Surface.ROTATION_270:
            rotation = 270;
            break;

        default:
            rotation = 0;
            break;
        }
        return rotation;
    }
}

Related Tutorials