List of usage examples for android.content Context getResources
public abstract Resources getResources();
From source file:Main.java
/** * gets color from resource values//from ww w . j a va 2s . co m * * @param context context of calling activity * @param colorId resource id * @return color id */ public static int getColorResource(Context context, int colorId) { return context.getResources().getColor(colorId); }
From source file:Main.java
public static int dpToPx(Context context, int dp) { return (int) ((dp * context.getResources().getDisplayMetrics().density) + 0.5); }
From source file:Main.java
public static final int getInt(final Context context, final int resId) { return context.getResources().getInteger(resId); }
From source file:Main.java
public static int pxTodp(int px, Context context) { DisplayMetrics met = context.getResources().getDisplayMetrics(); float pxtodp = px / (met.densityDpi / 160f); return (int) pxtodp; }
From source file:Main.java
public static String getString(Context context, int resId) { return context.getResources().getString(resId); }
From source file:Main.java
public static int pxToDp(Context context, int px) { return (int) ((px / context.getResources().getDisplayMetrics().density) + 0.5); }
From source file:Main.java
public static int getSizeInPixels(float dp, Context context) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); float pixels = metrics.density * dp; return (int) (pixels + 0.5f); }
From source file:Main.java
public static int convertSpToPixel(int sp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return Math.round(sp * metrics.scaledDensity); }
From source file:Main.java
public static int getHeightForDP(Context ctx, float dp) { final float scale = ctx.getResources().getDisplayMetrics().density; return (int) (dp * scale + 0.5f); }
From source file:Main.java
static public int getIdentifier(Context context, String name) { return context.getResources().getIdentifier(name, "id", context.getPackageName()); }