adding some status bar related improvements
This commit is contained in:
parent
7aec92a201
commit
001686670f
3 changed files with 8 additions and 9 deletions
|
@ -240,8 +240,11 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
|
|||
materialScrollColorAnimation?.end()
|
||||
|
||||
val statusBarColor = getColoredMaterialStatusBarColor()
|
||||
val contrastColor = statusBarColor.getContrastColor()
|
||||
updateStatusbarColor(statusBarColor)
|
||||
toolbar.setBackgroundColor(statusBarColor)
|
||||
toolbar.setTitleTextColor(contrastColor)
|
||||
toolbar.navigationIcon?.applyColorFilter(contrastColor)
|
||||
} else if (scrollY == 0 && oldScrollY > 0) {
|
||||
val colorFrom = getColoredMaterialStatusBarColor()
|
||||
val colorTo = getProperBackgroundColor()
|
||||
|
@ -249,8 +252,12 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
|
|||
materialScrollColorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), colorFrom, colorTo)
|
||||
materialScrollColorAnimation!!.addUpdateListener { animator ->
|
||||
val color = animator.animatedValue as Int
|
||||
val contrastColor = color.getContrastColor()
|
||||
window.statusBarColor = color
|
||||
toolbar.setBackgroundColor(color)
|
||||
toolbar.setTitleTextColor(contrastColor)
|
||||
toolbar.navigationIcon?.applyColorFilter(contrastColor)
|
||||
updateStatusbarColor(color)
|
||||
}
|
||||
|
||||
materialScrollColorAnimation!!.start()
|
||||
|
|
|
@ -42,12 +42,7 @@ fun Context.getColoredMaterialStatusBarColor(): Int {
|
|||
return if (baseConfig.isUsingSystemTheme) {
|
||||
resources.getColor(R.color.you_status_bar_color, theme)
|
||||
} else {
|
||||
val properBackgroundColor = getProperBackgroundColor()
|
||||
if (properBackgroundColor.getContrastColor() == DARK_GREY) {
|
||||
getProperPrimaryColor().lightenColor(MATERIAL_COLOR_CHANGE_FACTOR)
|
||||
} else {
|
||||
getProperPrimaryColor().darkenColor(20)
|
||||
}
|
||||
getProperPrimaryColor()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,9 +48,6 @@ const val LOWER_ALPHA = 0.25f
|
|||
const val MEDIUM_ALPHA = 0.5f
|
||||
const val HIGHER_ALPHA = 0.75f
|
||||
|
||||
// by how much should we darken toolbar and statusbar at scrolling
|
||||
const val MATERIAL_COLOR_CHANGE_FACTOR = 35
|
||||
|
||||
const val HOUR_MINUTES = 60
|
||||
const val DAY_MINUTES = 24 * HOUR_MINUTES
|
||||
const val WEEK_MINUTES = DAY_MINUTES * 7
|
||||
|
|
Loading…
Reference in a new issue