Android Camera Get getCameraRotation(final Context context)

Here you can find the source of getCameraRotation(final Context context)

Description

get Camera Rotation

Declaration

public static int getCameraRotation(final Context context) 

Method Source Code

//package com.java2s;
import android.content.Context;

import android.util.DisplayMetrics;

import android.view.Surface;
import android.view.WindowManager;

public class Main {
    public static int getCameraRotation(final Context context) {
        final WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        int rotation = windowManager.getDefaultDisplay().getRotation();
        final DisplayMetrics metrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(metrics);
        final int width = metrics.widthPixels;
        final int height = metrics.heightPixels;

        if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180)
                && height > width
                || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)
                && width > height) {
            // Need to rotate on portrait device
            rotation = 270 - rotation;/* ww  w.  jav  a  2 s . c o m*/
        }
        return rotation;
    }
}

Related

  1. getDefaultCamera(int position)
  2. getDefaultCameraInstance()
  3. getDefaultFrontFacingCameraInstance()
  4. getNumberOfCameras()
  5. getDefaultBackFacingCameraInstance()
  6. indexOfClosestZoom(Camera.Parameters parameters, double targetZoomRatio)
  7. getLowestResolution(Camera.Parameters cp)
  8. launchCamera(Activity activity)