List of usage examples for android.util TypedValue applyDimension
public static float applyDimension(int unit, float value, DisplayMetrics metrics)
From source file:Main.java
private static float convertUnitToPixel(Context context, int unit, float in) { return TypedValue.applyDimension(unit, in, context.getResources().getDisplayMetrics()); }
From source file:Main.java
/** * Convert a dp float value to pixels//from w w w . ja va2s. com * * @param dp float value in dps to convert * @return DP value converted to pixels */ static int dp2px(Context context, float dp) { float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); return Math.round(px); }
From source file:Main.java
/** * Function to convert the given size in dp. * @param mContext context of the activity. * @param iValue value the needed to be changed. * @return value in dp// w w w. ja v a 2 s .c om */ public static int getSizeInDp(Context mContext, int iValue) { return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, iValue, mContext.getResources().getDisplayMetrics())); }
From source file:Main.java
/** * /*from ww w . j a v a 2 s. c o m*/ * @param context * @param dip * @return */ public static float dipToPixels(Context context, int dip) { Resources r = context.getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics()); return px; }
From source file:Main.java
public static int dp2px(Context context, float dpVal) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal, context.getResources().getDisplayMetrics()); }
From source file:Main.java
/** * Converts density pixels to pixels/*from ww w. j ava 2 s. co m*/ * * @param context context for getResources() * @param dp desired density pixels * @return converted dp to pixels */ static float dpToPx(Context context, final int dp) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); }
From source file:Main.java
/** * Converts a value from device independent pixels (dp) to pixels. * @param context context.//from www . jav a 2s .c om * @param dpValue the value to convert. * @return the given value converted to pixels. */ public static float toPixels(Context context, float dpValue) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, context.getResources().getDisplayMetrics()); }
From source file:Main.java
public static float dp2pixel(Context context, int dp) { Resources r = context.getResources(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }
From source file:Main.java
/** * Converts scale pixels to pixels -- used for setting text sizes * * @param context context for getResources() * @param sp desired scale pixels pixels * @return converted sp to pixels/*ww w . j a v a 2 s . co m*/ */ static int spToPx(Context context, final float sp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics()); }
From source file:Main.java
/** * Converts density pixels into pixels./*ww w .j a v a 2 s. c om*/ * * @param context the application context. * @param densityPixels the amount of DPs to convert. * @return the amount in pixels. */ public static int getPixels(Context context, int densityPixels) { return (int) Math.ceil(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, densityPixels, context.getResources().getDisplayMetrics())); }