List of usage examples for android.util DisplayMetrics DisplayMetrics
public DisplayMetrics()
From source file:Main.java
public static int getScreenWidth(Activity activity) { WindowManager manager = activity.getWindowManager(); DisplayMetrics outMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(outMetrics); // int height = outMetrics.heightPixels; int width2 = outMetrics.widthPixels; return width2; }
From source file:Main.java
public static int getScreenHight(Activity activity) { WindowManager manager = activity.getWindowManager(); DisplayMetrics outMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(outMetrics); int height = outMetrics.heightPixels; //int width2 = outMetrics.widthPixels; return height; }
From source file:Main.java
/** * @param context/* w w w. j av a 2 s . co m*/ * @param height * @return */ public static int getMetricsDensity(Context context, float height) { DisplayMetrics localDisplayMetrics = new DisplayMetrics(); ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getMetrics(localDisplayMetrics); return Math.round(height * localDisplayMetrics.densityDpi / 160.0F); }
From source file:Main.java
public static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.widthPixels; }
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
public static int getDeviceDesity(Activity activity) { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); return dm.densityDpi; }
From source file:Main.java
public static int[] getDeviceResolution(Activity activity) { int[] args = new int[2]; DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); args[0] = dm.widthPixels;/*from ww w.j a v a2 s .co m*/ args[1] = dm.heightPixels; return args; }
From source file:Main.java
public static DisplayMetrics getDisplayMetrics(Context context) { Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics);/*from w ww. j a v a 2 s . co m*/ return metrics; }
From source file:Main.java
public static DisplayMetrics getDisplayMetrics(Activity activity) { DisplayMetrics displayMetrics = null; if (density == -1) { displayMetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); }/*from w w w. java 2 s . c om*/ return displayMetrics; }
From source file:Main.java
/** * Returns a valid DisplayMetrics object * * @param context valid context//from ww w. j a v a 2s . c o m * @return DisplayMetrics object */ public 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; }