List of usage examples for android.view WindowManager getDefaultDisplay
public Display getDefaultDisplay();
From source file:Main.java
/** * Returns a valid DisplayMetrics object * * @param context valid context//from w w w. ja v a 2 s .c om * @return DisplayMetrics object */ static DisplayMetrics getDisplayMetrics(final Context context) { final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final DisplayMetrics metrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(metrics); return metrics; }
From source file:Main.java
public static DisplayMetrics getDeviceDisplayMetrics(Context context) { android.view.WindowManager windowsManager = (android.view.WindowManager) context .getSystemService(Context.WINDOW_SERVICE); android.view.Display display = windowsManager.getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics);//from w ww. j av a 2 s . com return outMetrics; }
From source file:Main.java
public static int[] getScreenSize(Context context, boolean useDeviceSize) { int[] size = new int[2]; WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display d = w.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); d.getMetrics(metrics);/*from w ww . j a va 2s . com*/ // since SDK_INT = 1; int widthPixels = metrics.widthPixels; int heightPixels = metrics.heightPixels; if (!useDeviceSize) { size[0] = widthPixels; size[1] = heightPixels - getStatusBarHeight(context); return size; } // includes window decorations (statusbar bar/menu bar) if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) try { widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d); heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d); } catch (Exception ignored) { } // includes window decorations (statusbar bar/menu bar) if (Build.VERSION.SDK_INT >= 17) try { Point realSize = new Point(); Display.class.getMethod("getRealSize", Point.class).invoke(d, realSize); widthPixels = realSize.x; heightPixels = realSize.y; } catch (Exception ignored) { } size[0] = widthPixels; size[1] = heightPixels; return size; }
From source file:Main.java
/** * Computes the navigation bar height comparing the usable screen height and the real display height. * Please note that the system status bar is considered part of the usable screen height. * @param context Android Context instance * @return The height in pixels of the system navigation bar *///from ww w . j av a 2s . c o m public static int getNavigationBarSize(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); //noinspection ConstantConditions Display display = windowManager.getDefaultDisplay(); Point appUsableSize = new Point(); display.getSize(appUsableSize); Point realScreenSize = new Point(); display.getRealSize(realScreenSize); return realScreenSize.y - appUsableSize.y; }
From source file:Main.java
/** * Returns a valid DisplayMetrics object * * @param context valid context//from w w w .ja v a 2 s .c o m * @return DisplayMetrics object */ public static DisplayMetrics getDisplayMetrics(final Context context) { final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final DisplayMetrics metrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(metrics); return metrics; }
From source file:Main.java
public static void getDisplayDpi(Context ctx) { DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); double x = Math.pow(dm.widthPixels / dm.xdpi, 2); double y = Math.pow(dm.heightPixels / dm.ydpi, 2); double screenInches = Math.sqrt(x + y); int screenInch = (int) Math.round(screenInches); Log.d("screeninch", String.valueOf(screenInch)); int dapi = dm.densityDpi; Log.d("dapi", String.valueOf(dapi)); try {/*w w w. j ava 2 s . c o m*/ switch (dm.densityDpi) { case DisplayMetrics.DENSITY_LOW: UI_DENSITY = 120; if (screenInch <= 7) { UI_SIZE = 4; } else { UI_SIZE = 10; } break; case DisplayMetrics.DENSITY_MEDIUM: UI_DENSITY = 160; if (screenInch <= 7) { UI_SIZE = 4; } else { UI_SIZE = 10; } break; case DisplayMetrics.DENSITY_HIGH: UI_DENSITY = 240; if (screenInch <= 7) { UI_SIZE = 4; } else { UI_SIZE = 10; } break; default: break; } } catch (Exception e) { // Caught exception here } }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static int getSoftKeyBarHeight(Context context) { // getRealMetrics is only available with API 17 and + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); int usableHeight = metrics.heightPixels; wm.getDefaultDisplay().getRealMetrics(metrics); int realHeight = metrics.heightPixels; if (realHeight > usableHeight) { return realHeight - usableHeight; } else {/*from w ww. j ava2s . co m*/ return 0; } } return 0; }
From source file:Main.java
/** * Compute the minimum cache size for a view. When the cache is created we do not actually * know the size of the mapview, so the screenRatio is an approximation of the required size. * * @param c the context/*from www.j a v a2 s. c o m*/ * @param tileSize the tile size * @param overdrawFactor the overdraw factor applied to the mapview * @param screenRatio the part of the screen the view covers * @return the minimum cache size for the view */ @SuppressWarnings("deprecation") @TargetApi(13) public static int getMinimumCacheSize(Context c, int tileSize, double overdrawFactor, float screenRatio) { WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int height; int width; if (android.os.Build.VERSION.SDK_INT >= 13) { Point p = new Point(); display.getSize(p); height = p.y; width = p.x; } else { // deprecated since Android 13 height = display.getHeight(); width = display.getWidth(); } // height * overdrawFactor / tileSize calculates the number of tiles that would cover // the view port, adding 1 is required since we can have part tiles on either side, // adding 2 adds another row/column as spare and ensures that we will generally have // a larger number of tiles in the cache than a TileLayer will render for a view. // Multiplying by screenRatio adjusts this somewhat inaccurately for MapViews on only part // of a screen (the result can be too low if a MapView is very narrow). // For any size we need a minimum of 4 (as the intersection of 4 tiles can always be in the // middle of a view. return (int) Math.max(4, screenRatio * (2 + (height * overdrawFactor / tileSize)) * (2 + (width * overdrawFactor / tileSize))); }
From source file:Main.java
public static DisplayMetrics getDisplayMetric(Context context) { if (context != null) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displayMetrics = new DisplayMetrics(); Display display = windowManager.getDefaultDisplay(); display.getMetrics(displayMetrics); return displayMetrics; }// w w w . ja v a 2 s. com return null; }
From source file:Main.java
private static Point getScreenSizeInternal(final Context context) { Point size = null;//from ww w.j a v a 2 s . c o m final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (windowManager != null) { final Display display = windowManager.getDefaultDisplay(); if (display != null) { // only works if Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2 size = new Point(); display.getSize(size); } } return size; }