aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-09-22 15:15:06 -0700
committerAllan Wang <me@allanwang.ca>2019-09-22 15:15:06 -0700
commit46e7d201d0b9d58aebda9532869ba719d3c3ae02 (patch)
tree658452d1237b7d870c63b1552ce1537a2898aa7c /core/src/main/kotlin
parentbfba246d84aa6a22bc02837f9fcbd97780867d10 (diff)
downloadkau-46e7d201d0b9d58aebda9532869ba719d3c3ae02.tar.gz
kau-46e7d201d0b9d58aebda9532869ba719d3c3ae02.tar.bz2
kau-46e7d201d0b9d58aebda9532869ba719d3c3ae02.zip
Automatically update flags for status and nav colors
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt35
1 files changed, 31 insertions, 4 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
index 279bcd3..20abe8a 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
@@ -117,7 +117,20 @@ inline var Activity.navigationBarColor: Int
get() = if (buildIsLollipopAndUp) window.navigationBarColor else Color.BLACK
@SuppressLint("NewApi")
set(value) {
- if (buildIsLollipopAndUp) window.navigationBarColor = value
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ return
+ }
+ window.navigationBarColor = value
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
+ return
+ }
+ var prevSystemUiVisibility = window.decorView.systemUiVisibility
+ prevSystemUiVisibility = if (value.isColorDark) {
+ prevSystemUiVisibility xor View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
+ } else {
+ prevSystemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
+ }
+ window.decorView.systemUiVisibility = prevSystemUiVisibility
}
inline var Activity.statusBarColor: Int
@@ -125,9 +138,20 @@ inline var Activity.statusBarColor: Int
get() = if (buildIsLollipopAndUp) window.statusBarColor else Color.BLACK
@SuppressLint("NewApi")
set(value) {
- if (buildIsLollipopAndUp) {
- window.statusBarColor = value
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ return
}
+ window.statusBarColor = value
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
+ return
+ }
+ var prevSystemUiVisibility = window.decorView.systemUiVisibility
+ prevSystemUiVisibility = if (value.isColorDark) {
+ prevSystemUiVisibility xor View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
+ } else {
+ prevSystemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
+ }
+ window.decorView.systemUiVisibility = prevSystemUiVisibility
}
inline var Activity.statusBarLight: Boolean
@@ -148,7 +172,10 @@ inline var Activity.statusBarLight: Boolean
*
* Call in [Activity.onCreateOptionsMenu]
*/
-fun Context.setMenuIcons(menu: Menu, @ColorInt color: Int = Color.WHITE, vararg iicons: Pair<Int, IIcon>) {
+fun Context.setMenuIcons(
+ menu: Menu, @ColorInt color: Int = Color.WHITE,
+ vararg iicons: Pair<Int, IIcon>
+) {
iicons.forEach { (id, iicon) ->
menu.findItem(id).icon = iicon.toDrawable(this, sizeDp = 18, color = color)
}