List of usage examples for android.app Activity getWindowManager
public WindowManager getWindowManager()
From source file:Main.java
private static int getCameraDisplayOrientation_1(Activity activity, @SuppressWarnings("deprecation") Camera.CameraInfo cameraInfo) { // android.hardware.Camera.CameraInfo info = // new android.hardware.Camera.CameraInfo(); // android.hardware.Camera.getCameraInfo(cameraId, info); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0;//from ww w . j a v a 2 s. com break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; default: { Log.e(TAG, "un deal with handler task"); } break; } int result; //noinspection deprecation if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (cameraInfo.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (cameraInfo.orientation - degrees + 360) % 360; } return result; }
From source file:Main.java
/** * get activity screen shot bitmap. system status bar is not included. * @param activity the activity/*from w w w . ja v a 2 s .c o m*/ * @return bitmap */ public static Bitmap capture(Activity activity) { View view = activity.getWindow().getDecorView(); view.buildDrawingCache(); Bitmap bitmap = view.getDrawingCache(); Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay().getHeight(); Bitmap b = Bitmap.createBitmap(bitmap, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return b; }
From source file:Main.java
static int calculateOrientation(Activity activity, int cameraId) { if (cameraId == NO_CAMERA) return 0; DisplayMetrics dm = new DisplayMetrics(); Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); int cameraRotationOffset = info.orientation; activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (currentScreenRotation) { case Surface.ROTATION_0: degrees = 0;/* w w w . j a v a2 s . co m*/ break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; orientation = (360 - orientation) % 360; } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } return orientation; }
From source file:Main.java
public static int getDisplayHeight(Activity activity) { int height = 0; if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { Point point = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(point); height = point.y;/* w w w. ja va 2 s .co m*/ } Log.e(TAG, "isSupportSmartBar:" + isSupportSmartBar); if (isSupportSmartBar) { int smartBarHeight = getSmartBarHeight(activity); Log.e(TAG, "smartBarHeight:" + smartBarHeight); height -= smartBarHeight; } if (activity != null && activity.getActionBar() != null) { int actionbar = activity.getActionBar().getHeight(); if (actionbar == 0) { TypedArray actionbarSizeTypedArray = activity .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); actionbar = (int) actionbarSizeTypedArray.getDimension(0, 0); } Log.d(TAG, "actionbar:" + actionbar); height -= actionbar; } int status = getStatusBarHeight(activity); Log.d(TAG, "status:" + status); height -= status; Log.d(TAG, "height:" + height); return height; }
From source file:Main.java
/** * Calculates the clockwise rotation applied to the camera such that the picture will be aligned with the screen * orientation./*from w ww. j a va2s. com*/ * * @param activity the {@link Activity}. * @param cameraId id of the camera. * @return the clockwise rotation in degrees. */ public static int getCameraScreenOrientation(Activity activity, int cameraId) { int cameraScreenOrientation = CAMERA_SCREEN_ORIENTATION_0; // Get camera info. CameraInfo info = new CameraInfo(); Camera.getCameraInfo(cameraId, info); // Get screen orientation. int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = SCREEN_ROTATION_0; switch (rotation) { case Surface.ROTATION_0: degrees = SCREEN_ROTATION_0; break; case Surface.ROTATION_90: degrees = SCREEN_ROTATION_90; break; case Surface.ROTATION_180: degrees = SCREEN_ROTATION_180; break; case Surface.ROTATION_270: degrees = SCREEN_ROTATION_270; break; } /* * Calculate result based on camera and screen orientation. */ if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { // Calculate relative rotation between camera and screen. cameraScreenOrientation = (info.orientation + degrees) % 360; // Account for mirroring. cameraScreenOrientation = (360 - cameraScreenOrientation) % 360; } else { // Calculate relative rotation between camera and screen. cameraScreenOrientation = (info.orientation - degrees + 360) % 360; } return cameraScreenOrientation; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static ImageReader createImageReader(Activity c) { DisplayMetrics metrics = c.getResources().getDisplayMetrics(); int density = metrics.densityDpi; int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; //DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; Display display = c.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size);//from www .j a va2 s . c o m return ImageReader.newInstance(size.x, size.y, PixelFormat.RGB_565, 2); }
From source file:org.solovyev.android.calculator.App.java
@SuppressWarnings("deprecation") public static int getScreenOrientation(@Nonnull Activity activity) { final android.view.Display display = activity.getWindowManager().getDefaultDisplay(); if (display.getWidth() <= display.getHeight()) { return Configuration.ORIENTATION_PORTRAIT; } else {/*w ww. j a v a 2s. c o m*/ return Configuration.ORIENTATION_LANDSCAPE; } }
From source file:Main.java
public static Bitmap takeScreenShot(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true);/*w ww . jav a 2 s .co m*/ view.buildDrawingCache(); Bitmap b1 = view.getDrawingCache(); Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay().getHeight(); Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return b; }
From source file:Main.java
public static Bitmap getSampleBitmap(Activity activity, String filepath) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;// w w w.j av a2s . c o m BitmapFactory.decodeFile(filepath, options); options.inJustDecodeBounds = false; int width = options.outWidth; int height = options.outHeight; DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int scale = Math.min(width / dm.widthPixels, height / dm.heightPixels); options.inSampleSize = scale; Bitmap bitmap2 = BitmapFactory.decodeFile(filepath, options); return bitmap2; }
From source file:Main.java
/** * Take screenshot without status bar./* w w w .j a v a 2s.com*/ * * @param activity * @return screenshot bitmap. */ public static Bitmap takeScreenshot(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bitmap = view.getDrawingCache(); Rect rect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); int statusBarHeight = rect.top; int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay().getHeight(); Bitmap bitmap2 = Bitmap.createBitmap(bitmap, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return bitmap2; }