List of usage examples for android.graphics Point Point
public Point()
From source file:Main.java
public static int getFullScreenSizeWidth(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 .co m*/ 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 realWidth; }
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 {// ww w . jav a 2s .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
@SuppressLint("NewApi") @SuppressWarnings("deprecation") public static int[] getScreenWidthHeight(Context context) { int[] widthAndHeight = new int[2]; WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT >= 13) { Point size = new Point(); display.getSize(size);/*from ww w . jav a 2 s . c o m*/ widthAndHeight[0] = size.x; widthAndHeight[1] = size.y; } else { widthAndHeight[0] = display.getWidth(); widthAndHeight[1] = display.getHeight(); } return widthAndHeight; }
From source file:Main.java
/** * Gets device's display resolution./*from w ww. ja v a 2 s . c o m*/ * @since 0.1.0 * @param aContext The context from which the system service is retrieved to get the window's information. * @return The struct of Point with x attribute contains the width and y attribute contains the height. */ public static Point getDisplayResolution(Context aContext) { WindowManager wm = (WindowManager) (aContext.getSystemService(Context.WINDOW_SERVICE)); Point p = new Point(); wm.getDefaultDisplay().getSize(p); return p; }
From source file:Main.java
/** * @return return screen height px unit. *//*from w w w.ja va 2 s . com*/ 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; }
From source file:Main.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) public static int getScreenHeight(Context ctx) { WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int height;/*from w ww . j a v a2 s .co m*/ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) { height = display.getHeight(); // deprecated } else { Point size = new Point(); display.getSize(size); height = size.y; } return height; }
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. ja va 2s .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 Point calcDecodeSizeHint(ImageView imageView) { Point p = new Point(); LayoutParams params = imageView.getLayoutParams(); p.x = (params != null) ? params.width : imageView.getWidth(); p.y = (params != null) ? params.height : imageView.getHeight(); return p;/* w w w . j av a 2s . c o m*/ }
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 *//*ww w .j a va 2 s . 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
public static float sizeYByX(WindowManager windowManager, float baseY, float basex, int exceptDis) { final Display display = windowManager.getDefaultDisplay(); Point mPoint = new Point(); getSize(display, mPoint);/* w w w . ja v a2s . com*/ if (exceptDis > mPoint.x) { return 0.0f; } float displayWidth = mPoint.x - exceptDis; float scaleX = displayWidth / basex; return baseY * scaleX; }