List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:Main.java
public static int convertDIP2PX(Context context, float dip) { Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; resources = null;/*ww w .j av a 2 s . c o m*/ return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1)); }
From source file:Main.java
public static int convertPX2DIP(Context context, float px) { Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; resources = null;/*w w w .j a va2s. com*/ return (int) (px / scale + 0.5f * (px >= 0 ? 1 : -1)); }
From source file:Main.java
public static float sp2px(Resources resources, float sp) { final float scale = resources.getDisplayMetrics().scaledDensity; return sp * scale; }
From source file:Main.java
public static float dp2px(Resources resources, float dp) { final float scale = resources.getDisplayMetrics().density; return dp * scale + 0.5f; }
From source file:Main.java
public static float dpToPx(Resources resources, float dp) { final float scale = resources.getDisplayMetrics().density; return dp * scale + 0.5f; }
From source file:Main.java
public static int animateContainerExtraTopOffset(Resources resources) { float density = resources.getDisplayMetrics().density; if (density >= 4.0) { return 0; }/*from www. j a va 2 s.co m*/ if (density >= 3.0) { return 0; } if (density >= 2.0) { return 1; } if (density >= 1.5) { return 2; } if (density >= 1.0) { return 2; } return 0; }
From source file:Main.java
public static float spToPx(Resources resources, float sp) { final float scale = resources.getDisplayMetrics().scaledDensity; return sp * scale; }
From source file:Main.java
public static int animateContainerExtraSideOffset(Resources resources) { float density = resources.getDisplayMetrics().density; if (density >= 4.0) { return 2; }//from w w w . j av a 2s . co m if (density >= 3.0) { return 2; } if (density >= 2.0) { return 2; } if (density >= 1.5) { return 2; } if (density >= 1.0) { return 0; } return 0; }
From source file:Main.java
public static DisplayMetrics getScreenPixels(Context context) { Resources resources = context.getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); return dm;//from ww w . j a v a2s. c o m }
From source file:Main.java
public static float convertDensityToPixel(Context context, float densityPixel) { Resources resources = context.getResources(); return densityPixel * (resources.getDisplayMetrics().densityDpi / 160f); }