package com.amalgam.view;

import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public final class ViewUtils {
    private ViewUtils() {}

    /**
     * Convert the dips to pixels, based on density scale
     *
     * @param resources application resources
     * @param dip to be converted value
     * @return converted value(px)
     */
    public static int dipToPixel(Resources resources, int dip) {
        final float scale = resources.getDisplayMetrics().density;
        // add 0.5f to round the figure up to the nearest whole number
        return (int) (dip * scale + 0.5f);
    }

    /**
     * Convert the pixels to dips, based on density scale
     * @param windowManager the window manager of the display to use the scale density of
     * @param pixel
     * @return converted value(dip)
     */
    public static float pixelToDip(WindowManager windowManager, int pixel) {
        float dip = 0;
        DisplayMetrics metrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(metrics);
        dip = metrics.scaledDensity * pixel;
        return dip;
    }
}
@@ -47,21 +47,101 @@
 ent.
-res.Resources
+Context;%0Aimport android.content.res.Resources;%0Aimport android.hardware.display.DisplayManager
 ;%0Aim
@@ -210,16 +210,58 @@
 nager;%0A%0A
+import com.amalgam.content.ContextUtils;%0A%0A
 public f
@@ -311,16 +311,140 @@
 s() %7B%7D%0A%0A
+    public static int dipToPixel(Context context, int dip) %7B%0A        return dipToPixel(context.getResources(), dip);%0A    %7D%0A%0A
     /**%0A
@@ -882,32 +882,178 @@
 + 0.5f);%0A    %7D%0A%0A
+    public static float pixelToDip(Context context, int pixel) %7B%0A        return pixelToDip(ContextUtils.getWindowManager(context), pixel);%0A    %7D%0A%0A
     /**%0A     * C
@@ -1337,31 +1337,8 @@
 ) %7B%0A
-        float dip = 0;%0A
     
@@ -1463,63 +1463,648 @@
     
-dip = metrics.scaledDensity * pixel;%0A        return dip
+return metrics.scaledDensity * pixel;%0A    %7D%0A%0A    public static float sipToPixel(Context context, float sip) %7B%0A        return sipToPixel(context.getResources(), sip);%0A    %7D%0A%0A    public static float sipToPixel(Resources resources, float sip) %7B%0A        float density = resources.getDisplayMetrics().scaledDensity;%0A        return sip * density;%0A    %7D%0A%0A    public static float pixelToSip(Context context, float pixels) %7B%0A        DisplayMetrics metrics = new DisplayMetrics();%0A        float scaledDensity = metrics.scaledDensity;%0A        if (pixels == 0 %7C%7C scaledDensity == 0) %7B%0A            return 1;%0A        %7D%0A        return pixels/scaledDensity
 ;%0A  

Add sip to pixel conversion