List of usage examples for android.util DisplayMetrics DisplayMetrics
public DisplayMetrics()
From source file:Main.java
public static DisplayMetrics getScreenDisplayMetrics(Activity context) { DisplayMetrics metric = new DisplayMetrics(); context.getWindowManager().getDefaultDisplay().getMetrics(metric); return metric; }
From source file:Main.java
public static float getScreenDensity(Context context) { try {/*from ww w .j a v a 2 s . c o m*/ DisplayMetrics dm = new DisplayMetrics(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); manager.getDefaultDisplay().getMetrics(dm); return dm.density; } catch (Exception ex) { } return 1.0f; }
From source file:Main.java
public static int[] sizeScreen(Activity activity) { int[] size = new int[2]; DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); size[0] = dm.widthPixels;//from w w w . j ava2 s . c o m size[1] = dm.heightPixels; return size; }
From source file:Main.java
public static int[] getScreenSize(Context context) { int[] screens; DisplayMetrics dm = new DisplayMetrics(); dm = context.getResources().getDisplayMetrics(); screens = new int[] { dm.widthPixels, dm.heightPixels }; return screens; }
From source file:Main.java
public static int getScreenWidth(Context context) { DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); display.getMetrics(dm);//from w ww . j a v a 2s .co m return dm.widthPixels; }
From source file:Main.java
public static int getScreenHeight(Context context) { DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); display.getMetrics(dm);//from w w w . j a va2s . co m return dm.heightPixels; }
From source file:Main.java
private static float getDensity(Activity activity) { if (density < 0) { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); density = dm.density;// w ww . j ava 2 s . c o m } return density; }
From source file:Main.java
public static int getScreenHeightPixels(Activity activity) { if (activity == null) { return 0; }/*from w ww. j a v a 2s. co m*/ DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); return dm.heightPixels; }
From source file:Main.java
public static int getScreenWidthPixels(Activity activity) { if (activity == null) { return 0; }// ww w . j a va2 s .c o m DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); return dm.widthPixels; }
From source file:Main.java
private static double getDisplayInches(Activity activity) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); int widthPixels = metrics.widthPixels; int heightPixels = metrics.heightPixels; float widthDpi = metrics.xdpi; float heightDpi = metrics.ydpi; float widthInches = widthPixels / widthDpi; float heightInches = heightPixels / heightDpi; double diagonalInches = Math.sqrt((widthInches * widthInches) + (heightInches * heightInches)); return diagonalInches; }