Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
For #11545 - Replace clearColorFilter with setColorFilter for securit…
Browse files Browse the repository at this point in the history
…y icon

Clear color filter doesn't work on Api 21, 22
Even if we invalidate the view after clearColorFilter the filter is not removed, so to fix the bug
we need to use setColorFilter with color Color.Transparent when the API version is lower than 23
  • Loading branch information
Ionut Cristian Bedregeanu authored and mergify[bot] committed Jan 21, 2022
1 parent 70892ae commit b55a7d8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

1 comment on commit b55a7d8

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Failed to fetch task artifact public/github/customCheckRunText.md for GitHub integration.
Make sure the artifact exists on the worker or other location.

Please sign in to comment.