Unverified Commit 5faa22d6 authored by Tiger Oakes's avatar Tiger Oakes Committed by GitHub
Browse files

Use createBlendModeColorFilterCompat (#8129)

parent 5515f1ba
......@@ -4,10 +4,11 @@
package org.mozilla.fenix.collections
import android.graphics.PorterDuff.Mode.SRC_IN
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.graphics.BlendModeColorFilterCompat.createBlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.collections_list_item.view.*
import mozilla.components.feature.tab.collections.TabCollection
......@@ -52,11 +53,8 @@ class CollectionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(collection: TabCollection) {
itemView.collection_item.text = collection.title
itemView.collection_description.text = collection.description(itemView.context)
itemView.collection_icon.setColorFilter(
collection.getIconColor(itemView.context),
SRC_IN
)
itemView.collection_icon.colorFilter =
createBlendModeColorFilterCompat(collection.getIconColor(itemView.context), SRC_IN)
}
companion object {
......
......@@ -5,13 +5,13 @@
package org.mozilla.fenix.ext
import android.graphics.ColorFilter
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.widget.ActionMenuView
import android.widget.ImageButton
import androidx.annotation.ColorInt
import androidx.appcompat.view.menu.ActionMenuItemView
import androidx.appcompat.widget.Toolbar
import androidx.core.graphics.BlendModeColorFilterCompat.createBlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.core.view.forEach
/**
......@@ -22,7 +22,7 @@ fun Toolbar.setToolbarColors(@ColorInt foreground: Int, @ColorInt background: In
setBackgroundColor(background)
setTitleTextColor(foreground)
val colorFilter = PorterDuffColorFilter(foreground, PorterDuff.Mode.SRC_IN)
val colorFilter = createBlendModeColorFilterCompat(foreground, SRC_IN)
overflowIcon?.colorFilter = colorFilter
forEach { child ->
when (child) {
......@@ -33,7 +33,7 @@ fun Toolbar.setToolbarColors(@ColorInt foreground: Int, @ColorInt background: In
}
}
private fun themeActionMenuView(item: ActionMenuView, colorFilter: ColorFilter) {
private fun themeActionMenuView(item: ActionMenuView, colorFilter: ColorFilter?) {
item.forEach { innerChild ->
if (innerChild is ActionMenuItemView) {
innerChild.compoundDrawables.forEach { drawable ->
......
......@@ -5,9 +5,10 @@
package org.mozilla.fenix.home.sessioncontrol.viewholders
import android.content.Context
import android.graphics.PorterDuff.Mode.SRC_IN
import android.view.View
import android.view.ViewGroup
import androidx.core.graphics.BlendModeColorFilterCompat.createBlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.collection_home_list_row.*
......@@ -89,7 +90,7 @@ class CollectionViewHolder(
view.collection_description.visibility = View.VISIBLE
}
view.collection_icon.setColorFilter(
view.collection_icon.colorFilter = createBlendModeColorFilterCompat(
collection.getIconColor(view.context),
SRC_IN
)
......
package org.mozilla.fenix.search.awesomebar
/* 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/. */
* 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 org.mozilla.fenix.search.awesomebar
import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import androidx.core.graphics.BlendModeColorFilterCompat.createBlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.core.graphics.drawable.toBitmap
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
......@@ -25,12 +26,12 @@ import mozilla.components.feature.awesomebar.provider.SessionSuggestionProvider
import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.android.view.hideKeyboard
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.asActivity
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getColorFromAttr
import org.mozilla.fenix.search.SearchEngineSource
import org.mozilla.fenix.search.SearchFragmentState
......@@ -124,56 +125,56 @@ class AwesomeBarView(
init {
view.itemAnimator = null
with(container.context) {
val primaryTextColor = getColorFromAttr(R.attr.primaryText)
val draw = getDrawable(R.drawable.ic_link)!!
draw.setColorFilter(primaryTextColor, SRC_IN)
sessionProvider =
SessionSuggestionProvider(
components.core.sessionManager,
selectTabUseCase,
components.core.icons,
excludeSelectedSession = true
)
historyStorageProvider =
HistoryStorageSuggestionProvider(
components.core.historyStorage,
loadUrlUseCase,
components.core.icons
)
bookmarksStorageSuggestionProvider =
BookmarksStorageSuggestionProvider(
components.core.bookmarksStorage,
loadUrlUseCase,
components.core.icons
)
val searchDrawable = getDrawable(R.drawable.ic_search)!!
searchDrawable.setColorFilter(primaryTextColor, SRC_IN)
defaultSearchSuggestionProvider =
SearchSuggestionProvider(
context = this,
searchEngineManager = components.search.searchEngineManager,
searchUseCase = searchUseCase,
fetchClient = components.core.client,
mode = SearchSuggestionProvider.Mode.MULTIPLE_SUGGESTIONS,
limit = 3,
icon = searchDrawable.toBitmap()
)
shortcutsEnginePickerProvider =
ShortcutsSuggestionProvider(
components.search.provider,
this,
interactor::onSearchShortcutEngineSelected,
interactor::onClickSearchEngineSettings
)
}
val context = container.context
val components = context.components
val primaryTextColor = context.getColorFromAttr(R.attr.primaryText)
val draw = getDrawable(context, R.drawable.ic_link)!!
draw.colorFilter = createBlendModeColorFilterCompat(primaryTextColor, SRC_IN)
sessionProvider =
SessionSuggestionProvider(
components.core.sessionManager,
selectTabUseCase,
components.core.icons,
excludeSelectedSession = true
)
historyStorageProvider =
HistoryStorageSuggestionProvider(
components.core.historyStorage,
loadUrlUseCase,
components.core.icons
)
bookmarksStorageSuggestionProvider =
BookmarksStorageSuggestionProvider(
components.core.bookmarksStorage,
loadUrlUseCase,
components.core.icons
)
val searchDrawable = getDrawable(context, R.drawable.ic_search)!!
searchDrawable.colorFilter = createBlendModeColorFilterCompat(primaryTextColor, SRC_IN)
defaultSearchSuggestionProvider =
SearchSuggestionProvider(
context = context,
searchEngineManager = components.search.searchEngineManager,
searchUseCase = searchUseCase,
fetchClient = components.core.client,
mode = SearchSuggestionProvider.Mode.MULTIPLE_SUGGESTIONS,
limit = 3,
icon = searchDrawable.toBitmap()
)
shortcutsEnginePickerProvider =
ShortcutsSuggestionProvider(
searchEngineProvider = components.search.provider,
context = context,
selectShortcutEngine = interactor::onSearchShortcutEngineSelected,
selectShortcutEngineSettings = interactor::onClickSearchEngineSettings
)
searchSuggestionProviderMap = HashMap()
search_shortcuts_button.setOnClickListener {
......@@ -324,25 +325,23 @@ class AwesomeBarView(
}
private fun getSuggestionProviderForEngine(engine: SearchEngine): SearchSuggestionProvider? {
if (!searchSuggestionProviderMap.containsKey(engine)) {
with(container.context) {
val draw = getDrawable(R.drawable.ic_search)
draw?.colorFilter =
PorterDuffColorFilter(getColorFromAttr(R.attr.primaryText), SRC_IN)
searchSuggestionProviderMap.put(
engine, SearchSuggestionProvider(
components.search.provider.installedSearchEngines(this).list.find { it.name == engine.name }
?: components.search.provider.getDefaultEngine(this),
shortcutSearchUseCase,
components.core.client,
limit = 3,
mode = SearchSuggestionProvider.Mode.MULTIPLE_SUGGESTIONS,
icon = draw?.toBitmap()
)
)
}
return searchSuggestionProviderMap.getOrPut(engine) {
val context = container.context
val components = context.components
val primaryTextColor = context.getColorFromAttr(R.attr.primaryText)
val draw = getDrawable(context, R.drawable.ic_search)
draw?.colorFilter = createBlendModeColorFilterCompat(primaryTextColor, SRC_IN)
SearchSuggestionProvider(
components.search.provider.installedSearchEngines(context).list.find { it.name == engine.name }
?: components.search.provider.getDefaultEngine(context),
shortcutSearchUseCase,
components.core.client,
limit = 3,
mode = SearchSuggestionProvider.Mode.MULTIPLE_SUGGESTIONS,
icon = draw?.toBitmap()
)
}
return searchSuggestionProviderMap[engine]
}
}
......@@ -5,10 +5,11 @@
package org.mozilla.fenix.share.viewholders
import android.content.Context
import android.graphics.PorterDuff
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.getColor
import androidx.core.graphics.BlendModeColorFilterCompat.createBlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.account_share_list_item.view.*
import mozilla.components.concept.sync.DeviceType
......@@ -51,8 +52,8 @@ class AccountDeviceViewHolder(
itemView.deviceIcon.apply {
setImageResource(drawableRes)
background.setColorFilter(ContextCompat.getColor(context, colorRes), PorterDuff.Mode.SRC_IN)
drawable.setTint(ContextCompat.getColor(context, R.color.device_foreground))
background.colorFilter = createBlendModeColorFilterCompat(getColor(context, colorRes), SRC_IN)
drawable.setTint(getColor(context, R.color.device_foreground))
}
itemView.isClickable = option != SyncShareOption.Offline
itemView.deviceName.text = name
......
......@@ -6,13 +6,13 @@ package org.mozilla.fenix.utils
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.PorterDuff.Mode.SRC_IN
import android.graphics.PorterDuffColorFilter
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.MotionEvent.ACTION_UP
import androidx.appcompat.content.res.AppCompatResources
import androidx.appcompat.widget.AppCompatEditText
import androidx.core.graphics.BlendModeColorFilterCompat.createBlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN
import mozilla.components.support.ktx.android.view.putCompoundDrawablesRelativeWithIntrinsicBounds
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getColorFromAttr
......@@ -46,10 +46,9 @@ class ClearableEditText @JvmOverloads constructor(
* Displays a clear icon if text has been entered.
*/
override fun onTextChanged(text: CharSequence?, start: Int, lengthBefore: Int, lengthAfter: Int) {
super.onTextChanged(text, start, lengthBefore, lengthAfter)
val drawable = if (shouldShowClearButton(lengthAfter)) {
AppCompatResources.getDrawable(context, R.drawable.ic_clear)?.apply {
colorFilter = PorterDuffColorFilter(context.getColorFromAttr(R.attr.primaryText), SRC_IN)
colorFilter = createBlendModeColorFilterCompat(context.getColorFromAttr(R.attr.primaryText), SRC_IN)
}
} else {
null
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment