25
25
package com.jmstudios.redmoon
26
26
27
27
import android.content.Context
28
+ import android.content.res.Resources
28
29
import android.graphics.Canvas
30
+ import android.graphics.PixelFormat
31
+ import android.os.Build
29
32
import android.view.View
33
+ import android.view.WindowInsets
30
34
import android.view.WindowManager
31
35
32
36
import com.jmstudios.redmoon.helper.Logger
33
37
import com.jmstudios.redmoon.manager.BrightnessManager
34
- import com.jmstudios.redmoon.manager.ScreenManager
35
38
import com.jmstudios.redmoon.receiver.OrientationChangeReceiver
36
39
37
40
import kotlin.properties.Delegates
@@ -42,7 +45,6 @@ class Overlay(context: Context) : View(context), Filter,
42
45
OrientationChangeReceiver .OnOrientationChangeListener {
43
46
44
47
private val mWindowManager = context.getSystemService(Context .WINDOW_SERVICE ) as WindowManager
45
- private val mScreenManager = ScreenManager (context, mWindowManager)
46
48
private val mOrientationReceiver = OrientationChangeReceiver (context, this )
47
49
private val mBrightnessManager = BrightnessManager (context)
48
50
@@ -71,7 +73,6 @@ class Overlay(context: Context) : View(context), Filter,
71
73
}
72
74
73
75
private fun show () {
74
- updateLayoutParams()
75
76
mWindowManager.addView(this , mLayoutParams)
76
77
mBrightnessManager.brightnessLowered = profile.lowerBrightness
77
78
mOrientationReceiver.register()
@@ -93,26 +94,47 @@ class Overlay(context: Context) : View(context), Filter,
93
94
mBrightnessManager.brightnessLowered = profile.lowerBrightness
94
95
}
95
96
96
- private var mLayoutParams = mScreenManager.layoutParams
97
- get() = field.apply {
98
- buttonBrightness = Config .buttonBacklightLevel
99
- type = if (atLeastAPI(26 )) {
100
- WindowManager .LayoutParams .TYPE_APPLICATION_OVERLAY
101
- } else {
102
- WindowManager .LayoutParams .TYPE_SYSTEM_OVERLAY
103
- }
97
+ val mLayoutParams = WindowManager .LayoutParams ().apply {
98
+ buttonBrightness = Config .buttonBacklightLevel
99
+ // TODO: why is cutout always null?
100
+ // if(atLeastAPI(Build.VERSION_CODES.P)) {
101
+ // val cutout = WindowInsets.Builder().build().displayCutout
102
+ // val top = cutout?.boundingRectTop?.height() ?: 0
103
+ // val bottom = cutout?.boundingRectBottom?.height() ?: 0
104
+ // val left = cutout?.boundingRectLeft?.width() ?: 0
105
+ // val right = cutout?.boundingRectRight?.width() ?: 0
106
+ // height = Resources.getSystem().displayMetrics.heightPixels + top + bottom
107
+ // width = Resources.getSystem().displayMetrics.widthPixels + left + right
108
+ // x = -left
109
+ // y = -top
110
+ // } else {
111
+ height = Resources .getSystem().displayMetrics.heightPixels + 4000
112
+ width = Resources .getSystem().displayMetrics.widthPixels + 4000
113
+ x = - 1000
114
+ y = - 1000
115
+ // }
116
+ format = PixelFormat .TRANSLUCENT
117
+ type = if (isAccessibilityServiceOn(context) && atLeastAPI(Build .VERSION_CODES .M )) {
118
+ WindowManager .LayoutParams .TYPE_ACCESSIBILITY_OVERLAY
119
+ } else if (atLeastAPI(Build .VERSION_CODES .O )) {
120
+ WindowManager .LayoutParams .TYPE_APPLICATION_OVERLAY
121
+ } else {
122
+ WindowManager .LayoutParams .TYPE_SYSTEM_OVERLAY
123
+ }
124
+ flags = WindowManager .LayoutParams .FLAG_NOT_TOUCHABLE
125
+ .or (WindowManager .LayoutParams .FLAG_NOT_FOCUSABLE )
126
+ .or (WindowManager .LayoutParams .FLAG_LAYOUT_NO_LIMITS )
127
+ .or (WindowManager .LayoutParams .FLAG_LAYOUT_IN_SCREEN )
128
+ if (atLeastAPI(Build .VERSION_CODES .P )) {
129
+ layoutInDisplayCutoutMode = WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
104
130
}
105
-
106
- private fun updateLayoutParams () {
107
- mLayoutParams = mScreenManager.layoutParams
108
131
}
109
132
110
133
private fun reLayout () = mWindowManager.updateViewLayout(this , mLayoutParams)
111
134
112
135
override fun onDraw (canvas : Canvas ) = canvas.drawColor(profile.filterColor)
113
136
114
137
override fun onOrientationChanged () {
115
- updateLayoutParams()
116
138
reLayout()
117
139
}
118
140
0 commit comments