List of usage examples for android.content Context getResources
public abstract Resources getResources();
From source file:Main.java
public static float pixelsToSp(float px, Context context) { Resources resources = context.getResources(); float scaledDensity = resources.getDisplayMetrics().scaledDensity; return px / scaledDensity; }
From source file:Main.java
public static int convertDpToPx(Context context, float dp) { return (int) (dp * context.getResources().getDisplayMetrics().density + 0.5f); }
From source file:Main.java
public static boolean isZh(Context context) { Locale locale = context.getResources().getConfiguration().locale; String language = locale.getLanguage(); if (language.startsWith("zh")) return true; else//from w w w . j a v a 2 s . co m return false; }
From source file:Main.java
public static int convertpxTodip(Context context, int px) { float scale = context.getResources().getDisplayMetrics().density; return (int) (px / scale + 0.5f * (px >= 0 ? 1 : -1)); }
From source file:Main.java
public static int getNavigationBarHeight(Context context) { int id = context.getResources().getIdentifier( context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android"); if (id > 0) { return context.getResources().getDimensionPixelSize(id); }/* w w w . jav a2 s . com*/ return 0; }
From source file:Main.java
public static boolean isZh(Context context) { Locale locale = context.getResources().getConfiguration().locale; String language = locale.getLanguage(); if (language.endsWith("zh")) return true; else//from w w w . j av a 2 s. co m return false; }
From source file:Main.java
public static float px2dp(Context context, int px) { float density = context.getResources().getDisplayMetrics().density; return px / density + 0.5f; }
From source file:Main.java
/** * convert hardcoded density independent pixel value into a raw pixel value * @param dps an int specifying number of dps * @param context the context in which to calculate the correct number of pixels * @return number of pixels for the specified dps value *///from ww w . j a v a 2 s . c o m public static int dpToPixels(int dps, Context context) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dps * scale + 0.5f); }
From source file:Main.java
public static String getString(Context context, final int mStringId) { return context.getResources().getString(mStringId); }
From source file:Main.java
public static int convertDp(Context context, int pixels) { float scale = context.getResources().getDisplayMetrics().density; return (int) (pixels * scale + 0.5f); }