package eu.se_bastiaan.popcorntimeremote.utils; import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; import android.util.TypedValue; /** * Created by Sebastiaan on 11-06-14. */ public final class PixelUtils { private PixelUtils() throws InstantiationException { throw new InstantiationException("This class is not created for instantiation"); } public static int getPixelsFromDp(Context context, Integer dp) { Resources r = context.getResources(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); } public static int getPixelsFromSp(Context context, Integer sp) { Resources r = context.getResources(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, r.getDisplayMetrics()); } public static Drawable changeDrawableColor(Context context, Integer resId, Integer color) { Drawable drawable = context.getResources().getDrawable(resId).mutate(); drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY)); return drawable; } public static Integer getStatusBarHeight(Context context) { int statusBarHeight = 0; int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { statusBarHeight = context.getResources().getDimensionPixelSize(resourceId); } return statusBarHeight; } }