package com.example.base.utils

import android.content.Context
import android.graphics.Point
import android.provider.Settings
import android.view.WindowManager


object ScreenUtils {
    fun getScreenHeight(): Int {
        val wm = Utils.getApp().getSystemService(Context.WINDOW_SERVICE) as WindowManager?
            ?: return -1
        val point = Point()
        wm.defaultDisplay.getRealSize(point)
        return point.y
    }


    fun getScreenWidth(): Int {
        val wm =
            Utils.getApp().getSystemService(Context.WINDOW_SERVICE) as WindowManager? ?: return -1
        val point = Point()
        wm.defaultDisplay.getRealSize(point)
        return point.x
    }

    /**
     * 获取真实窗口大小
     */
    fun getWindowSize(): Point {
        val point = Point()
        val displayMetrics = Utils.getApp().resources.displayMetrics
        point.x = displayMetrics.widthPixels
        point.y = displayMetrics.heightPixels
        return point
    }

    /**
     * 判断是否开启了 “屏幕自动旋转”
     */
    fun isScreenAutoRotate(): Boolean {
        var gravity = 0
        try {
            gravity = Settings.System.getInt(Utils.getApp().contentResolver, Settings.System.ACCELEROMETER_ROTATION)
        } catch (e: Settings.SettingNotFoundException) {
            e.printStackTrace()
        }
        return gravity == 1
    }
}