9:17 AM
0

public class Dimensions {
    /**
     * The FIRST_DIMENTION_NUMBER.
     */
    public static final int FIRST_DIMENTION_NUMBER = 160;
    /**
     * The SECOND_DIMENTION_NUMBER.
     */
    public static final int SECOND_DIMENTION_NUMBER = 213;

    /**
     * displayMetrics.
     */
    private static DisplayMetrics displayMetrics;

    /**
     * Convert PX to DP.
     * @param d
     *            number of PX.
     * @param context
     *            application context.
     * @return number of DP
     */
    public static int convertDptoPx(final double d, final Context context) {
        if (displayMetrics == null) {
            displayMetrics = context.getResources().getDisplayMetrics();
        }
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            (float) ((d * FIRST_DIMENTION_NUMBER) / SECOND_DIMENTION_NUMBER), displayMetrics);
    }

 

0 comments:

Post a Comment