mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-28 08:49:01 +03:00
View extension methods to tint current background
This commit is contained in:
parent
7cad30e6bb
commit
9b6811c915
2 changed files with 14 additions and 13 deletions
vector/src/main/java/im/vector/app
|
@ -23,6 +23,7 @@ import android.view.ViewGroup
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.annotation.AttrRes
|
import androidx.annotation.AttrRes
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
@ -70,6 +71,15 @@ fun View.setAttributeTintedBackground(@DrawableRes drawableRes: Int, @AttrRes ti
|
||||||
background = drawable
|
background = drawable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun View.tintBackground(@ColorInt tintColor: Int) {
|
||||||
|
val bkg = background?.let {
|
||||||
|
val backgroundDrawable = DrawableCompat.wrap(background)
|
||||||
|
DrawableCompat.setTint(backgroundDrawable, tintColor)
|
||||||
|
backgroundDrawable
|
||||||
|
}
|
||||||
|
background = bkg
|
||||||
|
}
|
||||||
|
|
||||||
fun ImageView.setAttributeTintedImageResource(@DrawableRes drawableRes: Int, @AttrRes tint: Int) {
|
fun ImageView.setAttributeTintedImageResource(@DrawableRes drawableRes: Int, @AttrRes tint: Int) {
|
||||||
val drawable = ContextCompat.getDrawable(context, drawableRes)!!
|
val drawable = ContextCompat.getDrawable(context, drawableRes)!!
|
||||||
DrawableCompat.setTint(drawable, ThemeUtils.getColor(context, tint))
|
DrawableCompat.setTint(drawable, ThemeUtils.getColor(context, tint))
|
||||||
|
|
|
@ -24,9 +24,9 @@ import android.widget.ImageView
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.drawable.DrawableCompat
|
|
||||||
import androidx.core.view.setPadding
|
import androidx.core.view.setPadding
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
import im.vector.app.core.extensions.tintBackground
|
||||||
import im.vector.app.databinding.ViewLocationSharingOptionBinding
|
import im.vector.app.databinding.ViewLocationSharingOptionBinding
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,12 +61,7 @@ class LocationSharingOptionView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setIconBackgroundTint(@ColorInt color: Int) {
|
fun setIconBackgroundTint(@ColorInt color: Int) {
|
||||||
val bkg = binding.shareLocationOptionIcon.background?.let {
|
binding.shareLocationOptionIcon.tintBackground(color)
|
||||||
val backgroundDrawable = DrawableCompat.wrap(binding.shareLocationOptionIcon.background)
|
|
||||||
DrawableCompat.setTint(backgroundDrawable, color)
|
|
||||||
backgroundDrawable
|
|
||||||
}
|
|
||||||
binding.shareLocationOptionIcon.background = bkg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setIcon(typedArray: TypedArray) {
|
private fun setIcon(typedArray: TypedArray) {
|
||||||
|
@ -83,12 +78,8 @@ class LocationSharingOptionView @JvmOverloads constructor(
|
||||||
val description = typedArray.getString(R.styleable.LocationSharingOptionView_iconDescription)
|
val description = typedArray.getString(R.styleable.LocationSharingOptionView_iconDescription)
|
||||||
|
|
||||||
iconView.setImageDrawable(icon)
|
iconView.setImageDrawable(icon)
|
||||||
val bkg = background?.let {
|
iconView.background = background
|
||||||
val backgroundDrawable = DrawableCompat.wrap(it)
|
iconView.tintBackground(backgroundTint)
|
||||||
DrawableCompat.setTint(backgroundDrawable, backgroundTint)
|
|
||||||
backgroundDrawable
|
|
||||||
}
|
|
||||||
iconView.background = bkg
|
|
||||||
iconView.setPadding(padding)
|
iconView.setPadding(padding)
|
||||||
iconView.contentDescription = description
|
iconView.contentDescription = description
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue