List of usage examples for android.content Context getResources
public abstract Resources getResources();
From source file:Main.java
public static int getRawDisplayHeight(Context context) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return metrics.heightPixels; }
From source file:Main.java
public static int px2dip(Context context, float pxValue) { float m = context.getResources().getDisplayMetrics().density; return (int) (pxValue / m + 0.5f); }
From source file:Main.java
public static int dpToPx(Context context, int dp) { Resources r = context.getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); return (int) px; }
From source file:Main.java
public static float convertDpToPixel(float dp, Context context) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return dp * (metrics.densityDpi / 160f); }
From source file:Main.java
public static int getPixelsFromDp(Context c, int dp) { final float scale = c.getResources().getDisplayMetrics().density; int pixels = (int) (dp * scale + 0.5f); return pixels; }
From source file:Main.java
public static int getColorAsInt(Context context, int colorId) { return context.getResources().getColor(colorId); }
From source file:Main.java
public static int getScreenWidth(Context context) { DisplayMetrics dm = context.getResources().getDisplayMetrics(); int width = dm.widthPixels; return width; }
From source file:Main.java
public static int convertDpToPixel(Context context, int dp) { Resources r = context.getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); return Math.round(px); }
From source file:Main.java
public static float convertPixelsToDp(float px, Context context) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return px / (metrics.densityDpi / 160f); }
From source file:Main.java
public static int getScreenWidth(Context context) { DisplayMetrics dm = context.getResources().getDisplayMetrics(); return dm.widthPixels; }