From 9b440c510a655491178e26e4fa6c0f8a3537be53 Mon Sep 17 00:00:00 2001 From: iorgamgabriel Date: Mon, 17 Oct 2022 13:29:20 +0300 Subject: [PATCH] [components] For #1795650 The colors of the icons from the status bar should be in contrast with the status bar background color. --- .../components/support/ktx/build.gradle | 6 +++ .../ktx/src/androidTest/AndroidManifest.xml | 13 +++++ .../mozilla/components/support/ktx/TestActivity.kt | 12 +++++ .../support/ktx/android/view/WindowKtTest.kt | 57 ++++++++++++++++++++++ .../components/support/ktx/android/view/Window.kt | 12 ++--- .../android/android-components/docs/changelog.md | 3 ++ 6 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 mobile/android/android-components/components/support/ktx/src/androidTest/AndroidManifest.xml create mode 100644 mobile/android/android-components/components/support/ktx/src/androidTest/java/mozilla/components/support/ktx/TestActivity.kt create mode 100644 mobile/android/android-components/components/support/ktx/src/androidTest/java/mozilla/components/support/ktx/android/view/WindowKtTest.kt diff --git a/mobile/android/android-components/components/support/ktx/build.gradle b/mobile/android/android-components/components/support/ktx/build.gradle index 3618fed73510..14d00cc4bbcf 100644 --- a/mobile/android/android-components/components/support/ktx/build.gradle +++ b/mobile/android/android-components/components/support/ktx/build.gradle @@ -52,6 +52,12 @@ dependencies { testImplementation Dependencies.testing_coroutines testImplementation Dependencies.testing_robolectric testImplementation Dependencies.testing_mockito + + androidTestImplementation project(':support-android-test') + androidTestImplementation Dependencies.androidx_test_core + androidTestImplementation Dependencies.androidx_test_runner + androidTestImplementation Dependencies.androidx_test_rules + androidTestImplementation Dependencies.androidx_test_junit } apply from: '../../../publish.gradle' diff --git a/mobile/android/android-components/components/support/ktx/src/androidTest/AndroidManifest.xml b/mobile/android/android-components/components/support/ktx/src/androidTest/AndroidManifest.xml new file mode 100644 index 000000000000..d526611a9752 --- /dev/null +++ b/mobile/android/android-components/components/support/ktx/src/androidTest/AndroidManifest.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/mobile/android/android-components/components/support/ktx/src/androidTest/java/mozilla/components/support/ktx/TestActivity.kt b/mobile/android/android-components/components/support/ktx/src/androidTest/java/mozilla/components/support/ktx/TestActivity.kt new file mode 100644 index 000000000000..ad3d123c10bd --- /dev/null +++ b/mobile/android/android-components/components/support/ktx/src/androidTest/java/mozilla/components/support/ktx/TestActivity.kt @@ -0,0 +1,12 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package mozilla.components.support.ktx + +import android.app.Activity + +/** + * Empty activity only to be used in UI tests. + */ +internal class TestActivity : Activity() diff --git a/mobile/android/android-components/components/support/ktx/src/androidTest/java/mozilla/components/support/ktx/android/view/WindowKtTest.kt b/mobile/android/android-components/components/support/ktx/src/androidTest/java/mozilla/components/support/ktx/android/view/WindowKtTest.kt new file mode 100644 index 000000000000..35d3ce326783 --- /dev/null +++ b/mobile/android/android-components/components/support/ktx/src/androidTest/java/mozilla/components/support/ktx/android/view/WindowKtTest.kt @@ -0,0 +1,57 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package mozilla.components.support.ktx.android.view + +import android.graphics.Color +import androidx.test.ext.junit.rules.ActivityScenarioRule +import androidx.test.filters.SdkSuppress +import mozilla.components.support.ktx.TestActivity +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test + +class WindowKtTest { + @get:Rule + internal val activityRule: ActivityScenarioRule = ActivityScenarioRule(TestActivity::class.java) + + @SdkSuppress(minSdkVersion = 23) + @Test + fun whenALightColorIsAppliedToStatusBarThenSetIsAppearanceLightStatusBarsToTrue() { + activityRule.scenario.onActivity { + it.window.setStatusBarTheme(Color.WHITE) + + assertTrue(it.window.getWindowInsetsController().isAppearanceLightStatusBars) + } + } + + @Test + fun whenADarkColorIsAppliedToStatusBarThenSetIsAppearanceLightStatusBarsToFalse() { + activityRule.scenario.onActivity { + it.window.setStatusBarTheme(Color.BLACK) + + assertFalse(it.window.getWindowInsetsController().isAppearanceLightStatusBars) + } + } + + @SdkSuppress(minSdkVersion = 23) + @Test + fun whenALightColorIsAppliedToNavigationBarThemeThenSetIsAppearanceLightNavigationBarsToTrue() { + activityRule.scenario.onActivity { + it.window.setNavigationBarTheme(Color.WHITE) + + assertTrue(it.window.getWindowInsetsController().isAppearanceLightNavigationBars) + } + } + + @Test + fun whenADarkColorIsAppliedToNavigationBarThemeThenSetIsAppearanceLightNavigationBarsToFalse() { + activityRule.scenario.onActivity { + it.window.setNavigationBarTheme(Color.BLACK) + + assertFalse(it.window.getWindowInsetsController().isAppearanceLightNavigationBars) + } + } +} diff --git a/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/view/Window.kt b/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/view/Window.kt index e2eff49a3fbe..b54a34f6e3e9 100644 --- a/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/view/Window.kt +++ b/mobile/android/android-components/components/support/ktx/src/main/java/mozilla/components/support/ktx/android/view/Window.kt @@ -15,24 +15,24 @@ import mozilla.components.support.utils.ColorUtils.isDark * Colors the status bar. * If the color is light enough, a light status bar with dark icons will be used. */ -fun Window.setStatusBarTheme(@ColorInt color: Int) { +fun Window.setStatusBarTheme(@ColorInt toolbarColor: Int) { getWindowInsetsController().isAppearanceLightStatusBars = - isDark(color) - statusBarColor = color + !isDark(toolbarColor) + statusBarColor = toolbarColor } /** * Colors the navigation bar. * If the color is light enough, a light navigation bar with dark icons will be used. */ -fun Window.setNavigationBarTheme(@ColorInt color: Int) { +fun Window.setNavigationBarTheme(@ColorInt toolbarColor: Int) { getWindowInsetsController().isAppearanceLightNavigationBars = - isDark(color) + !isDark(toolbarColor) if (SDK_INT >= Build.VERSION_CODES.P) { navigationBarDividerColor = 0 } - navigationBarColor = color + navigationBarColor = toolbarColor } /** diff --git a/mobile/android/android-components/docs/changelog.md b/mobile/android/android-components/docs/changelog.md index 5d3516324f36..04dc9a4526fc 100644 --- a/mobile/android/android-components/docs/changelog.md +++ b/mobile/android/android-components/docs/changelog.md @@ -13,6 +13,9 @@ permalink: /changelog/ * **feature-qr** * QRFeature now allows querying if scanning is in progress with a new `isScanInProgress` property. This helps deciding on whether to resume scanning by calling `scan` in a new `QRFeature` instance as it can happen if the process is restarted as a followup to the user updating system permissions for the app. +* **support-ktx**: + * The colors of the icons from the status bar should be in contrast with the status bar background color [#1795650](https://bugzilla.mozilla.org/show_bug.cgi?id=1795650) + # 107.0.0 * [Commits](https://github.com/mozilla-mobile/android-components/compare/v106.0.0..v107.0.0) * [Milestone](https://github.com/mozilla-mobile/android-components/milestone/154?closed=1) -- 2.11.4.GIT