package com.yxkang.android.util;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

/**
 * Created by fine on 2015/6/17.
 */
public class ScreenUtil {

    /**
     * get the screen width
     *
     * @param context context
     * @return screen width
     */
    public static int getScreenWidth(Context context) {
        WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        return display.getWidth();
    }

    /**
     * get the screen height
     *
     * @param context context
     * @return screen height
     */
    public static int getScreenHeight(Context context) {
        WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        return display.getHeight();
    }

    /**
     * get the screen width and height
     *
     * @param activity activity
     * @return width and height
     */
    public static int[] getScreenWH(Activity activity) {
        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        return new int[]{dm.widthPixels, dm.heightPixels};
    }
}

@@ -1385,10 +1385,1526 @@
 ;%0A    %7D%0A
+%0A%0A    /**%0A     * transform the dip to px, according to the phone density%0A     *%0A     * @param context context%0A     * @param dpValue dp value%0A     * @return px value%0A     */%0A    public static int dip2px(Context context, float dpValue) %7B%0A        final float scale = context.getResources().getDisplayMetrics().density;%0A        return (int) (dpValue * scale + 0.5f);%0A    %7D%0A%0A    /**%0A     * transform the px to dip, according to the phone density%0A     *%0A     * @param context context%0A     * @param pxValue px value%0A     * @return dip value%0A     */%0A    public static int px2dip(Context context, float pxValue) %7B%0A        final float scale = context.getResources().getDisplayMetrics().density;%0A        return (int) (pxValue / scale + 0.5f);%0A    %7D%0A%0A%0A    /**%0A     * transform the px to sp, according to the phone scaledDensity%0A     *%0A     * @param context context%0A     * @param pxValue the px value%0A     * @return sp value%0A     */%0A    public static int px2sp(Context context, float pxValue) %7B%0A        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;%0A        return (int) (pxValue / fontScale + 0.5f);%0A    %7D%0A%0A%0A    /**%0A     * transform the sp to px, according to the phone scaledDensity%0A     *%0A     * @param context context%0A     * @param spValue ap value%0A     * @return px value%0A     */%0A    public static int sp2px(Context context, float spValue) %7B%0A        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;%0A        return (int) (spValue * fontScale + 0.5f);%0A    %7D%0A
 %7D%0A

update ScreenUtil