forked from mozilla-mobile/android-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#3647 - Custom HTTP(S) icons in toolbar
- Loading branch information
Showing
9 changed files
with
221 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ser/toolbar/src/main/java/mozilla/components/browser/toolbar/display/SiteSecurityIcons.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* 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 both icons. | ||
*/ | ||
fun withColorFilter(newColorFilter: ColorFilter): SiteSecurityIcons { | ||
return copy( | ||
insecure = insecure?.apply { colorFilter = newColorFilter }, | ||
secure = secure?.apply { colorFilter = newColorFilter } | ||
) | ||
} | ||
|
||
/** | ||
* Returns an instance of [SiteSecurityIcons] with a color tint applied to both icons. | ||
*/ | ||
fun withColorFilter(@ColorInt newColor: Int): SiteSecurityIcons { | ||
val newColorFilter: ColorFilter = if (SDK_INT >= Build.VERSION_CODES.Q) { | ||
BlendModeColorFilter(newColor, BlendMode.SRC_IN) | ||
} else { | ||
PorterDuffColorFilter(newColor, PorterDuff.Mode.SRC_IN) | ||
} | ||
|
||
return withColorFilter(newColorFilter) | ||
} | ||
|
||
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.