package com.base.browserwhite.utils

import android.content.Context
import android.content.Intent
import android.util.DisplayMetrics
import android.util.TypedValue
import android.view.WindowManager


object Utils{

    // 扩展函数：dp 转 px
    fun Context.dpToPx(dp: Float): Float {
        val metrics = resources.displayMetrics
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics)
    }

    fun getScreenWidth(context: Context): Int {
        val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val display = windowManager.defaultDisplay
        val metrics = DisplayMetrics()
        display.getMetrics(metrics)
        return metrics.widthPixels
    }
//    private fun getIgnoreBatteryPermissionIntent( context: Context): Intent {
//        var intent = Intent("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS")
//        intent.setData(PermissionUtils.getPackageNameUri(context))
//        if (!PermissionUtils.areActivityIntent(context, intent)) {
//            intent = Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS")
//        }
//        return if (!PermissionUtils.areActivityIntent(
//                context,
//                intent
//            )
//        ) PermissionIntentManager.getApplicationDetailsIntent(context) else intent
//    }
}
