diff --git a/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt b/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt index caf420b5fd2..38a4844dba2 100644 --- a/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt +++ b/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/DisplayToolbar.kt @@ -8,6 +8,7 @@ import android.content.Context import android.graphics.Color import android.graphics.Typeface import android.graphics.drawable.Drawable +import android.os.Build import android.util.TypedValue import android.view.View import android.view.accessibility.AccessibilityEvent @@ -500,7 +501,7 @@ class DisplayToolbar internal constructor( Toolbar.SiteSecurity.INSECURE -> colors.securityIconInsecure Toolbar.SiteSecurity.SECURE -> colors.securityIconSecure } - if (color == Color.TRANSPARENT) { + if (color == Color.TRANSPARENT && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { views.securityIndicator.clearColorFilter() } else { views.securityIndicator.setColorFilter(color) diff --git a/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/display/DisplayToolbarTest.kt b/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/display/DisplayToolbarTest.kt index 5254eaa5003..a872ad583ab 100644 --- a/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/display/DisplayToolbarTest.kt +++ b/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/display/DisplayToolbarTest.kt @@ -5,6 +5,7 @@ package mozilla.components.browser.toolbar.display import android.graphics.Color +import android.os.Build import android.view.View import androidx.core.content.ContextCompat import androidx.core.view.isGone @@ -41,6 +42,7 @@ import org.mockito.Mockito.never import org.mockito.Mockito.reset import org.mockito.Mockito.spy import org.mockito.Mockito.verify +import org.robolectric.util.ReflectionHelpers @RunWith(AndroidJUnit4::class) class DisplayToolbarTest { @@ -648,19 +650,43 @@ class DisplayToolbarTest { assertNull(displayToolbar.views.securityIndicator.colorFilter) + displayToolbar.colors = displayToolbar.colors.copy( + securityIconSecure = Color.BLUE, + securityIconInsecure = Color.BLUE + ) + + assertNotNull(displayToolbar.views.securityIndicator.colorFilter) + } + + @Test + fun `color filter is set with transparent when securityIconColor changes to transparent and api version is lower than 23`() { + ReflectionHelpers.setStaticField(Build.VERSION::class.java, "SDK_INT", 22) + val (_, displayToolbar) = createDisplayToolbar() + + assertNull(displayToolbar.views.securityIndicator.colorFilter) + displayToolbar.colors = displayToolbar.colors.copy( securityIconSecure = Color.TRANSPARENT, securityIconInsecure = Color.TRANSPARENT ) + assertNotNull(displayToolbar.views.securityIndicator.colorFilter) + } + + @Test + fun `color filter is cleared when securityIconColor changes to transparent and api version is bigger than 22`() { + ReflectionHelpers.setStaticField(Build.VERSION::class.java, "SDK_INT", 23) + + val (_, displayToolbar) = createDisplayToolbar() + assertNull(displayToolbar.views.securityIndicator.colorFilter) displayToolbar.colors = displayToolbar.colors.copy( - securityIconSecure = Color.BLUE, - securityIconInsecure = Color.BLUE + securityIconSecure = Color.TRANSPARENT, + securityIconInsecure = Color.TRANSPARENT ) - assertNotNull(displayToolbar.views.securityIndicator.colorFilter) + assertNull(displayToolbar.views.securityIndicator.colorFilter) } @Test diff --git a/docs/changelog.md b/docs/changelog.md index bcd2dfbc770..97944aea8ac 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -11,6 +11,9 @@ permalink: /changelog/ * [Gecko](https://github.com/mozilla-mobile/android-components/blob/main/buildSrc/src/main/java/Gecko.kt) * [Configuration](https://github.com/mozilla-mobile/android-components/blob/main/.config.yml) +* **browser-toolbar** + * 🚒 Bug fixed [issue #11545](https://github.com/mozilla-mobile/android-components/issues/11545) - `clearColorFilter` doesn't work on Api 21, 22, so the default white filter remains set.Use `clearColorFilter` only when the version of API is bigger than 22 + * **support-ktx** * 🚒 Bug fixed [issue #11527](https://github.com/mozilla-mobile/android-components/issues/11527) - Fix some situations in which the immersive mode wasn't properly applied.