List of usage examples for android.view Display getMetrics
public void getMetrics(DisplayMetrics outMetrics)
From source file:Main.java
public static int getScreenHeightDP(Activity activity) { WindowManager wm = activity.getWindowManager(); //wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display dp = wm.getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); dp.getMetrics(dm); float res = dm.heightPixels / dm.density; return (int) res; }
From source file:Main.java
public static int getScreenWidthDP(Activity activity) { WindowManager wm = activity.getWindowManager(); //wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display dp = wm.getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); dp.getMetrics(dm); float res = dm.widthPixels / dm.density; return (int) res; }
From source file:Main.java
public static DisplayMetrics getScreenSizeInPx(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); return metrics; }
From source file:Main.java
public static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); return metrics.widthPixels; }
From source file:Main.java
public static int getScreenHeight(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); return metrics.heightPixels; }
From source file:Main.java
public static int getScreeWH(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); return outMetrics.heightPixels; }
From source file:Main.java
public static int dp2px(Context context, int dp) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics displaymetrics = new DisplayMetrics(); display.getMetrics(displaymetrics); return (int) (dp * displaymetrics.density + 0.5f); }
From source file:Main.java
public static int px2dp(Context context, int px) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics displaymetrics = new DisplayMetrics(); display.getMetrics(displaymetrics); return (int) (px / displaymetrics.density + 0.5f); }
From source file:Main.java
public static int getScreenWidth(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); return metrics.widthPixels; }
From source file:Main.java
public static int getDPI() { if (sActivity != null) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = sActivity.getWindowManager(); if (wm != null) { Display d = wm.getDefaultDisplay(); if (d != null) { d.getMetrics(metrics); return (int) (metrics.density * 160.0f); }/*www. j a v a2 s . c o m*/ } } return -1; }