File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
AnkiDroid/src/main/java/com/ichi2/anki/browser
common/src/main/java/com/ichi2/anki/utils/android Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,9 @@ import com.ichi2.anki.AnkiDroidApp.Companion.sharedPrefs
38
38
import com.ichi2.anki.Flag
39
39
import com.ichi2.anki.R
40
40
import com.ichi2.anki.utils.android.darkenColor
41
+ import com.ichi2.anki.utils.android.lightenColorAbsolute
41
42
import com.ichi2.anki.utils.ext.findViewById
43
+ import com.ichi2.annotations.NeedsTest
42
44
import net.ankiweb.rsdroid.BackendException
43
45
import timber.log.Timber
44
46
import kotlin.math.abs
@@ -119,10 +121,19 @@ class BrowserMultiColumnAdapter(
119
121
checkBoxView.isChecked = value
120
122
}
121
123
124
+ @NeedsTest(" 17731 - maybe check all activities load in dark mode, at least check this code" )
122
125
fun setColor (
123
126
@ColorInt color : Int ,
124
127
) {
125
- val pressedColor = darkenColor(color, 0.85f )
128
+ var pressedColor = darkenColor(color, 0.85f )
129
+
130
+ if (pressedColor == color) {
131
+ // if the color is black, we can't darken it.
132
+ // A non-black background looks unusual, so the 'press' should lighten the color
133
+
134
+ // 25% was determined by visual inspection
135
+ pressedColor = lightenColorAbsolute(pressedColor, 0.25f )
136
+ }
126
137
127
138
require(pressedColor != color)
128
139
val rippleDrawable =
Original file line number Diff line number Diff line change @@ -39,6 +39,25 @@ fun darkenColor(
39
39
return Color .HSVToColor (hsv)
40
40
}
41
41
42
+ /* *
43
+ * Lightens the provided ARGB color by a provided [amount]
44
+ *
45
+ * @param argb The ARGB color to transform
46
+ * @param amount Amount to lighten, between 0.0f (no change) and 1.0f (100% brightness)
47
+ * @return The lightened color in ARGB
48
+ */
49
+ @ColorInt
50
+ fun lightenColorAbsolute (
51
+ @ColorInt argb : Int ,
52
+ amount : Float ,
53
+ ): Int {
54
+ val hsv = argb.toHSV()
55
+ // https://en.wikipedia.org/wiki/HSL_and_HSV
56
+ // The third component is the 'value', or 'lightness/darkness'
57
+ hsv[2 ] = (hsv[2 ] + amount).clamp(0f , 1f )
58
+ return Color .HSVToColor (hsv)
59
+ }
60
+
42
61
/* *
43
62
* Converts an ARGB color to an array of its HSV components
44
63
*
You can’t perform that action at this time.
0 commit comments