List of usage examples for android.app Activity getWindowManager
public WindowManager getWindowManager()
From source file:Main.java
public static int getOrientationInDegree(Activity activity) { int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { case Surface.ROTATION_0: degrees = 0;/*from w w w .j a va2s. com*/ break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } return degrees; }
From source file:Main.java
public static int[] getResolution(Activity activity) { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); return new int[] { dm.widthPixels, dm.heightPixels }; }
From source file:Main.java
private static void initScreen(Activity mActivity) { DisplayMetrics metric = new DisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(metric); screenW = metric.widthPixels;/*from w w w .j a v a 2s .c o m*/ screenH = metric.heightPixels; }
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 Pair<Integer, Integer> getResolution(Activity activity) { if (null == sResolution) { int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay().getHeight(); sResolution = new Pair<Integer, Integer>(width, height); }/*from w ww .j a v a 2s .c om*/ return sResolution; }
From source file:Main.java
public static Point getRealScreenSize(Activity activity) { Point result = new Point(); Display display = activity.getWindowManager().getDefaultDisplay(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealSize(result);// w w w . ja va 2 s . c o m } else { display.getSize(result); } return result; }
From source file:Main.java
public static int dpToPixel(Activity activity, float dp) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); return (int) (metrics.density * dp); }
From source file:Main.java
public static float getScreenWidthDp(Activity act) { final DisplayMetrics displayMetrics = new DisplayMetrics(); act.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); float midu = (float) displayMetrics.densityDpi; return displayMetrics.widthPixels / (midu / 160); }
From source file:Main.java
public static float dip2px2(Activity context, float dipValue) { DisplayMetrics dm = new DisplayMetrics(); context.getWindowManager().getDefaultDisplay().getMetrics(dm); final float screen = (float) dm.widthPixels / (float) 240; return screen; }
From source file:Main.java
/** * calculate the display parameters//from ww w.j a v a 2s.co m * * @param activity * @return */ public static DisplayMetrics getDisplayMetrics(Activity activity) { DisplayMetrics displaymetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); return displaymetrics; }