List of usage examples for android.view WindowManager getDefaultDisplay
public Display getDefaultDisplay();
From source file:Main.java
public static int getScreenHeight(Context context) { WindowManager wManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); wManager.getDefaultDisplay().getMetrics(metrics); return metrics.heightPixels; }
From source file:Main.java
public static int getScreenWidth(Context context) { WindowManager wManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); wManager.getDefaultDisplay().getMetrics(metrics); return metrics.widthPixels; }
From source file:Main.java
public static int[] getScreenSize(Context context) { int[] size = new int[2]; WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display d = w.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); d.getMetrics(metrics);//w w w . j ava 2 s . c o m // since SDK_INT = 1; int widthPixels = metrics.widthPixels; int heightPixels = metrics.heightPixels; // 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
public static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displayMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(displayMetrics); return displayMetrics.widthPixels; }
From source file:Main.java
public static int getScreenWidth(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(dm); return dm.widthPixels; }
From source file:Main.java
public static int getScreenHeightDP(Activity activity) { WindowManager wm = activity.getWindowManager(); //wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display dp = wm.getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); dp.getMetrics(dm);/*from ww w .j ava 2 s. c om*/ float res = dm.heightPixels / dm.density; return (int) res; }
From source file:Main.java
public static int getScreenWidthDP(Activity activity) { WindowManager wm = activity.getWindowManager(); //wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display dp = wm.getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); dp.getMetrics(dm);/* w w w . java 2 s . c o m*/ float res = dm.widthPixels / dm.density; return (int) res; }
From source file:Main.java
public static int getScreenHeight(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(dm); return dm.heightPixels; }
From source file:Main.java
public static DisplayMetrics getScreenMetrics(Context context) { WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(outMetrics); return outMetrics; }
From source file:Main.java
/** * This method calculates maximum size of both width and height of bitmap. * It is twice the device screen diagonal for default implementation (extra quality to zoom image). * Size cannot exceed max texture size.//from ww w.j av a2s. c o m * * @return - max bitmap size in pixels. */ @SuppressWarnings({ "SuspiciousNameCombination", "deprecation" }) public static int calculateMaxBitmapSize(@NonNull Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); int width, height; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(size); width = size.x; height = size.y; } else { width = display.getWidth(); height = display.getHeight(); } int screenDiagonal = (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); Canvas canvas = new Canvas(); return Math.min(screenDiagonal * 2, Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight())); }