/*
 * DimensionUtils.java
 *
 * Author: Ming Tsang
 * Copyright (c) 2015 Ming Tsang
 * Refer to LICENSE for details
 */

package com.nkming.utils.unit;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.TypedValue;

public class DimensionUtils
{
	public static float dpToPx(Context context, float dp)
	{
		DisplayMetrics dm = context.getResources().getDisplayMetrics();
		return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, dm);
	}

	public static float spToPx(Context context, float sp)
	{
		DisplayMetrics dm = context.getResources().getDisplayMetrics();
		return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, dm);
	}
}

@@ -676,11 +676,210 @@
  dm);%0A%09%7D
+%0A%0A%09public static float pxToDp(Context context, float px)%0A%09%7B%0A%09%09DisplayMetrics dm = context.getResources().getDisplayMetrics();%0A%09%09return px * (DisplayMetrics.DENSITY_DEFAULT / (float)dm.densityDpi);%0A%09%7D
 %0A%7D%0A

Translate px to dp