List of usage examples for android.content Context getResources
public abstract Resources getResources();
From source file:Main.java
public static Point getScreenWH(Context context) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return new Point(metrics.widthPixels, metrics.heightPixels); }
From source file:Main.java
public static int getNavigationBarHeight(Context context) { Resources resources = context.getResources(); int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int height = resources.getDimensionPixelSize(resourceId); return height; }
From source file:Main.java
public static int dip2px(Context context, float dipValue) { float scale = context.getResources().getDisplayMetrics().density; return (int) (scale * dipValue + 0.5f); }
From source file:Main.java
public static float convertDpToPixel(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return px;//from ww w .j av a 2s. c o m }
From source file:Main.java
public static String quantity(Context context, int resId, int quantity) { return context.getResources().getQuantityString(resId, quantity, quantity); }
From source file:Main.java
public static int spToPixels(Context context, int sp) { float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity; return (int) (sp * scaledDensity); }
From source file:Main.java
public static float getRawSize(int unit, float size, Context context) { Resources r;/*w w w . jav a 2 s. c o m*/ r = context.getResources(); return TypedValue.applyDimension(unit, size, r.getDisplayMetrics()); }
From source file:Main.java
public static int getResId(Context paramContext, String paramString) { return paramContext.getResources().getIdentifier(paramString, "id", paramContext.getPackageName()); }
From source file:Main.java
public static int dpToPx(Context context, float dp) { final float scale = context.getResources().getDisplayMetrics().density; return Math.round(dp * scale); }
From source file:Main.java
public static int px2dp(Context context, float pxValue) { float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); }