List of usage examples for android.view Display getMetrics
public void getMetrics(DisplayMetrics outMetrics)
From source file:org.alfresco.mobile.android.application.fragments.DisplayUtils.java
public static int getScreenWidth(FragmentActivity context) { Display display = context.getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); float density = context.getResources().getDisplayMetrics().density; return Math.round(outMetrics.widthPixels / density); }
From source file:org.alfresco.mobile.android.application.fragments.DisplayUtils.java
/** * Returns in dp/*from ww w . ja v a 2 s.c o m*/ * * @param context * @return */ public static int getSplitterWidth(MainActivity context) { Display display = context.getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); float density = context.getResources().getDisplayMetrics().density; SplitPaneLayout split = (SplitPaneLayout) context.findViewById(R.id.master_pane); return (split != null) ? Math.round(split.getSplitterPosition() / density) : Math.round(outMetrics.widthPixels / density); }
From source file:org.alfresco.mobile.android.application.fragments.DisplayUtils.java
public static int getWidth(FragmentActivity context) { Display display = context.getWindowManager().getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); float density = context.getResources().getDisplayMetrics().density; int width = Math.round(outMetrics.widthPixels / density); Resources res = context.getResources(); int coeff;// ww w. j a v a 2 s. c o m if (width < 320) { coeff = res.getInteger(R.integer.width_320); } else if (width < 480) { coeff = res.getInteger(R.integer.width_480); } else if (width < 600) { coeff = res.getInteger(R.integer.width_600); } else if (width < 720) { coeff = res.getInteger(R.integer.width_720); } else if (width < 1000) { coeff = res.getInteger(R.integer.width_1000); } else { coeff = res.getInteger(R.integer.width_max); } return coeff; }
From source file:me.wimanacra.collector.DisplayManagerCollector.java
private static void collectMetrics(@NonNull Display display, JSONObject container) throws JSONException { final DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); JSONObject result = new JSONObject(); collectMetrics(metrics, result);//ww w. java 2s. c o m container.put("metrics", result); }
From source file:count.ly.messaging.DeviceInfo.java
/** * Returns the non-scaled pixel resolution of the current default display being used by the * WindowManager in the specified context. * @param context context to use to retrieve the current WindowManager * @return a string in the format "WxH", or the empty string "" if resolution cannot be determined */// w w w . j a v a2 s. c om static String getResolution(final Context context) { // user reported NPE in this method; that means either getSystemService or getDefaultDisplay // were returning null, even though the documentation doesn't say they should do so; so now // we catch Throwable and return empty string if that happens String resolution = ""; try { final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final Display display = wm.getDefaultDisplay(); final DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); resolution = metrics.widthPixels + "x" + metrics.heightPixels; } catch (Throwable t) { if (Countly.sharedInstance().isLoggingEnabled()) { Log.i(Countly.TAG, "Device resolution cannot be determined"); } } return resolution; }
From source file:com.android.leanlauncher.LauncherAppState.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) static DynamicGrid createDynamicGrid(Context context, DynamicGrid dynamicGrid) { // Determine the dynamic grid properties WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point realSize = new Point(); display.getRealSize(realSize);/*from w w w. j a va 2 s . c o m*/ DisplayMetrics dm = new DisplayMetrics(); display.getMetrics(dm); if (dynamicGrid == null) { Point smallestSize = new Point(); Point largestSize = new Point(); display.getCurrentSizeRange(smallestSize, largestSize); dynamicGrid = new DynamicGrid(context, context.getResources(), Math.min(smallestSize.x, smallestSize.y), Math.min(largestSize.x, largestSize.y), realSize.x, realSize.y, dm.widthPixels, dm.heightPixels); } // Update the icon size DeviceProfile grid = dynamicGrid.getDeviceProfile(); grid.updateFromConfiguration(context, context.getResources(), realSize.x, realSize.y, dm.widthPixels, dm.heightPixels); return dynamicGrid; }
From source file:com.cloverstudio.spika.SpikaApp.java
/** * Sets sliding transport based on screen density and required offset width * <p>/*from ww w . j ava2s .c o m*/ * Depends on width of side offset in dp * * @param sideWidthInDp */ public static void setTransportBasedOnScreenDensity(int sideWidthInDp) { WindowManager wm = (WindowManager) sInstance.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); double sideWidthInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sideWidthInDp, sInstance.getResources().getDisplayMetrics()); double transportRate = 1 - sideWidthInPx / metrics.widthPixels; sInstance.mTransport = (int) Math.floor(metrics.widthPixels * transportRate); }
From source file:despotoski.nikola.github.com.bottomnavigationlayout.Util.java
public static boolean isNavigationBarTranslucent(Context context) { AppCompatActivity activity = (AppCompatActivity) context; getNavigationBarHeight(context);//from w w w . ja va 2 s. c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return false; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return hasSoftwareKeys; } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return (activity.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0; } else { return false; } }
From source file:com.yamin.kk.vlc.Util.java
public static int convertPxToDp(int px) { WindowManager wm = (WindowManager) VLCApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); float logicalDensity = metrics.density; int dp = Math.round(px / logicalDensity); return dp;//from ww w.j av a2 s. c o m }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static int getScreenRealH(Context context) { int h;// w w w . j av a2s . c o m WindowManager winMgr = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = winMgr.getDefaultDisplay(); DisplayMetrics dm = new DisplayMetrics(); if (Build.VERSION.SDK_INT >= 17) { display.getRealMetrics(dm); h = dm.heightPixels; } else { try { Method method = Class.forName("android.view.Display").getMethod("getRealMetrics", DisplayMetrics.class); method.invoke(display, dm); h = dm.heightPixels; } catch (Exception e) { display.getMetrics(dm); h = dm.heightPixels; } } return h; }