-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathEdgeToEdge.kt
More file actions
97 lines (77 loc) · 2.28 KB
/
EdgeToEdge.kt
File metadata and controls
97 lines (77 loc) · 2.28 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.ipcamera
import android.view.View
import android.view.Window
import androidx.core.graphics.Insets
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
abstract class WindowInsetsHandler {
abstract fun onApplyWindowInsets(
root: View,
windowInsets: WindowInsetsCompat
) : WindowInsetsCompat
}
class DefaultInsetsHandler : WindowInsetsHandler() {
override fun onApplyWindowInsets(
root: View,
windowInsets: WindowInsetsCompat,
): WindowInsetsCompat {
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
root.setPadding(
0,
insets.top,
0,
insets.bottom,
)
return WindowInsetsCompat.CONSUMED
}
}
class StreamActivityInsetsHandler(
private val onApplySystemBarsInsets: (insets: Insets) -> Unit,
) : WindowInsetsHandler() {
override fun onApplyWindowInsets(
root: View,
windowInsets: WindowInsetsCompat,
): WindowInsetsCompat {
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
root.setPadding(
0,
0,
0,
0,
)
onApplySystemBarsInsets.invoke(insets)
return WindowInsetsCompat.CONSUMED
}
}
object EdgeToEdge {
fun setDecorFitsSystemWindows(
window: Window,
fitSystemWindows: Boolean
) {
WindowCompat.setDecorFitsSystemWindows(window, fitSystemWindows)
}
fun setInsetsHandler(
root: View,
handler: WindowInsetsHandler,
) {
ViewCompat.setOnApplyWindowInsetsListener(
root
) { view, insets ->
handler.onApplyWindowInsets(
root = view,
windowInsets = insets,
)
}
}
fun enableImmersiveMode(window: Window) {
val insetsController = WindowCompat.getInsetsController(
window,
window.decorView,
)
insetsController.systemBarsBehavior = WindowInsetsControllerCompat
.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
insetsController.hide(WindowInsetsCompat.Type.systemBars())
}
}