List of usage examples for android.view WindowManager getDefaultDisplay
public Display getDefaultDisplay();
From source file:com.nextgis.maplibui.util.ControlHelper.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static void lockScreenOrientation(Activity activity) { WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); Configuration configuration = activity.getResources().getConfiguration(); int rotation = windowManager.getDefaultDisplay().getRotation(); // Search for the natural position of the device if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) || configuration.orientation == Configuration.ORIENTATION_PORTRAIT && (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270)) { // Natural position is Landscape switch (rotation) { case Surface.ROTATION_0: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case Surface.ROTATION_90: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); break; case Surface.ROTATION_180: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); break; case Surface.ROTATION_270: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; }/*from w w w. j a va2s. c o m*/ } else { // Natural position is Portrait switch (rotation) { case Surface.ROTATION_0: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; case Surface.ROTATION_90: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; case Surface.ROTATION_180: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); break; case Surface.ROTATION_270: activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); break; } } }
From source file:com.spoiledmilk.ibikecph.util.Util.java
public static void init(WindowManager manager) { if (jsonMapper == null) { jsonMapper = new ObjectMapper(); }/*from w w w . j av a 2 s . com*/ if (metrics == null) { metrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(metrics); if (metrics != null) { screenWidht = metrics.widthPixels; screenHeight = metrics.heightPixels; LOG.d("screenWidth = " + screenWidht); LOG.d("screenHeight = " + screenHeight); LOG.d("density = " + metrics.density); } } }
From source file:com.silentcircle.common.util.ViewUtil.java
/** * Returns screen dimensions in passed Point structure *///from w ww. j a v a 2 s .com public static void getScreenDimensions(final Context context, final Point size) { if (context == null || size == null) { return; } WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); display.getSize(size); }
From source file:com.appassit.common.Utils.java
public static float sp2px(Context context, float sp) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics displaymetrics = new DisplayMetrics(); display.getMetrics(displaymetrics);// w w w .ja v a 2 s . c om final float scale = displaymetrics.scaledDensity; return sp * scale; }
From source file:com.dunrite.xpaper.utility.Utils.java
/** * Gets device's screen resoluton height * * @param context current context//from w w w. j a v a 2s. c om * @return height value * //TODO: get actual value, if possible */ public static int getDeviceResHeight(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); int density = metrics.densityDpi; Log.d("DEVICE HEIGHT", "" + (density / 160) * metrics.heightPixels); return (density / 160) * metrics.heightPixels; }
From source file:com.dunrite.xpaper.utility.Utils.java
/** * Gets Device's screen resolution width * * @param context current context/*from ww w . j a va 2 s . c o m*/ * @return width value * //TODO: get actual value, if possible */ public static int getDeviceResWidth(Context context) { int width = 0; WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); Display display = wm.getDefaultDisplay(); int density = metrics.densityDpi; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealMetrics(metrics); width = metrics.widthPixels; } Log.d("DEVICE WIDTH", "" + width); return width; }
From source file:com.appsimobile.appsii.module.weather.WeatherLoadingService.java
private static int getMaxScreenDimension(WindowManager windowManager) { Point point = new Point(); windowManager.getDefaultDisplay().getSize(point); int dimen = Math.max(point.x, point.y); dimen = (dimen * 3) / 4;/*from www . j av a 2 s. com*/ return dimen; }
From source file:com.android.fastergallery.ui.TileImageView.java
public static boolean isHighResolution(Context context) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); return metrics.heightPixels > 2048 || metrics.widthPixels > 2048; }
From source file:com.pdftron.pdf.utils.Utils.java
/** * Gets the size of the display, in pixels. * * @param context the Context// w w w.ja va 2 s . c om * @param outSize A Point object to receive the size information */ public static void getDisplaySize(Context context, Point outSize) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (outSize == null) { outSize = new Point(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(outSize); } else { outSize.set(display.getWidth(), display.getHeight()); } }
From source file:com.aidy.launcher3.photos.views.TiledImageRenderer.java
private static boolean isHighResolution(Context context) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); return metrics.heightPixels > 2048 || metrics.widthPixels > 2048; }