package net.micode.notes.utils;

import android.content.res.Resources;
import android.graphics.Rect;
import android.view.View;


public class ScreenUtils {
    private static float mDensity = -1.0F;

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

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

    public static float getDensity() {
        if (mDensity == -1.0F) {
            return ContextUtils.getContext().getResources().getDisplayMetrics().density;
        }
        return mDensity;
    }

    public static int dip2px(float dp) {
        if (mDensity == -1.0F) {
            mDensity = ContextUtils.getContext().getResources().getDisplayMetrics().density;
        }
        return (int) (dp * mDensity + 0.5f);
    }

    public static Rect getMeasuredSize(View view) {
        Rect rect = new Rect();
        if (view != null) {
            int width = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
            int height = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
            view.measure(width, height);
            rect.set(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
        }
        return rect;
    }


}
