List of usage examples for android.view WindowManager getDefaultDisplay
public Display getDefaultDisplay();
From source file:Main.java
public static DisplayMetrics getScreenSize(Context context) { if (displayMetrics == null) { try {//from ww w .j a v a2 s .co m displayMetrics = new DisplayMetrics(); displayMetrics.widthPixels = 1280; displayMetrics.heightPixels = 720; WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(displayMetrics); } catch (Exception e) { Log.e(TAG, e.getMessage()); } } return displayMetrics; }
From source file:Main.java
/** * Gets screen width.//from w w w. j a va2s .c o m * * @param context the context * @return the screen width in pixels */ public static int getScreenWidth(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); Point size = new Point(); display.getSize(size); return size.x; }
From source file:Main.java
public static int getScreenOrientation(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int orientation = Configuration.ORIENTATION_UNDEFINED; if (display.getWidth() == display.getHeight()) { orientation = Configuration.ORIENTATION_SQUARE; } else {// w w w .j av a 2s .co m if (display.getWidth() < display.getHeight()) { orientation = Configuration.ORIENTATION_PORTRAIT; } else { orientation = Configuration.ORIENTATION_LANDSCAPE; } } return orientation; }
From source file:Main.java
/** * Returns the screen/display size/*from www . j a v a 2s . c o m*/ */ public static Point getDisplaySize(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); return size; }
From source file:Main.java
public static Point getScreenSize(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(size);/*from w w w .j ava 2 s .co m*/ } else { size.set(display.getWidth(), display.getHeight()); } return size; }
From source file:Main.java
public static boolean isVertical(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size);// w ww. j a va 2 s . c o m int width = size.x; int height = size.y; if (width > height) { return false; } else { return true; } }
From source file:Main.java
public static int getScreenHeight(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size);// w w w . j a v a 2 s .c o m return size.y; }
From source file:Main.java
public static int getWindowW(Context context) { WindowManager manager = ((Activity) context).getWindowManager(); DisplayMetrics outMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.widthPixels; }
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 w w .java 2 s . c om*/ 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
/** * Returns the size of the screen/*from w w w .j a v a2 s . co m*/ * * @param activity The {@link Activity} to use * @return Point where x=width and y=height */ public static Point getScreenSize(Activity activity) { if (activity != null) { WindowManager service = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); service.getDefaultDisplay().getSize(mScreenSize); } return mScreenSize; }