Skip to content

Commit

Permalink
For mozilla-mobile#11545 - Replace clearColorFilter with setColorFilt…
Browse files Browse the repository at this point in the history
…er for security 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 committed Jan 19, 2022
1 parent ccb5325 commit 4406c48
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 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
7 changes: 5 additions & 2 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 All @@ -20,9 +23,9 @@ permalink: /changelog/
* **feature-top-sites**
* ⚠️ **This is a breaking change**: The existing data class `TopSite` has been converted into a sealed class. [#11483](https://github.com/mozilla-mobile/android-components/issues/11483)
* Extend `DefaultTopSitesStorage` to accept a `TopSitesProvider` for fetching top sites. [#11483](https://github.com/mozilla-mobile/android-components/issues/11483)

* **service-contile**
* Adds a `ContileTopSitesProvider` that implements `TopSitesProvider` for returning top sites from the Contile services API. [#11483](https://github.com/mozilla-mobile/android-components/issues/11483)
* Adds a `ContileTopSitesProvider` that implements `TopSitesProvider` for returning top sites from the Contile services API. [#11483](https://github.com/mozilla-mobile/android-components/issues/11483)

# 97.0.0
* [Commits](https://github.com/mozilla-mobile/android-components/compare/v96.0.0...v97.0.0)
Expand Down

0 comments on commit 4406c48

Please sign in to comment.