Create static helper methods for pixel-to-DP conversion
This commit is contained in:
parent
d677f9ce16
commit
85ef16a75a
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue