package com.sunzee.utils;


import com.sunzee.base.BaseApplication;

/**
 * 单位准换
 */
public class DensityUtil {

    public static float dp2px(float dpValue) {
        float density = BaseApplication.getContext().getResources().getDisplayMetrics().density;
        return density * dpValue + 0.5f;
    }

    public static float px2dp(float pxValue) {
        float density = BaseApplication.getContext().getResources().getDisplayMetrics().density;
        return pxValue / density + 0.5f;
    }

    public static int px2sp(float pxValue) {
        float scaledDensity = BaseApplication.getContext().getResources().getDisplayMetrics().scaledDensity;
        return (int) (pxValue / scaledDensity + 0.5f);
    }

    public static int sp2px(float spValue) {
        float scaledDensity = BaseApplication.getContext().getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * scaledDensity + 0.5f);
    }

    public static int getScreenWidth() {
        return BaseApplication.getContext().getResources().getDisplayMetrics().widthPixels;
    }

    public static int getScreenHeight() {
        return BaseApplication.getContext().getResources().getDisplayMetrics().heightPixels;
    }

    public static int getStatusBarHeight() {
        int statusBarHeight = 0;
        int resourceId = BaseApplication.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            statusBarHeight = BaseApplication.getContext().getResources().getDimensionPixelSize(resourceId);
        }
        return statusBarHeight;
    }
}
