List of usage examples for android.app Activity getWindowManager
public WindowManager getWindowManager()
From source file:Main.java
public static double getScreenSize(Activity activity) { if (dm == null) { dm = new DisplayMetrics(); }//from w ww.ja v a 2 s. c om activity.getWindowManager().getDefaultDisplay().getMetrics(dm); double x = Math.pow(dm.widthPixels / dm.densityDpi, 2); double y = Math.pow(dm.heightPixels / dm.densityDpi, 2); return Math.sqrt(x + y); }
From source file:Main.java
public static int[] getScreenWH(Activity activity) { int[] WH = { 0, 0 }; DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); WH[0] = metrics.widthPixels;/*from w w w.j a va 2 s . c o m*/ WH[1] = metrics.heightPixels; return WH; }
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;/* ww w .java2 s. co m*/ } return density; }
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;/* w w w . j a v a 2s .co m*/ size[1] = dm.heightPixels; return size; }
From source file:Main.java
public static DisplayMetrics getDisplayMetrics(Activity activity) { if (dm == null) { dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); }//from w ww .ja v a 2s .c om return dm; }
From source file:Main.java
/** * Checks if the device is a tablet or a phone * * @param activityContext/*w w w.j ava 2 s . c o m*/ * The Activity Context. * @return Returns true if the device is a Tablet */ public static boolean isTabletDevice(Context activityContext) { // Verifies if the Generalized Size of the device is XLARGE to be // considered a Tablet boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); // If XLarge, checks if the Generalized Density is at least MDPI // (160dpi) if (xlarge) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = (Activity) activityContext; activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160, // DENSITY_TV=213, DENSITY_XHIGH=320 if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { // Yes, this is a tablet! return true; } } // No, this is not a tablet! return false; }
From source file:Main.java
/** * get a screen shot with default screen size. *//*from w w w. j av a 2s . com*/ public static Bitmap getScreenShot(Activity activity) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); int width = metrics.widthPixels; int height = metrics.heightPixels; return getScreenShot(activity, width, height); }
From source file:Main.java
/** * Get a BitmapDrawable from a local file that is scaled down * to fit the current Window size.// w w w .ja va2 s . co m */ @SuppressWarnings("deprecation") static BitmapDrawable getScaledBitmap(String path, Activity a) { Display display = a.getWindowManager().getDefaultDisplay(); float destWidth = display.getWidth(); float destHeight = display.getHeight(); // read in the dimensions of the image on disk BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); float srcWidth = options.outWidth; float srcHeight = options.outHeight; int inSampleSize = 1; if (srcHeight > destHeight || srcWidth > destWidth) { if (srcWidth > srcHeight) { inSampleSize = Math.round(srcHeight / destHeight); } else { inSampleSize = Math.round(srcWidth / destWidth); } } options = new BitmapFactory.Options(); options.inSampleSize = inSampleSize; Bitmap bitmap = BitmapFactory.decodeFile(path, options); return new BitmapDrawable(a.getResources(), bitmap); }
From source file:Main.java
public static int getWidth(Activity activity) { if (mScreenWidth == 0) { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); mScreenWidth = dm.widthPixels;/*from www .j ava 2 s .com*/ } return mScreenWidth; }
From source file:Main.java
public static int getWindowHeight(Activity activity) { if (mHeightPixels < 0) { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); mWidthPixels = dm.widthPixels;/*from w w w . j a va2 s. c om*/ mHeightPixels = dm.heightPixels; } return mHeightPixels; }