-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathActivityEdgeToEdgeUtils.kt
More file actions
55 lines (49 loc) · 1.73 KB
/
ActivityEdgeToEdgeUtils.kt
File metadata and controls
55 lines (49 loc) · 1.73 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
package eu.opencloud.android.ui.activity
import android.graphics.Color
import android.util.TypedValue
import android.view.View
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.annotation.Px
import androidx.core.graphics.Insets
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.fragment.app.FragmentActivity
fun FragmentActivity.enableEdgeToEdgePreSetContentView(
isNavigationBackgroundPrimary: Boolean
) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.dark(Color.TRANSPARENT),
navigationBarStyle =
if (isNavigationBackgroundPrimary)
SystemBarStyle.dark(Color.TRANSPARENT)
else SystemBarStyle.light(
Color.TRANSPARENT,
Color.TRANSPARENT
)
)
}
fun FragmentActivity.enableEdgeToEdgePostSetContentView(onInsets: (Insets) -> Unit) {
ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content)) { _, windowInsets ->
val insets = windowInsets.getInsets(
WindowInsetsCompat.Type.systemBars() or
WindowInsetsCompat.Type.displayCutout(),
)
onInsets(insets)
WindowInsetsCompat.CONSUMED
}
}
fun FragmentActivity.getActionBarSize(): Int {
val tv = TypedValue()
if (theme.resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
return TypedValue.complexToDimensionPixelSize(tv.data, resources.displayMetrics)
}
return 0
}
fun View.updatePaddingTop(@Px paddingTop: Int) {
updatePadding(top = paddingTop)
}
fun View.updatePaddingBottom(@Px paddingBottom: Int) {
updatePadding(bottom = paddingBottom)
}