Create static helper methods for pixel-to-DP conversion

This commit is contained in:
sigmabeta 2016-01-14 23:58:34 -05:00
parent d677f9ce16
commit 85ef16a75a
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package org.dolphinemu.dolphinemu.utils;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
public final class Pixels
{
private Pixels()
{
}
public static float convertDpToPx(float original, Context context)
{
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
return original * metrics.density;
}
public static float convertPxToDp(float original, Context context)
{
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
return original / metrics.density;
}
}