List of usage examples for android.content Context WINDOW_SERVICE
String WINDOW_SERVICE
To view the source code for android.content Context WINDOW_SERVICE.
Click Source Link
From source file:Main.java
public static int getFullScreenSizeHeight(Context context) { int realWidth; int realHeight; WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point point = new Point(); if (Build.VERSION.SDK_INT >= 17) { //new pleasant way to get real metrics DisplayMetrics realMetrics = new DisplayMetrics(); display.getRealMetrics(realMetrics); realWidth = realMetrics.widthPixels; realHeight = realMetrics.heightPixels; } else if (Build.VERSION.SDK_INT >= 14) { //reflection for this weird in-between time try {/*from ww w . j a va2 s. com*/ Method mGetRawH = Display.class.getMethod("getRawHeight"); Method mGetRawW = Display.class.getMethod("getRawWidth"); realWidth = (Integer) mGetRawW.invoke(display); realHeight = (Integer) mGetRawH.invoke(display); } catch (Exception e) { //this may not be 100% accurate, but it's all we've got realWidth = display.getWidth(); realHeight = display.getHeight(); Log.e("Display Info", "Couldn't use reflection to get the real display metrics."); } } else { //This should be close, as lower API devices should not have window navigation bars realWidth = display.getWidth(); realHeight = display.getHeight(); } return realHeight; }
From source file:Main.java
public static DisplayMetrics getDisplayMetrics(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displayMetrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(displayMetrics); return displayMetrics; }
From source file:Main.java
/** * This method to get screen size./*from w w w . ja v a 2 s. c o m*/ * * @param context * @return window manager instance which contains width and height of the * screen */ public static DisplayMetrics getScreenSize(Context context) { // TODO Auto-generated method stub DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); return dm; }
From source file:Main.java
/** Returns the result of Display.getRotation, or Surface.ROTATION_0 if the getRotation method isn't available in * the current Android API.//from w ww. j a v a2 s . c om */ public static int getDeviceRotation(Context context) { try { Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); Method rotationMethod = null; // look for getRotation or the deprecated getOrientation for (String methodName : new String[] { "getRotation", "getOrientation" }) { try { rotationMethod = Display.class.getMethod(methodName); break; } catch (Exception ignored) { } } if (rotationMethod != null) { return (Integer) rotationMethod.invoke(display); } } catch (Exception ignored) { } return Surface.ROTATION_0; }
From source file:Main.java
public static float getDimensionPixelSize(int unit, float value, Context context) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); switch (unit) { case PX://from ww w . jav a2 s . c o m return value; case DIP: case SP: return TypedValue.applyDimension(unit, value, metrics); default: throw new IllegalArgumentException("unknow unix"); } }
From source file:Main.java
public static int getOrientation(Context context) { DisplayMetrics displayMetrics = new DisplayMetrics(); displayMetrics.widthPixels = 1280;/* w w w . j a v a2s . c o m*/ displayMetrics.heightPixels = 720; try { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(displayMetrics); } catch (Exception e) { //do nothing } if (displayMetrics.heightPixels > displayMetrics.widthPixels) { return PORTRAIT; } else { return LANDSCAPE; } }
From source file:Main.java
public static void init(Context context) { if (context == null) { return;/*w ww.ja v a 2s. c om*/ } DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); SCREEN_WIDTH_PIXELS = dm.widthPixels; SCREEN_HEIGHT_PIXELS = dm.heightPixels; SCREEN_DENSITY = dm.density; SCREEN_WIDTH_DP = (int) (SCREEN_WIDTH_PIXELS / dm.density); SCREEN_HEIGHT_DP = (int) (SCREEN_HEIGHT_PIXELS / dm.density); }
From source file:Main.java
/** * Get the size of the Display./* w w w .j av a 2s . c o m*/ * @param context * @return Point */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static Point getScreenSize(Context context) { Point p = new Point(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (VERSION.SDK_INT >= 13) { windowManager.getDefaultDisplay().getSize(p); } else { p.x = windowManager.getDefaultDisplay().getWidth(); p.y = windowManager.getDefaultDisplay().getHeight(); } return p; }
From source file:Main.java
/** * Method getDensity() used to get the Device's Density. With this function, * we can use for checking the device's density and supporting for other * devices./* ww w .j a va 2 s .c om*/ * * @param context * The Application Context. * @return Integer Type. */ public static int getDensity(Context context) { final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); return metrics.densityDpi; }
From source file:Main.java
/** * @return return screen height px unit. *//*from w w w. j av a2 s . co m*/ public static int getScreenHeigth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); return size.y; }