diff options
author | Allan Wang <me@allanwang.ca> | 2019-09-22 22:59:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-22 22:59:43 -0700 |
commit | 2889fae685edbad89c40e3cfe8a9b16f0b87ebcc (patch) | |
tree | e784f7f5a98b3083d25fa401ea122c40d14e5769 /core/src | |
parent | cd4799b7b93c542e1d8204a32b6d43df7e5d1191 (diff) | |
parent | dba4c72e90946dda0917a43b9be99d21695e6bdf (diff) | |
download | kau-2889fae685edbad89c40e3cfe8a9b16f0b87ebcc.tar.gz kau-2889fae685edbad89c40e3cfe8a9b16f0b87ebcc.tar.bz2 kau-2889fae685edbad89c40e3cfe8a9b16f0b87ebcc.zip |
Merge pull request #229 from AllanWang/nav-bar-flag
Nav bar flag
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt | 1 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 59 |
2 files changed, 35 insertions, 25 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 279bcd3..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,34 +113,41 @@ 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 (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 and View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv() + } else { + prevSystemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + } + window.decorView.systemUiVisibility = prevSystemUiVisibility } 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 (buildIsLollipopAndUp) { - window.statusBarColor = value + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + return } - } - -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() + window.statusBarColor = value + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + return } + var prevSystemUiVisibility = window.decorView.systemUiVisibility + prevSystemUiVisibility = if (value.isColorDark) { + prevSystemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() + } else { + prevSystemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR + } + window.decorView.systemUiVisibility = prevSystemUiVisibility } /** @@ -148,7 +155,11 @@ 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) } |