List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:com.adjust.sdk.Util.java
protected static String getUserAgent(final Context context) { final Resources resources = context.getResources(); final DisplayMetrics displayMetrics = resources.getDisplayMetrics(); final Configuration configuration = resources.getConfiguration(); final Locale locale = configuration.locale; final int screenLayout = configuration.screenLayout; final String[] parts = { getPackageName(context), getAppVersion(context), getDeviceType(screenLayout), getDeviceName(), getOsName(), getOsVersion(), getLanguage(locale), getCountry(locale), getScreenSize(screenLayout), getScreenFormat(screenLayout), getScreenDensity(displayMetrics), getDisplayWidth(displayMetrics), getDisplayHeight(displayMetrics) }; return TextUtils.join(" ", parts); }
From source file:org.chromium.chrome.browser.widget.selection.SelectableListLayout.java
/** * @param displayStyle The current display style.. * @param resources The {@link Resources} used to retrieve configuration and display metrics. * @return The lateral padding to use for the current display style. *///from w w w. j a v a2 s . co m public static int getPaddingForDisplayStyle(DisplayStyle displayStyle, Resources resources) { int padding = 0; if (displayStyle.horizontal == HorizontalDisplayStyle.WIDE) { int screenWidthDp = resources.getConfiguration().screenWidthDp; float dpToPx = resources.getDisplayMetrics().density; padding = (int) (((screenWidthDp - UiConfig.WIDE_DISPLAY_STYLE_MIN_WIDTH_DP) / 2.f) * dpToPx); padding = (int) Math.max(WIDE_DISPLAY_MIN_PADDING_DP * dpToPx, padding); } return padding; }
From source file:com.waz.zclient.utils.ViewUtils.java
public static int toPx(Resources resources, int dp) { final float scale = resources.getDisplayMetrics().density; return (int) (dp * scale + 0.5f); }
From source file:com.waz.zclient.utils.ViewUtils.java
public static int toPx(Resources resources, double dp) { final float scale = resources.getDisplayMetrics().density; return (int) (dp * scale + 0.5f); }
From source file:ch.arnab.simplelauncher.GridFragment.java
public static int convertDpToPixels(float dp, Context context) { Resources resources = context.getResources(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); }
From source file:me.zhang.bingo.Utility.java
public static void applyAppLanguage(Context context) { Locale myLocale = Utility.getChoosedLocale(context); Resources res = context.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale;/*from w w w .ja v a2 s . c om*/ res.updateConfiguration(conf, dm); }
From source file:Main.java
public static void updateConfiguration(Context context) { Resources resources = context.getResources(); Configuration conf = resources.getConfiguration(); Locale current = Locale.getDefault(); String currentLanguage = current.getDisplayLanguage(); if (Locale.CHINESE.getDisplayLanguage().equals(currentLanguage) || Locale.ENGLISH.getDisplayLanguage().equals(currentLanguage)) { return;/* www. ja v a 2 s . c o m*/ } conf.locale = Locale.ENGLISH; resources.updateConfiguration(conf, resources.getDisplayMetrics()); }
From source file:me.zhang.bingo.Utility.java
/** * This method converts dp unit to equivalent pixels, depending on device density. * * @param dp A value in dp (density independent pixels) unit. Which we need to convert * into pixels//from w ww. j ava2s . c o m * @param context Context to get resources and device specific display metrics * @return A float value to represent px equivalent to dp depending on device density */ public static float convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); }
From source file:me.zhang.bingo.Utility.java
/** * This method converts device specific pixels to density independent pixels. * * @param px A value in px (pixels) unit. Which we need to convert into db * @param context Context to get resources and device specific display metrics * @return A float value to represent dp equivalent to px value */// w ww.j ava 2 s . c o m public static float convertPixelsToDp(float px, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return px / ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); }
From source file:org.bottiger.podcast.utils.UIUtils.java
/** * This method converts dp unit to equivalent pixels, depending on device density. * * @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels * @param context Context to get resources and device specific display metrics * @return A float value to represent px equivalent to dp depending on device density */// www . j a v a 2 s .c o m public static float convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return px; }