カラーピッカーの文字列解釈を変更

This commit is contained in:
tateisu 2021-11-22 08:19:40 +09:00
parent 8241a6f377
commit 422e21c28a
2 changed files with 4 additions and 4 deletions

View File

@ -16,8 +16,8 @@ class TestColorString {
assertEquals("#$s", expect, parseColorString("#$s"))
}
a("", Color.BLACK)
a("8", Color.BLACK or 0x00_00_88)
a("56", Color.BLACK or 0x00_00_56)
a("8", Color.BLACK or 0x88_88_88)
a("56", Color.BLACK or 0x55_66_00)
a("123", Color.BLACK or 0x11_22_33)
a("1234", 0x11_22_33_44)
a("12345", Color.BLACK or 0x12_34_55)

View File

@ -14,8 +14,8 @@ fun parseColorString(src: String): Int {
return when (src.length - start) {
0 -> Color.BLACK
1 -> Color.argb(255, 0, 0, c1(0))
2 -> Color.argb(255, 0, 0, c2(0))
1 -> Color.argb(255, c1(0), c1(0), c1(0))
2 -> Color.argb(255, c1(0), c1(1), 0)
3 -> Color.argb(255, c1(0), c1(1), c1(2))
4 -> Color.argb(c1(0), c1(1), c1(2), c1(3))
5 -> Color.argb(255, c2(0), c2(2), c1(4))