List of usage examples for android.view WindowManager getDefaultDisplay
public Display getDefaultDisplay();
From source file:Main.java
public static int getScreenHeight(Context paramContext) { WindowManager localWindowManager = (WindowManager) paramContext.getSystemService("window"); DisplayMetrics localDisplayMetrics = new DisplayMetrics(); localWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics); return localDisplayMetrics.heightPixels; }
From source file:Main.java
/** * Get the size of the Display.// ww w. ja va 2s . c om * @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
public static void getListViewSize(ListView listView, Context context) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null || listAdapter.getCount() < 2) { // pre-condition return;/*from w ww .j a v a2 s .com*/ } WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); int totalHeight = 0; int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(size.x, View.MeasureSpec.AT_MOST); int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST); for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(desiredWidth, listItem.getHeight()); totalHeight += listItem.getMeasuredHeight(); } totalHeight += listView.getPaddingTop() + listView.getPaddingBottom(); totalHeight += (listView.getDividerHeight() * (listAdapter.getCount() + 1)); ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight; listView.setLayoutParams(params); listView.requestLayout(); }
From source file:Main.java
public static DisplayMetrics getScreenPixels(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); return outMetrics; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static int getScreenRealH(Context context) { int h;//from www . ja v a 2 s.co m WindowManager winMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = winMgr.getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); if (Build.VERSION.SDK_INT >= 17) { display.getRealMetrics(dm); h = dm.heightPixels; } else { try { Method method = Class.forName("android.view.Display").getMethod("getRealMetrics", DisplayMetrics.class); method.invoke(display, dm); h = dm.heightPixels; } catch (Exception e) { display.getMetrics(dm); h = dm.heightPixels; } } return h; }
From source file:Main.java
public static int[] getWidthAndHeight(Context context) { WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(metrics); return new int[] { metrics.widthPixels, metrics.heightPixels }; }
From source file:Main.java
private static int getDeviceOrientationDegree(Context context) { int degrees = 0; WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int rotation = windowManager.getDefaultDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_0: degrees = 0;/* w w w . j a v a 2 s. c o m*/ break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } return degrees; }
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./*from w w w .j av a 2s. com*/ * * @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
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 w w. j a v a 2 s. c o m*/ // since SDK_INT = 1; int widthPixels = metrics.widthPixels; int heightPixels = metrics.heightPixels; if (!useDeviceSize) { size[0] = widthPixels; size[1] = heightPixels; 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
public static Pair<Integer, Integer> getScreenDimensions(Context paramContext) { WindowManager localWindowManager = (WindowManager) paramContext.getSystemService("window"); DisplayMetrics localDisplayMetrics = new DisplayMetrics(); localWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics); int i = Math.min(localDisplayMetrics.widthPixels, localDisplayMetrics.heightPixels); int j = Math.max(localDisplayMetrics.widthPixels, localDisplayMetrics.heightPixels); return new Pair(Integer.valueOf(i), Integer.valueOf(j)); }