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
@SuppressWarnings("deprecation") @SuppressLint("NewApi") public static Point getScreenSize(Context mContext) { WindowManager wm = (WindowManager) mContext.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 a v a 2 s.c o m return size; } else { size.x = display.getWidth(); size.y = display.getHeight(); return size; } }
From source file:Main.java
public static int getDisplayHeight(Context context) { if (displayHeight <= 0) { WindowManager wm = (WindowManager) context.getApplicationContext() .getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); displayHeight = dm.heightPixels; }/*from ww w . jav a 2 s . c o m*/ return displayHeight; }
From source file:Main.java
public static int[] getScreenPixels(Context context) { DisplayMetrics displaysMetrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) (context.getSystemService(Context.WINDOW_SERVICE)); windowManager.getDefaultDisplay().getMetrics(displaysMetrics); int[] widthAndHeight = new int[2]; widthAndHeight[0] = displaysMetrics.widthPixels; widthAndHeight[1] = displaysMetrics.heightPixels; return widthAndHeight; }
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 ww w. j a v a 2 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 Point getScreenSize(Context context) { if (screenSize != null) { return screenSize; }//from w ww . j a v a 2 s .co m int pxWidth; int pxHeight; Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); pxWidth = display.getWidth(); pxHeight = display.getHeight(); screenSize = new Point(pxWidth, pxHeight); return screenSize; }
From source file:Main.java
public static Bitmap decodeSampledBitmapByPath(Context context, String path) { DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(displayMetrics); final int height = displayMetrics.heightPixels; final int width = displayMetrics.widthPixels; // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w ww . j av a 2s . co m BitmapFactory.decodeFile(path, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, width, height); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(path, options); }
From source file:Main.java
public static float getDensity(Context context) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); manager.getDefaultDisplay().getMetrics(metrics); return metrics.density; }
From source file:Main.java
public static DisplayMetrics getScreenSize(Context context) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); display.getMetrics(metrics);/*w w w . java 2 s . c o m*/ return metrics; }
From source file:Main.java
public static WindowManager windowManagerFromContext(@NonNull Context context) { if (context instanceof Activity) { return ((Activity) context).getWindowManager(); }/*from w w w. j a va2s . c o m*/ return (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); }
From source file:Main.java
/** * Get the screen width.// w w w . ja v a2s . c o m * * @param context * @return the screen width */ public static int getScreenWidth(Context context) { if (context != null) { DisplayMetrics displayMetrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(displayMetrics); return displayMetrics.widthPixels; } else { return 1080; } }