package com.ydl.media.music.utils

import android.annotation.SuppressLint
import android.content.Context
import android.view.WindowManager

/**
 * Created by haorui on 2019-10-27 .
 * Des:
 */
@SuppressLint("StaticFieldLeak")
object ScreenUtils {
    fun getScreenWidth(context: Context): Int{
        val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        return wm.defaultDisplay.width
    }

    /**
     * 获取状态栏高度
     */
    fun getStatusBarHeight(context:Context): Int{
            var result = 0
            val resourceId =
                context!!.resources.getIdentifier("status_bar_height", "dimen", "android")
            if (resourceId > 0) {
                result = context!!.resources.getDimensionPixelSize(resourceId)
            }
            return result
        }


    fun dp2px(context: Context,dpValue: Float): Int {
        val scale = context!!.resources.displayMetrics.density
        return (dpValue * scale + 0.5f).toInt()
    }

    fun px2dp(context: Context,pxValue: Float): Int {
        val scale = context!!.resources.displayMetrics.density
        return (pxValue / scale + 0.5f).toInt()
    }

    fun sp2px(context: Context,spValue: Float): Int {
        val fontScale = context!!.resources.displayMetrics.scaledDensity
        return (spValue * fontScale + 0.5f).toInt()
    }
}
