Back to project page Pimp_my_Z1.
The source code is released under:
GNU General Public License
If you think the Android project Pimp_my_Z1 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.fima.cardsui; // w w w . ja v a2 s .c o m import android.content.Context; import android.util.DisplayMetrics; public class Utils { /** * This method converts device specific pixels to device independent pixels. * * @param px * A value in px (pixels) unit. Which we need to convert into db * @param context * Context to get resources and device specific display metrics * @return A float value to represent db equivalent to px value */ public float convertPixelsToDp(Context ctx, float px) { DisplayMetrics metrics = ctx.getResources().getDisplayMetrics(); float dp = px / (metrics.densityDpi / 160f); return dp; } public static int convertDpToPixelInt(Context context, float dp) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); int px = (int) (dp * (metrics.densityDpi / 160f)); return px; } public static float convertDpToPixel(Context context, float dp) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); float px = (float) (dp * (metrics.densityDpi / 160f)); return px; } }