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
/** * Method getDeviceScreenWidth(), It's used for checking the screen's with * and To develop the functionality of horizontal direction or vertical * direction, we can used this for seperating the raised issues * /* w w w .ja v a 2 s .c o m*/ * @return Integer Type. */ public static int getDeviceScreenWidth(Context context) { int width; WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { width = wm.getDefaultDisplay().getHeight(); } else { width = wm.getDefaultDisplay().getWidth(); } return width; }
From source file:Main.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") public static Point getFullDisplaySize(Context context) { Point point = new Point(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Method mGetRawH = null, mGetRawW = null; DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics);/*from w w w .ja va 2s.co m*/ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { display.getRealMetrics(outMetrics); point.x = outMetrics.widthPixels; point.y = outMetrics.heightPixels; } else { try { mGetRawH = Display.class.getMethod("getRawHeight"); mGetRawW = Display.class.getMethod("getRawWidth"); point.x = (Integer) mGetRawW.invoke(display); point.y = (Integer) mGetRawH.invoke(display); } catch (Exception e) { display.getMetrics(outMetrics); point.x = display.getWidth(); point.y = display.getHeight(); e.printStackTrace(); } } return point; }
From source file:Main.java
/** * Method getDeviceScreenHeight(). It's used for checking the screen's with * and To develop the functionality of horizontal direction or vertical * direction, we can used this for seperating the raised issues * //from w w w.j av a2 s . co m * @return Integer Type. */ public static int getDeviceScreenHeight(Context context) { int height; WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { height = wm.getDefaultDisplay().getWidth(); } else { height = wm.getDefaultDisplay().getHeight(); } return height; }
From source file:Main.java
/** * Returns DisplayMetrics.//from ww w .ja v a 2s .co m * * @param context * @return */ public static DisplayMetrics getDisplayMetrics(Context context) { WindowManager window = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); window.getDefaultDisplay().getMetrics(outMetrics); return outMetrics; }
From source file:Main.java
/** * Gets device's display resolution.//from w w w. ja va 2s .c om * @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
/** * 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 */// w w w .j a v a 2 s . c om 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 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 int getPortraitCamearaDisplayOrientation(Context context, int cameraId, boolean isFrontCamera) { if (cameraId < 0 || cameraId > getCameraNumber()) { return -1; }/*from w w w . ja v a2s. c o m*/ Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); int rotation = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (isFrontCamera) { result = (cameraInfo.orientation + degrees) % 360; result = (360 - result) % 360; } else { result = (cameraInfo.orientation - degrees + 360) % 360; } return result; }
From source file:Main.java
/** * <pre>//from w ww. j a va 2s. c o m * Get sizes of screen in pixels. * </pre> * @return interger array with 2 elements: width and height */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) @SuppressWarnings("deprecation") public static int[] getDisplaySizes() { Context context = getCurrentContext(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); if (Build.VERSION.SDK_INT < 13) { return new int[] { display.getWidth(), display.getHeight() }; } else { Point point = new Point(); display.getSize(point); return new int[] { point.x, point.y }; } }
From source file:Main.java
/** * Returns a valid DisplayMetrics object * * @param context valid context// w w w .j ava2 s .co m * @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; }