Change colors for selected/active messages in the message list
We can't use semi-transparent colors because the message list item backgrounds are drawn on top of other colors when using swipe actions. Instead, we mix the colors ourselves, e.g. 60% of ?attr/colorSecondaryVariant on ?attr/colorSurface
This commit is contained in:
parent
9bed86a636
commit
6244ea6573
4 changed files with 55 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
package com.fsck.k9.ui
|
||||
|
||||
import android.content.res.Resources.Theme
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.TypedValue
|
||||
|
||||
|
@ -15,6 +16,32 @@ fun Theme.resolveColorAttribute(attrId: Int): Int {
|
|||
return typedValue.data
|
||||
}
|
||||
|
||||
fun Theme.resolveColorAttribute(colorAttrId: Int, alphaFractionAttrId: Int, backgroundColorAttrId: Int): Int {
|
||||
val typedValue = TypedValue()
|
||||
|
||||
if (!resolveAttribute(colorAttrId, typedValue, true)) {
|
||||
error("Couldn't resolve attribute ($colorAttrId)")
|
||||
}
|
||||
val color = typedValue.data
|
||||
|
||||
if (!resolveAttribute(alphaFractionAttrId, typedValue, true)) {
|
||||
error("Couldn't resolve attribute ($alphaFractionAttrId)")
|
||||
}
|
||||
val colorPercentage = TypedValue.complexToFloat(typedValue.data)
|
||||
val backgroundPercentage = 1 - colorPercentage
|
||||
|
||||
if (!resolveAttribute(backgroundColorAttrId, typedValue, true)) {
|
||||
error("Couldn't resolve attribute ($colorAttrId)")
|
||||
}
|
||||
val backgroundColor = typedValue.data
|
||||
|
||||
val red = colorPercentage * Color.red(color) + backgroundPercentage * Color.red(backgroundColor)
|
||||
val green = colorPercentage * Color.green(color) + backgroundPercentage * Color.green(backgroundColor)
|
||||
val blue = colorPercentage * Color.blue(color) + backgroundPercentage * Color.blue(backgroundColor)
|
||||
|
||||
return Color.rgb(red.toInt(), green.toInt(), blue.toInt())
|
||||
}
|
||||
|
||||
fun Theme.resolveDrawableAttribute(attrId: Int): Drawable {
|
||||
val typedValue = TypedValue()
|
||||
|
||||
|
|
|
@ -51,8 +51,16 @@ class MessageListAdapter internal constructor(
|
|||
private val answeredIcon: Drawable = theme.resolveDrawableAttribute(R.attr.messageListAnswered)
|
||||
private val forwardedAnsweredIcon: Drawable = theme.resolveDrawableAttribute(R.attr.messageListAnsweredForwarded)
|
||||
private val previewTextColor: Int = theme.resolveColorAttribute(R.attr.messageListPreviewTextColor)
|
||||
private val activeItemBackgroundColor: Int = theme.resolveColorAttribute(R.attr.messageListActiveItemBackgroundColor)
|
||||
private val selectedItemBackgroundColor: Int = theme.resolveColorAttribute(R.attr.messageListSelectedBackgroundColor)
|
||||
private val activeItemBackgroundColor: Int = theme.resolveColorAttribute(
|
||||
colorAttrId = R.attr.messageListActiveItemBackgroundColor,
|
||||
alphaFractionAttrId = R.attr.messageListActiveItemBackgroundAlphaFraction,
|
||||
backgroundColorAttrId = R.attr.messageListActiveItemBackgroundAlphaBackground
|
||||
)
|
||||
private val selectedItemBackgroundColor: Int = theme.resolveColorAttribute(
|
||||
colorAttrId = R.attr.messageListSelectedBackgroundColor,
|
||||
alphaFractionAttrId = R.attr.messageListSelectedBackgroundAlphaFraction,
|
||||
backgroundColorAttrId = R.attr.messageListSelectedBackgroundAlphaBackground
|
||||
)
|
||||
private val regularItemBackgroundColor: Int = theme.resolveColorAttribute(R.attr.messageListRegularItemBackgroundColor)
|
||||
private val readItemBackgroundColor: Int = theme.resolveColorAttribute(R.attr.messageListReadItemBackgroundColor)
|
||||
private val unreadItemBackgroundColor: Int = theme.resolveColorAttribute(R.attr.messageListUnreadItemBackgroundColor)
|
||||
|
|
|
@ -69,12 +69,16 @@
|
|||
<attr name="backgroundColorChooseAccountHeader" format="color" />
|
||||
<attr name="messageListSelectedCheckMarkColor" format="reference|color"/>
|
||||
<attr name="messageListSelectedBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListSelectedBackgroundAlphaFraction" format="fraction"/>
|
||||
<attr name="messageListSelectedBackgroundAlphaBackground" format="reference|color"/>
|
||||
<attr name="messageListRegularItemBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListReadItemBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListUnreadItemBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListThreadCountForegroundColor" format="reference|color"/>
|
||||
<attr name="messageListThreadCountBackground" format="reference|color"/>
|
||||
<attr name="messageListActiveItemBackgroundColor" format="reference|color"/>
|
||||
<attr name="messageListActiveItemBackgroundAlphaFraction" format="fraction"/>
|
||||
<attr name="messageListActiveItemBackgroundAlphaBackground" format="reference|color"/>
|
||||
<attr name="messageListPreviewTextColor" format="reference|color"/>
|
||||
<attr name="messageListDividerColor" format="reference|color"/>
|
||||
<attr name="messageListStateIconTint" format="reference|color"/>
|
||||
|
|
|
@ -89,14 +89,18 @@
|
|||
<item name="iconSettingsImportStatus">@drawable/ic_import_status</item>
|
||||
<item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_light</item>
|
||||
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_light</item>
|
||||
<item name="messageListSelectedCheckMarkColor">#ff1976d2</item>
|
||||
<item name="messageListSelectedBackgroundColor">#ff99d9ee</item>
|
||||
<item name="messageListSelectedCheckMarkColor">?attr/colorSecondary</item>
|
||||
<item name="messageListSelectedBackgroundColor">?attr/colorSecondaryVariant</item>
|
||||
<item name="messageListSelectedBackgroundAlphaFraction">33%</item>
|
||||
<item name="messageListSelectedBackgroundAlphaBackground">?attr/colorSurface</item>
|
||||
<item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
|
||||
<item name="messageListReadItemBackgroundColor">#ffd8d8d8</item>
|
||||
<item name="messageListUnreadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
|
||||
<item name="messageListThreadCountForegroundColor">?android:attr/colorBackground</item>
|
||||
<item name="messageListThreadCountBackground">@drawable/thread_count_box_light</item>
|
||||
<item name="messageListActiveItemBackgroundColor">#ff2ea7d1</item>
|
||||
<item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
|
||||
<item name="messageListActiveItemBackgroundAlphaFraction">60%</item>
|
||||
<item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>
|
||||
<item name="messageListPreviewTextColor">#ff696969</item>
|
||||
<item name="messageListDividerColor">#ffcccccc</item>
|
||||
<item name="messageListStateIconTint">#bbbbbb</item>
|
||||
|
@ -245,14 +249,18 @@
|
|||
<item name="iconSettingsImportStatus">@drawable/ic_import_status</item>
|
||||
<item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_dark</item>
|
||||
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_dark</item>
|
||||
<item name="messageListSelectedCheckMarkColor">#ff1976d2</item>
|
||||
<item name="messageListSelectedBackgroundColor">#ff347489</item>
|
||||
<item name="messageListSelectedCheckMarkColor">?attr/colorSecondary</item>
|
||||
<item name="messageListSelectedBackgroundColor">?attr/colorSecondaryVariant</item>
|
||||
<item name="messageListSelectedBackgroundAlphaFraction">25%</item>
|
||||
<item name="messageListSelectedBackgroundAlphaBackground">?attr/colorSurface</item>
|
||||
<item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
|
||||
<item name="messageListReadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
|
||||
<item name="messageListUnreadItemBackgroundColor">#ff505050</item>
|
||||
<item name="messageListThreadCountForegroundColor">?android:attr/colorBackground</item>
|
||||
<item name="messageListThreadCountBackground">@drawable/thread_count_box_dark</item>
|
||||
<item name="messageListActiveItemBackgroundColor">#ff33b5e5</item>
|
||||
<item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
|
||||
<item name="messageListActiveItemBackgroundAlphaFraction">50%</item>
|
||||
<item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>
|
||||
<item name="messageListPreviewTextColor">#ffa0a0a0</item>
|
||||
<item name="messageListDividerColor">#ff333333</item>
|
||||
<item name="messageListStateIconTint">#777777</item>
|
||||
|
|
Loading…
Reference in a new issue