package com.swago.baseswago.util

import android.content.res.Resources

/**
 *@date 2021/8/15 12:12
 *description:
 */
object DpPxUtil {
    /**
     * 描述：dip转换为px
     */
    fun dip2px(dipValue: Float): Int {
        val scale =
            Resources.getSystem().displayMetrics.density
        return (dipValue * scale + 0.5f).toInt()
    }

    /**
     * 描述：px转换为dip
     */
    fun px2dip(pxValue: Float): Int {
        val scale =
            Resources.getSystem().displayMetrics.density
        return (pxValue / scale + 0.5f).toInt()
    }

    fun getScreenWidth():Int{
        val display = Resources.getSystem().displayMetrics
        return display?.widthPixels ?: 0
    }

    fun getScreenHeight():Int{
        val display = Resources.getSystem().displayMetrics
        return display?.heightPixels ?: 0
    }
}