List of usage examples for android.app Activity getWindowManager
public WindowManager getWindowManager()
From source file:Main.java
@SuppressLint("NewApi") public static void lockScreenOrientation(Activity activity) { switch (activity.getResources().getConfiguration().orientation) { case Configuration.ORIENTATION_PORTRAIT: if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else {//from w w w . j a va 2 s. co m int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_180) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } } break; case Configuration.ORIENTATION_LANDSCAPE: if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } break; } }
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; Log.w(TAG, "cameraRotationOffset = " + cameraRotationOffset); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Log.w(TAG, "currentScreenRotation = " + currentScreenRotation); 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; } Log.w(TAG, "degrees = " + degrees); int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; orientation = (360 - orientation) % 360; } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } Log.w(TAG, "orientation = " + orientation); return orientation; }
From source file:com.cardvlaue.sys.util.ScreenUtil.java
/** * ??// w ww .java 2s. co m */ public static int screenWidth(Activity activity) { DisplayMetrics outMetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics); return outMetrics.widthPixels; }
From source file:Main.java
static int calculateOrientationHint(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; Log.w(TAG, "OrientationHint cameraRotationOffset = " + cameraRotationOffset); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int currentScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); Log.w(TAG, "OrientationHint currentScreenRotation = " + currentScreenRotation); int degrees = 0; switch (currentScreenRotation) { case Surface.ROTATION_0: degrees = 0;/*from w w w .ja va2 s .c om*/ break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } Log.w(TAG, "OrientationHint degrees = " + degrees); int orientation; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { orientation = (cameraRotationOffset + degrees) % 360; if (degrees != 0) { orientation = (360 - orientation) % 360; } } else { orientation = (cameraRotationOffset - degrees + 360) % 360; } Log.w(TAG, "orientationHint = " + orientation); return orientation; }
From source file:menion.android.whereyougo.gui.extension.CustomActivity.java
protected static void customOnCreate(Activity activity) { //Logger.v(activity.getLocalClassName(), "customOnCreate(), id:" + activity.hashCode()); // set main activity parameters if (!(activity instanceof CustomMain)) { // Settings.setLanguage(this); Settings.setScreenBasic(activity); }//from w ww . ja v a2s .c o m // set screen size Const.SCREEN_WIDTH = activity.getWindowManager().getDefaultDisplay().getWidth(); Const.SCREEN_HEIGHT = activity.getWindowManager().getDefaultDisplay().getHeight(); }
From source file:jahirfiquitiva.iconshowcase.utilities.utils.Utils.java
public static int getNavigationBarHeight(Activity activity) { // getRealMetrics is only available with API 17 and + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); int usableHeight = activity.getResources().getBoolean(R.bool.isTablet) ? metrics.heightPixels : activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? metrics.widthPixels : metrics.heightPixels; activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); int realHeight = activity.getResources().getBoolean(R.bool.isTablet) ? metrics.heightPixels : activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? metrics.widthPixels : metrics.heightPixels; if (realHeight > usableHeight) return realHeight - usableHeight; else//from w w w . j a va 2 s . com return 0; } return 0; }
From source file:Main.java
public static void showAsPopup(Activity activity) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { return;/*w w w.ja v a 2 s . c o m*/ } activity.requestWindowFeature(Window.FEATURE_ACTION_BAR); //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest Window window = activity.getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND); Display display = activity.getWindowManager().getDefaultDisplay(); WindowManager.LayoutParams params = window.getAttributes(); params.height = (int) (display.getHeight() * 0.95); params.width = Math.min((int) (display.getWidth() * 0.9), (int) (params.height * 0.85)); params.gravity = Gravity.BOTTOM; params.alpha = 1.0f; params.dimAmount = 0.5f; window.setAttributes(params); }
From source file:com.frostwire.android.gui.util.UIUtils.java
public static boolean isPortrait(Activity activity) { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); return dm.heightPixels > dm.widthPixels; }
From source file:com.frostwire.android.gui.util.UIUtils.java
public static double getScreenInches(Activity activity) { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); double x_sq = Math.pow(dm.widthPixels / dm.xdpi, 2); double y_sq = Math.pow(dm.heightPixels / dm.ydpi, 2); // pitagoras//from w ww .j a va 2 s .c o m return Math.sqrt(x_sq + y_sq); }
From source file:tv.ouya.sdk.OuyaUnityPlugin.java
private static int getDisplayWidth() { Activity activity = IOuyaActivity.GetActivity(); WindowManager windowManager = activity.getWindowManager(); Display display = windowManager.getDefaultDisplay(); Point size = new Point(); display.getSize(size);//w ww. j av a 2 s.com return size.x; }