From 73281871f94363cd66d07e604899fdd3ec918db5 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Thu, 15 Apr 2021 03:24:15 -0400 Subject: [PATCH] Using a blended accent for the selected color in spinner view --- .../kanade/tachiyomi/widget/MaterialSpinnerView.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt index db7d22482b..2a6f2f78da 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/MaterialSpinnerView.kt @@ -13,6 +13,7 @@ import androidx.annotation.StringRes import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.widget.PopupMenu import androidx.core.content.ContextCompat +import androidx.core.graphics.ColorUtils import androidx.core.view.forEach import androidx.core.view.get import com.tfcporciuncula.flow.Preference @@ -40,6 +41,12 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att binding.titleView.text = value } + val blendedAccent = ColorUtils.blendARGB( + context.getResourceColor(android.R.attr.colorAccent), + context.getResourceColor(android.R.attr.textColorPrimary), + 0.5f + ) + var onItemSelectedListener: ((Int) -> Unit)? = null set(value) { field = value @@ -94,7 +101,7 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att selectedPosition = selection popup?.menu?.get(selectedPosition)?.let { it.icon = tintedCheck() - it.title = it.title?.tintText(context.getResourceColor(android.R.attr.colorAccent)) + it.title = it.title?.tintText(blendedAccent) } binding.detailView.text = entries.getOrNull(selection).orEmpty() } @@ -220,7 +227,7 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att popup.menu.getItem(selectedPosition)?.let { menuItem -> menuItem.icon = tintedCheck() menuItem.title = - menuItem.title?.tintText(context.getResourceColor(android.R.attr.colorAccent)) + menuItem.title?.tintText(blendedAccent) } this.popup = popup return popup @@ -228,7 +235,7 @@ class MaterialSpinnerView @JvmOverloads constructor(context: Context, attrs: Att private fun tintedCheck(): Drawable? { return ContextCompat.getDrawable(context, R.drawable.ic_check_24dp)?.mutate()?.apply { - setTint(context.getResourceColor(android.R.attr.colorAccent)) + setTint(blendedAccent) } } }