管灌系统巡查员智能手机App
zuoxiao
2025-02-11 dde9027478b772dd60371937413ac2838c4f3bbd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package cc.shinichi.library.tool.common
 
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.Resources
import android.util.DisplayMetrics
import android.view.Display
import android.view.WindowManager
 
 
/**
 * @author 工藤
 * @email qinglingou@gmail.com
 * cc.shinichi.drawlongpicturedemo.util
 * create at 2018/8/27  17:53
 * description:
 */
object PhoneUtil {
 
    private val TAG = PhoneUtil::class.java.simpleName
 
    fun getPhoneWid(context: Context): Int {
        val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val display: Display = wm.defaultDisplay
        var screenWidth = 0
        val dm = DisplayMetrics()
        display.getRealMetrics(dm)
        screenWidth = dm.widthPixels
        return screenWidth.apply {
            SLog.d(TAG, "getPhoneWid: $this")
        }
    }
 
    fun getPhoneHei(context: Context): Int {
        val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val display = wm.defaultDisplay
        var screenHeight = 0
 
        val dm = DisplayMetrics()
        display.getRealMetrics(dm)
        screenHeight = dm.heightPixels
        return screenHeight.apply {
            SLog.d(TAG, "getPhoneHei: $this")
        }
    }
 
    fun getPhoneRatio(context: Context): Float {
        return (getPhoneHei(context).toFloat() / getPhoneWid(context).toFloat()).apply {
            SLog.d(TAG, "getPhoneRatio: $this")
        }
    }
 
    @SuppressLint("InternalInsetResource")
    fun getNavBarHeight(context: Context): Int {
        val resources: Resources = context.resources
        val resourceId: Int = resources.getIdentifier("navigation_bar_height", "dimen", "android")
        return resources.getDimensionPixelSize(resourceId)
    }
 
    @SuppressLint("InternalInsetResource")
    fun getStatusBarHeight(context: Context): Int {
        val resources: Resources = context.resources
        val resourceId: Int = resources.getIdentifier("status_bar_height", "dimen", "android")
        return resources.getDimensionPixelSize(resourceId)
    }
}