From d94edf92f293304d8b5289bf4d215c682c36d13a Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Mon, 12 Aug 2019 10:35:13 -0400 Subject: [PATCH] Issue #3647 - Bring back siteSecurityColor --- .../browser/toolbar/BrowserToolbar.kt | 38 +++++------ .../browser/toolbar/display/DisplayToolbar.kt | 30 ++++++--- .../toolbar/display/SiteSecurityIconView.kt | 48 +++++++++++++ .../toolbar/display/SiteSecurityIcons.kt | 67 ------------------- .../res/drawable/mozac_ic_site_security.xml | 8 +++ .../main/res/values/attrs_browser_toolbar.xml | 9 ++- .../browser/toolbar/BrowserToolbarTest.kt | 19 ------ .../toolbar/display/DisplayToolbarTest.kt | 66 ++++++++++-------- .../toolbar/display/SiteSecurityIconsTest.kt | 55 --------------- .../customtabs/CustomTabsToolbarFeature.kt | 2 +- .../src/main/res/drawable/mozac_ic_lock.xml | 2 +- docs/changelog.md | 4 +- .../samples/toolbar/ToolbarActivity.kt | 4 ++ .../res/drawable/custom_security_icon.xml | 47 +++++++++++++ 14 files changed, 195 insertions(+), 204 deletions(-) create mode 100644 components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteSecurityIconView.kt delete mode 100644 components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteSecurityIcons.kt create mode 100644 components/browser/toolbar/src/main/res/drawable/mozac_ic_site_security.xml delete mode 100644 components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/display/SiteSecurityIconsTest.kt create mode 100644 samples/toolbar/src/main/res/drawable/custom_security_icon.xml diff --git a/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt b/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt index 0c9b3f9be0a..0fc54f11954 100644 --- a/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt +++ b/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/BrowserToolbar.kt @@ -31,7 +31,6 @@ import kotlinx.coroutines.launch import mozilla.components.browser.menu.BrowserMenuBuilder import mozilla.components.browser.toolbar.display.DisplayToolbar import mozilla.components.browser.toolbar.display.DisplayToolbar.Companion.BOTTOM_PROGRESS_BAR -import mozilla.components.browser.toolbar.display.SiteSecurityIcons import mozilla.components.browser.toolbar.display.TrackingProtectionIconView import mozilla.components.browser.toolbar.edit.EditToolbar import mozilla.components.concept.toolbar.AutocompleteDelegate @@ -114,12 +113,21 @@ class BrowserToolbar @JvmOverloads constructor( } /** - * Set/Get the site security icons (usually a lock or globe icon). It uses a pair of drawables - * which represent the insecure and secure colours respectively. + * Set/Get the site security icon (usually a lock and globe icon). It uses a + * [android.graphics.drawable.StateListDrawable] where "state_site_secure" represents the secure + * icon and empty state represents the insecure icon. */ - var siteSecurityIcons - get() = displayToolbar.securityIcons - set(value) { displayToolbar.securityIcons = value } + var siteSecurityIcon + get() = displayToolbar.securityIcon + set(value) { displayToolbar.securityIcon = value } + + /** + * Set/Get the site security icon colours. It uses a pair of color integers + * which represent the insecure and secure colours respectively. + */ + var siteSecurityColor: Pair + get() = displayToolbar.securityIconColor + set(value) { displayToolbar.securityIconColor = value } /** * Gets/Sets a custom view that will be drawn as behind the URL and page actions in display mode. @@ -301,11 +309,6 @@ class BrowserToolbar @JvmOverloads constructor( editToolbar.urlView.typeface = value } - fun setSiteSecurityColor(colors: Pair) { - displayToolbar.securityIcons = - displayToolbar.securityIcons.withColorFilter(colors.first, colors.second) - } - /** * Sets a listener to be invoked when focus of the URL input view (in edit mode) changed. */ @@ -474,20 +477,17 @@ class BrowserToolbar @JvmOverloads constructor( R.styleable.BrowserToolbar_browserToolbarSuggestionBackgroundColor, suggestionBackgroundColor ) - val inSecureIcon = getDrawable(R.styleable.BrowserToolbar_browserToolbarInsecureIcon) - ?: displayToolbar.securityIcons.insecure - val secureIcon = getDrawable(R.styleable.BrowserToolbar_browserToolbarSecureIcon) - ?: displayToolbar.securityIcons.secure - val inSecureColor = getColor( + siteSecurityIcon = getDrawable(R.styleable.BrowserToolbar_browserToolbarSecurityIcon) + ?: displayToolbar.securityIcon + val insecureColor = getColor( R.styleable.BrowserToolbar_browserToolbarInsecureColor, displayToolbar.defaultColor ) val secureColor = getColor( - R.styleable.BrowserToolbar_browserToolbarSecureColor, + R.styleable.BrowserToolbar_browserToolbarInsecureColor, displayToolbar.defaultColor ) - siteSecurityIcons = SiteSecurityIcons(inSecureIcon, secureIcon) - .withColorFilter(inSecureColor, secureColor) + siteSecurityColor = insecureColor to secureColor val fadingEdgeLength = getDimensionPixelSize( R.styleable.BrowserToolbar_browserToolbarFadingEdgeSize, resources.getDimensionPixelSize(R.dimen.mozac_browser_toolbar_url_fading_edge_size) 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 278b995f380..5509fea3895 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 @@ -6,6 +6,7 @@ package mozilla.components.browser.toolbar.display import android.annotation.SuppressLint import android.content.Context +import android.graphics.Color import android.graphics.drawable.Drawable import android.view.Gravity import android.view.View @@ -29,10 +30,10 @@ import mozilla.components.browser.toolbar.internal.wrapAction import mozilla.components.concept.toolbar.Toolbar import mozilla.components.concept.toolbar.Toolbar.SiteSecurity import mozilla.components.concept.toolbar.Toolbar.SiteTrackingProtection +import mozilla.components.concept.toolbar.Toolbar.SiteTrackingProtection.OFF_FOR_A_SITE +import mozilla.components.concept.toolbar.Toolbar.SiteTrackingProtection.OFF_GLOBALLY import mozilla.components.concept.toolbar.Toolbar.SiteTrackingProtection.ON_NO_TRACKERS_BLOCKED import mozilla.components.concept.toolbar.Toolbar.SiteTrackingProtection.ON_TRACKERS_BLOCKED -import mozilla.components.concept.toolbar.Toolbar.SiteTrackingProtection.OFF_GLOBALLY -import mozilla.components.concept.toolbar.Toolbar.SiteTrackingProtection.OFF_FOR_A_SITE /** * Sub-component of the browser toolbar responsible for displaying the URL and related controls. @@ -127,7 +128,13 @@ internal class DisplayToolbar( private var siteTrackingProtection = OFF_GLOBALLY - internal var securityIcons = SiteSecurityIcons.getDefaultSecurityIcons(context, defaultColor) + internal var securityIcon = context.getDrawable(R.drawable.mozac_ic_site_security) + set(value) { + field = value + siteSecurityIconView.setImageDrawable(value) + } + + internal var securityIconColor = defaultColor to defaultColor set(value) { field = value setSiteSecurity(currentSiteSecurity) @@ -160,11 +167,9 @@ internal class DisplayToolbar( setOnClickListener(null) } - internal val siteSecurityIconView = AppCompatImageView(context).apply { + internal val siteSecurityIconView = SiteSecurityIconView(context).apply { setPadding(resources.getDimensionPixelSize(R.dimen.mozac_browser_toolbar_icon_padding)) - setImageDrawable(securityIcons.insecure) - // Avoiding text behind the icon being selectable. If the listener is not set // with a value or null text behind the icon can be selectable. // https://github.com/mozilla-mobile/reference-browser/issues/448 @@ -305,12 +310,17 @@ internal class DisplayToolbar( * Sets the site's security icon as secure if true, else the regular globe. */ fun setSiteSecurity(secure: SiteSecurity) { - val drawable = when (secure) { - SiteSecurity.INSECURE -> securityIcons.insecure - SiteSecurity.SECURE -> securityIcons.secure + @ColorInt val color = when (secure) { + SiteSecurity.INSECURE -> securityIconColor.first + SiteSecurity.SECURE -> securityIconColor.second + } + if (color == Color.TRANSPARENT) { + siteSecurityIconView.clearColorFilter() + } else { + siteSecurityIconView.setColorFilter(color) } - siteSecurityIconView.setImageDrawable(drawable) + siteSecurityIconView.siteSecurity = secure currentSiteSecurity = secure } diff --git a/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteSecurityIconView.kt b/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteSecurityIconView.kt new file mode 100644 index 00000000000..4821b3306ca --- /dev/null +++ b/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteSecurityIconView.kt @@ -0,0 +1,48 @@ +/* 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.browser.toolbar.display + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import androidx.appcompat.widget.AppCompatImageView +import mozilla.components.browser.toolbar.R +import mozilla.components.concept.toolbar.Toolbar.SiteSecurity + +/** + * Internal widget to display the different icons of site security, relies on the + * [SiteSecurity] state of each page. + */ +internal class SiteSecurityIconView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : AppCompatImageView(context, attrs, defStyleAttr) { + + // We allow null here because in some situations, onCreateDrawableState is getting called from + // the super() constructor on the View class, way before this class properties get + // initialized causing a null pointer exception. + // See for more details: https://github.com/mozilla-mobile/android-components/issues/4058 + var siteSecurity: SiteSecurity? = SiteSecurity.INSECURE + set(value) { + if (value != field) { + field = value + refreshDrawableState() + } + + field = value + } + + override fun onCreateDrawableState(extraSpace: Int): IntArray { + return when (siteSecurity) { + SiteSecurity.INSECURE, null -> super.onCreateDrawableState(extraSpace) + SiteSecurity.SECURE -> { + val drawableState = super.onCreateDrawableState(extraSpace + 1) + View.mergeDrawableStates(drawableState, intArrayOf(R.attr.state_site_secure)) + drawableState + } + } + } +} diff --git a/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteSecurityIcons.kt b/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteSecurityIcons.kt deleted file mode 100644 index 7b0434d6bab..00000000000 --- a/components/browser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteSecurityIcons.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* 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.browser.toolbar.display - -import android.content.Context -import android.graphics.BlendMode -import android.graphics.BlendModeColorFilter -import android.graphics.ColorFilter -import android.graphics.PorterDuff -import android.graphics.PorterDuffColorFilter -import android.graphics.drawable.Drawable -import android.os.Build -import android.os.Build.VERSION.SDK_INT -import androidx.annotation.ColorInt -import mozilla.components.ui.icons.R - -/** - * Specifies icons to display in the toolbar representing the security of the current website. - * - * @property insecure Icon to display for HTTP sites. - * @property secure Icon to display for HTTPS sites. - */ -data class SiteSecurityIcons( - val insecure: Drawable?, - val secure: Drawable? -) { - - /** - * Returns an instance of [SiteSecurityIcons] with a color filter applied to each icon. - */ - fun withColorFilter(insecureColorFilter: ColorFilter, secureColorFilter: ColorFilter): SiteSecurityIcons { - return copy( - insecure = insecure?.apply { colorFilter = insecureColorFilter }, - secure = secure?.apply { colorFilter = secureColorFilter } - ) - } - - /** - * Returns an instance of [SiteSecurityIcons] with a color tint applied to each icon. - */ - fun withColorFilter(@ColorInt insecureColor: Int, @ColorInt secureColor: Int): SiteSecurityIcons { - val insecureColorFilter: ColorFilter = if (SDK_INT >= Build.VERSION_CODES.Q) { - BlendModeColorFilter(insecureColor, BlendMode.SRC_IN) - } else { - PorterDuffColorFilter(insecureColor, PorterDuff.Mode.SRC_IN) - } - - val secureColorFilter: ColorFilter = if (SDK_INT >= Build.VERSION_CODES.Q) { - BlendModeColorFilter(secureColor, BlendMode.SRC_IN) - } else { - PorterDuffColorFilter(secureColor, PorterDuff.Mode.SRC_IN) - } - - return withColorFilter(insecureColorFilter, secureColorFilter) - } - - companion object { - fun getDefaultSecurityIcons(context: Context, @ColorInt color: Int): SiteSecurityIcons { - return SiteSecurityIcons( - insecure = context.getDrawable(R.drawable.mozac_ic_globe), - secure = context.getDrawable(R.drawable.mozac_ic_lock) - ).withColorFilter(color, color) - } - } -} diff --git a/components/browser/toolbar/src/main/res/drawable/mozac_ic_site_security.xml b/components/browser/toolbar/src/main/res/drawable/mozac_ic_site_security.xml new file mode 100644 index 00000000000..cdba3bc2eab --- /dev/null +++ b/components/browser/toolbar/src/main/res/drawable/mozac_ic_site_security.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/components/browser/toolbar/src/main/res/values/attrs_browser_toolbar.xml b/components/browser/toolbar/src/main/res/values/attrs_browser_toolbar.xml index eef30845fda..d2a78de9e58 100644 --- a/components/browser/toolbar/src/main/res/values/attrs_browser_toolbar.xml +++ b/components/browser/toolbar/src/main/res/values/attrs_browser_toolbar.xml @@ -8,10 +8,9 @@ - - - + + @@ -29,4 +28,8 @@ + + + + diff --git a/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt b/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt index 1f309a72662..600718a60a6 100644 --- a/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt +++ b/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/BrowserToolbarTest.kt @@ -6,8 +6,6 @@ package mozilla.components.browser.toolbar import android.content.Context import android.graphics.Color -import android.graphics.PorterDuff -import android.graphics.PorterDuffColorFilter import android.graphics.Typeface import android.graphics.drawable.Drawable import android.util.AttributeSet @@ -908,23 +906,6 @@ class BrowserToolbarTest { assertEquals(View.VISIBLE, toolbar.displayToolbar.siteSecurityIconView.visibility) } - @Test - fun `siteSecurityColor setter`() { - val toolbar = BrowserToolbar(testContext) - - toolbar.setSiteSecurityColor(Color.RED to Color.BLUE) - assertEquals( - PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN), - toolbar.displayToolbar.siteSecurityIconView.drawable.colorFilter - ) - - toolbar.siteSecure = SiteSecurity.SECURE - assertEquals( - PorterDuffColorFilter(Color.BLUE, PorterDuff.Mode.SRC_IN), - toolbar.displayToolbar.siteSecurityIconView.drawable.colorFilter - ) - } - @Test fun `urlBoxView getter`() { val toolbar = BrowserToolbar(testContext) 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 abc4939c653..6d8789cc4e5 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 @@ -4,7 +4,9 @@ package mozilla.components.browser.toolbar.display +import android.graphics.Color import android.graphics.Rect +import android.graphics.drawable.Drawable import android.view.View import android.view.ViewGroup import android.widget.ImageButton @@ -42,19 +44,10 @@ import org.mockito.Mockito.never import org.mockito.Mockito.reset import org.mockito.Mockito.spy import org.mockito.Mockito.verify -import org.robolectric.Shadows.shadowOf @RunWith(AndroidJUnit4::class) class DisplayToolbarTest { - @Test - fun `initialized with security icon`() { - val toolbar = mock(BrowserToolbar::class.java) - val displayToolbar = DisplayToolbar(testContext, toolbar) - - assertNotNull(displayToolbar.siteSecurityIconView.drawable) - } - @Test fun `clicking on the URL switches the toolbar to editing mode`() { val toolbar = mock(BrowserToolbar::class.java) @@ -960,45 +953,64 @@ class DisplayToolbarTest { } @Test - fun `iconView changes image resource when site security changes`() { + fun `iconView changes site secure state when site security changes`() { val toolbar = mock(BrowserToolbar::class.java) val displayToolbar = DisplayToolbar(testContext, toolbar) - var shadowDrawable = shadowOf(displayToolbar.siteSecurityIconView.drawable) - assertEquals(R.drawable.mozac_ic_globe, shadowDrawable.createdFromResId) + assertEquals(SiteSecurity.INSECURE, displayToolbar.siteSecurityIconView.siteSecurity) displayToolbar.setSiteSecurity(SiteSecurity.SECURE) - shadowDrawable = shadowOf(displayToolbar.siteSecurityIconView.drawable) - assertEquals(R.drawable.mozac_ic_lock, shadowDrawable.createdFromResId) + assertEquals(SiteSecurity.SECURE, displayToolbar.siteSecurityIconView.siteSecurity) displayToolbar.setSiteSecurity(SiteSecurity.INSECURE) - shadowDrawable = shadowOf(displayToolbar.siteSecurityIconView.drawable) - assertEquals(R.drawable.mozac_ic_globe, shadowDrawable.createdFromResId) + assertEquals(SiteSecurity.INSECURE, displayToolbar.siteSecurityIconView.siteSecurity) } @Test - fun `securityIcons is set when securityIcons changes`() { + fun `securityIcon is set when securityIcon changes`() { val toolbar = mock(BrowserToolbar::class.java) val displayToolbar = DisplayToolbar(testContext, toolbar) - val insecure = testContext.getDrawable(R.drawable.mozac_ic_globe) - val secure = testContext.getDrawable(R.drawable.mozac_ic_lock) - displayToolbar.securityIcons = SiteSecurityIcons(insecure, secure) + val icon = testContext.getDrawable(R.drawable.mozac_ic_site_security) + displayToolbar.securityIcon = icon + + assertEquals(icon, displayToolbar.securityIcon) + } + + @Test + fun `setImageDrawable is called when securityIcon changes`() { + val toolbar = BrowserToolbar(testContext) + + val icon: Drawable = mock() + assertNotEquals(icon, toolbar.displayToolbar.siteSecurityIconView.drawable) + + toolbar.siteSecurityIcon = icon + assertEquals(icon, toolbar.displayToolbar.siteSecurityIconView.drawable) + } + + @Test + fun `securityIconColor is set when securityIconColor changes`() { + val toolbar = BrowserToolbar(testContext) + + assertNull(toolbar.displayToolbar.siteSecurityIconView.colorFilter) + + toolbar.siteSecurityColor = Color.TRANSPARENT to Color.TRANSPARENT + assertNull(toolbar.displayToolbar.siteSecurityIconView.colorFilter) - assertEquals(insecure, displayToolbar.securityIcons.insecure) - assertEquals(secure, displayToolbar.securityIcons.secure) + toolbar.siteSecurityColor = Color.BLUE to Color.BLUE + assertNotNull(toolbar.displayToolbar.siteSecurityIconView.colorFilter) } @Test - fun `setSiteSecurity is called when securityIcons changes`() { + fun `setSiteSecurity is called when securityIconColor changes`() { val toolbar = BrowserToolbar(testContext) - val icons = SiteSecurityIcons(mock(), mock()) - assertNotEquals(icons, toolbar.displayToolbar.securityIcons) + val icon: Drawable = mock() + assertNotEquals(icon, toolbar.displayToolbar.securityIcon) - toolbar.siteSecurityIcons = icons - assertEquals(icons, toolbar.displayToolbar.securityIcons) + toolbar.siteSecurityIcon = icon + assertEquals(icon, toolbar.displayToolbar.securityIcon) } @Test diff --git a/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/display/SiteSecurityIconsTest.kt b/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/display/SiteSecurityIconsTest.kt deleted file mode 100644 index cd6a7596999..00000000000 --- a/components/browser/toolbar/src/test/java/mozilla/components/browser/toolbar/display/SiteSecurityIconsTest.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* 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.browser.toolbar.display - -import android.graphics.Color -import android.graphics.ColorMatrix -import android.graphics.ColorMatrixColorFilter -import android.graphics.PorterDuff -import android.graphics.PorterDuffColorFilter -import android.graphics.drawable.Drawable -import androidx.test.ext.junit.runners.AndroidJUnit4 -import mozilla.components.support.test.mock -import mozilla.components.support.test.robolectric.testContext -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mockito.verify - -@RunWith(AndroidJUnit4::class) -class SiteSecurityIconsTest { - - @Test - fun `default returns non-null tinted icons`() { - val icons = SiteSecurityIcons.getDefaultSecurityIcons(testContext, Color.RED) - assertEquals(PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN), icons.insecure?.colorFilter) - assertEquals(PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN), icons.secure?.colorFilter) - } - - @Test - fun `withColorFilter tints existing drawables`() { - val insecure: Drawable = mock() - val secure: Drawable = mock() - val icons = SiteSecurityIcons(insecure, secure).withColorFilter(Color.BLUE, Color.RED) - - assertEquals(insecure, icons.insecure) - assertEquals(secure, icons.secure) - verify(insecure).colorFilter = PorterDuffColorFilter(Color.BLUE, PorterDuff.Mode.SRC_IN) - verify(secure).colorFilter = PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN) - } - - @Test - fun `withColorFilter allows custom filters to be used`() { - val insecure: Drawable = mock() - val secure: Drawable = mock() - val filter = ColorMatrixColorFilter(ColorMatrix()) - val icons = SiteSecurityIcons(insecure, secure).withColorFilter(filter, filter) - - assertEquals(insecure, icons.insecure) - assertEquals(secure, icons.secure) - verify(insecure).colorFilter = filter - verify(secure).colorFilter = filter - } -} diff --git a/components/feature/customtabs/src/main/java/mozilla/components/feature/customtabs/CustomTabsToolbarFeature.kt b/components/feature/customtabs/src/main/java/mozilla/components/feature/customtabs/CustomTabsToolbarFeature.kt index 055663d9f0d..705a139ae9e 100644 --- a/components/feature/customtabs/src/main/java/mozilla/components/feature/customtabs/CustomTabsToolbarFeature.kt +++ b/components/feature/customtabs/src/main/java/mozilla/components/feature/customtabs/CustomTabsToolbarFeature.kt @@ -101,7 +101,7 @@ class CustomTabsToolbarFeature( toolbar.setBackgroundColor(color) toolbar.textColor = readableColor toolbar.titleColor = readableColor - toolbar.setSiteSecurityColor(readableColor to readableColor) + toolbar.siteSecurityColor = readableColor to readableColor toolbar.menuViewColor = readableColor window?.setStatusBarTheme(color) diff --git a/components/ui/icons/src/main/res/drawable/mozac_ic_lock.xml b/components/ui/icons/src/main/res/drawable/mozac_ic_lock.xml index 2d77e7b3391..77d7c6b01a1 100644 --- a/components/ui/icons/src/main/res/drawable/mozac_ic_lock.xml +++ b/components/ui/icons/src/main/res/drawable/mozac_ic_lock.xml @@ -9,5 +9,5 @@ android:viewportHeight="24.0"> + android:pathData="M17 11V8A5 5 0 0 0 7 8v3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-6a2 2 0 0 0-2-2zM9 8a3 3 0 0 1 3-3 3 3 0 0 1 3 3v3H9z"/> diff --git a/docs/changelog.md b/docs/changelog.md index 87a2d926395..03747b8d6ba 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -19,8 +19,8 @@ permalink: /changelog/ * The component now handles situations where the Android system kills the content process (without killing the main app process) in order to reclaim resources. In those situations the component will automatically recover and restore the last known state of those sessions. * **browser-toolbar** - * ⚠️ **This is a breaking change**: The `BrowserToolbar.siteSecurityColor` property has been replaced with the setter `BrowserToolbar.setSiteSecurityColor`. - * Added `BrowserToolbar.siteSecurityIcons` to use custom security icons with multiple colors in the toolbar. + * Changed `BrowserToolbar.siteSecurityColor` to use no icon color filter when the color is set to `Color.TRANSPARENT`. + * Added `BrowserToolbar.siteSecurityIcon` to use custom security icons with multiple colors in the toolbar. * **feature-sendtab** * Added a `SendTabFeature` that observes account device events with optional support for push notifications. diff --git a/samples/toolbar/src/main/java/org/mozilla/samples/toolbar/ToolbarActivity.kt b/samples/toolbar/src/main/java/org/mozilla/samples/toolbar/ToolbarActivity.kt index 59ed69d8fdd..1d26f4d94f0 100644 --- a/samples/toolbar/src/main/java/org/mozilla/samples/toolbar/ToolbarActivity.kt +++ b/samples/toolbar/src/main/java/org/mozilla/samples/toolbar/ToolbarActivity.kt @@ -5,6 +5,7 @@ package org.mozilla.samples.toolbar import android.content.res.Resources +import android.graphics.Color import android.os.Bundle import android.view.View import androidx.annotation.DrawableRes @@ -160,6 +161,9 @@ class ToolbarActivity : AppCompatActivity() { */ private fun setupCustomMenu() { + toolbar.siteSecurityColor = Color.TRANSPARENT to Color.TRANSPARENT + toolbar.siteSecurityIcon = getDrawable(R.drawable.custom_security_icon) + toolbar.setBackgroundColor( ContextCompat.getColor(this, mozilla.components.ui.colors.R.color.photonBlue80)) diff --git a/samples/toolbar/src/main/res/drawable/custom_security_icon.xml b/samples/toolbar/src/main/res/drawable/custom_security_icon.xml new file mode 100644 index 00000000000..d0b622e9921 --- /dev/null +++ b/samples/toolbar/src/main/res/drawable/custom_security_icon.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + +