From 46e7d201d0b9d58aebda9532869ba719d3c3ae02 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 22 Sep 2019 15:15:06 -0700 Subject: Automatically update flags for status and nav colors --- .../kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 35 +++++++++++++++++++--- 1 file 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) { +fun Context.setMenuIcons( + menu: Menu, @ColorInt color: Int = Color.WHITE, + vararg iicons: Pair +) { iicons.forEach { (id, iicon) -> menu.findItem(id).icon = iicon.toDrawable(this, sizeDp = 18, color = color) } -- cgit v1.2.3 From 5dce2fc098908d5ee2842e07e13390a756e27a26 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 22 Sep 2019 21:11:16 -0700 Subject: Add back dependency by tag --- buildSrc/src/main/kotlin/kau/Dependencies.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/kau/Dependencies.kt b/buildSrc/src/main/kotlin/kau/Dependencies.kt index b2cdf48..bf9b6be 100644 --- a/buildSrc/src/main/kotlin/kau/Dependencies.kt +++ b/buildSrc/src/main/kotlin/kau/Dependencies.kt @@ -7,7 +7,8 @@ object Dependencies { @JvmStatic fun kau(version: String) = "ca.allanwang:kau:$version" - private fun kau(type: String, version: String) = "ca.allanwang.kau:$type:$version" + @JvmStatic + fun kau(type: String, version: String) = "ca.allanwang.kau:$type:$version" @JvmStatic fun kauAbout(version: String) = kau("about", version) -- cgit v1.2.3 From 788cec5455721894acd55ef6225d4ab4641e9e24 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 22 Sep 2019 22:35:34 -0700 Subject: Use and with inverse --- core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 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 20abe8a..206626e 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -126,7 +126,7 @@ inline var Activity.navigationBarColor: Int } var prevSystemUiVisibility = window.decorView.systemUiVisibility prevSystemUiVisibility = if (value.isColorDark) { - prevSystemUiVisibility xor View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + prevSystemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv() } else { prevSystemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR } @@ -147,7 +147,7 @@ inline var Activity.statusBarColor: Int } var prevSystemUiVisibility = window.decorView.systemUiVisibility prevSystemUiVisibility = if (value.isColorDark) { - prevSystemUiVisibility xor View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR + prevSystemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() } else { prevSystemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR } -- cgit v1.2.3 From dba4c72e90946dda0917a43b9be99d21695e6bdf Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 22 Sep 2019 22:51:05 -0700 Subject: Lower constraint for status bar light switch --- .../ca/allanwang/kau/swipe/SwipeBackLayout.kt | 1 - .../kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 30 +++++----------------- docs/Changelog.md | 2 ++ sample/src/main/res/xml/kau_changelog.xml | 7 ++--- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt index bf6d09d..b2d9a5f 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt @@ -248,7 +248,6 @@ internal class SwipeBackLayout @JvmOverloads constructor( dragHelper.shouldInterceptTouchEvent(event) } catch (e: Exception) { false - } } 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 206626e..2142047 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -17,7 +17,6 @@ package ca.allanwang.kau.utils -import android.annotation.SuppressLint import android.app.Activity import android.app.AlarmManager import android.app.PendingIntent @@ -35,6 +34,7 @@ import androidx.annotation.StringRes import ca.allanwang.kau.R import com.google.android.material.snackbar.Snackbar import com.mikepenz.iconics.typeface.IIcon +import kotlin.system.exitProcess /** * Created by Allan Wang on 2017-06-21. @@ -104,7 +104,7 @@ inline fun Activity.restartApplication() { else alarm.setExact(AlarmManager.RTC, System.currentTimeMillis() + 100, pending) finish() - System.exit(0) + exitProcess(0) } fun Activity.finishSlideOut() { @@ -113,9 +113,7 @@ fun Activity.finishSlideOut() { } inline var Activity.navigationBarColor: Int - @SuppressLint("NewApi") - get() = if (buildIsLollipopAndUp) window.navigationBarColor else Color.BLACK - @SuppressLint("NewApi") + get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) window.navigationBarColor else Color.BLACK set(value) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return @@ -134,15 +132,13 @@ inline var Activity.navigationBarColor: Int } inline var Activity.statusBarColor: Int - @SuppressLint("NewApi") - get() = if (buildIsLollipopAndUp) window.statusBarColor else Color.BLACK - @SuppressLint("NewApi") + get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) window.statusBarColor else Color.BLACK set(value) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return } window.statusBarColor = value - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return } var prevSystemUiVisibility = window.decorView.systemUiVisibility @@ -154,26 +150,14 @@ inline var Activity.statusBarColor: Int window.decorView.systemUiVisibility = prevSystemUiVisibility } -inline var Activity.statusBarLight: Boolean - @SuppressLint("InlinedApi") - get() = if (buildIsMarshmallowAndUp) window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR > 0 else false - @SuppressLint("InlinedApi") - set(value) { - if (buildIsMarshmallowAndUp) { - val flags = window.decorView.systemUiVisibility - window.decorView.systemUiVisibility = - if (value) flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - else flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() - } - } - /** * Themes the base menu icons and adds iicons programmatically based on ids * * Call in [Activity.onCreateOptionsMenu] */ fun Context.setMenuIcons( - menu: Menu, @ColorInt color: Int = Color.WHITE, + menu: Menu, + @ColorInt color: Int = Color.WHITE, vararg iicons: Pair ) { iicons.forEach { (id, iicon) -> diff --git a/docs/Changelog.md b/docs/Changelog.md index 0078430..073f3a5 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -2,6 +2,8 @@ ## v5.2.0 * :fastadapter: Migrate fastadapter to v4.x.x +* :core: Automatically switch light mode for navigationBarColor and statusBarColor +* :core: Remove statusBarLight toggle ## v5.1.0 * :adapter: Moved fastadapter elements to new module, :fastadapter:. To migrate, simply rename the dependency. If you don't use fast adapter, no changes are necessary diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index 7baecd8..3531e69 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -8,6 +8,10 @@ + + + + @@ -15,9 +19,6 @@ - - - -- cgit v1.2.3