Skip to content

Commit 7f9f482

Browse files
committed
Make coin flip count subtitle
1 parent bbcc1a2 commit 7f9f482

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

app/src/main/java/com/wstxda/toolkit/tiles/CoinFlipTileService.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ import kotlin.random.Random
1111

1212
class CoinFlipTileService : TileService() {
1313

14+
companion object {
15+
private var headsCount = 0
16+
private var tailsCount = 0
17+
}
18+
1419
override fun onStartListening() {
20+
}
21+
22+
override fun onStopListening() {
1523
setInactive()
1624
}
1725

@@ -24,29 +32,33 @@ class CoinFlipTileService : TileService() {
2432
}
2533

2634
private fun setHeads() {
35+
headsCount++
2736
qsTile?.update {
2837
state = Tile.STATE_ACTIVE
2938
label = getString(R.string.coin_heads_label)
3039
if (VERSION.SDK_INT >= VERSION_CODES.Q) {
31-
subtitle = getString(R.string.coin_flip_tile_label)
40+
subtitle = getString(R.string.coin_flip_count, headsCount, tailsCount)
3241
}
3342
icon = Icon.createWithResource(applicationContext, R.drawable.ic_coin_heads)
3443
}
3544
}
3645

3746
private fun setTails() {
47+
tailsCount++
3848
qsTile?.update {
3949
state = Tile.STATE_ACTIVE
4050
label = getString(R.string.coin_tails_label)
4151
if (VERSION.SDK_INT >= VERSION_CODES.Q) {
42-
subtitle = getString(R.string.coin_flip_tile_label)
52+
subtitle = getString(R.string.coin_flip_count, headsCount, tailsCount)
4353
}
4454
icon = Icon.createWithResource(applicationContext, R.drawable.ic_coin_tails)
4555
}
4656
}
4757

4858
private fun setInactive() {
4959
qsTile?.update {
60+
headsCount = 0
61+
tailsCount = 0
5062
state = Tile.STATE_INACTIVE
5163
label = getString(R.string.coin_flip_tile_label)
5264
if (VERSION.SDK_INT >= VERSION_CODES.Q) {

app/src/main/res/drawable/ic_coin_heads.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
android:viewportHeight="960">
77
<path
88
android:fillColor="@android:color/white"
9-
android:pathData="M360,570Q339,570 324.5,555.5Q310,541 310,520Q310,499 324.5,484.5Q339,470 360,470Q381,470 395.5,484.5Q410,499 410,520Q410,541 395.5,555.5Q381,570 360,570ZM600,570Q579,570 564.5,555.5Q550,541 550,520Q550,499 564.5,484.5Q579,470 600,470Q621,470 635.5,484.5Q650,499 650,520Q650,541 635.5,555.5Q621,570 600,570ZM480,800Q614,800 707,707Q800,614 800,480Q800,456 797,433.5Q794,411 786,390Q765,395 744,397.5Q723,400 700,400Q609,400 528,361Q447,322 390,252Q358,330 298.5,387.5Q239,445 160,474Q160,476 160,477Q160,478 160,480Q160,614 253,707Q346,800 480,800ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM426,165Q468,235 540,277.5Q612,320 700,320Q714,320 727,318.5Q740,317 754,315Q712,245 640,202.5Q568,160 480,160Q466,160 453,161.5Q440,163 426,165ZM177,379Q228,350 266,304Q304,258 323,201Q272,230 234,276Q196,322 177,379ZM426,165Q426,165 426,165Q426,165 426,165Q426,165 426,165Q426,165 426,165Q426,165 426,165Q426,165 426,165Q426,165 426,165Q426,165 426,165ZM323,201Q323,201 323,201Q323,201 323,201Q323,201 323,201Q323,201 323,201Z" />
9+
android:pathData="M360,570Q339,570 324.5,555.5Q310,541 310,520Q310,499 324.5,484.5Q339,470 360,470Q381,470 395.5,484.5Q410,499 410,520Q410,541 395.5,555.5Q381,570 360,570ZM600,570Q579,570 564.5,555.5Q550,541 550,520Q550,499 564.5,484.5Q579,470 600,470Q621,470 635.5,484.5Q650,499 650,520Q650,541 635.5,555.5Q621,570 600,570ZM480,800Q614,800 707,707Q800,614 800,480Q800,456 797,433.5Q794,411 786,390Q765,395 744,397.5Q723,400 700,400Q609,400 528,361Q447,322 390,252Q358,330 298.5,387.5Q239,445 160,474Q160,476 160,477Q160,478 160,480Q160,614 253,707Q346,800 480,800ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880Z" />
1010
</vector>

app/src/main/res/drawable/ic_coin_tails.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
android:viewportHeight="960">
77
<path
88
android:fillColor="@android:color/white"
9-
android:pathData="M200,800L200,720L760,720L760,800L200,800ZM200,660L149,339Q147,339 144.5,339.5Q142,340 140,340Q115,340 97.5,322.5Q80,305 80,280Q80,255 97.5,237.5Q115,220 140,220Q165,220 182.5,237.5Q200,255 200,280Q200,287 198.5,293Q197,299 195,304L320,360L445,189Q434,181 427,168Q420,155 420,140Q420,115 437.5,97.5Q455,80 480,80Q505,80 522.5,97.5Q540,115 540,140Q540,155 533,168Q526,181 515,189L640,360L765,304Q763,299 761.5,293Q760,287 760,280Q760,255 777.5,237.5Q795,220 820,220Q845,220 862.5,237.5Q880,255 880,280Q880,305 862.5,322.5Q845,340 820,340Q818,340 815.5,339.5Q813,339 811,339L760,660L200,660ZM268,580L692,580L718,413L613,459L480,276L347,459L242,413L268,580ZM480,580L480,580L480,580L480,580L480,580L480,580L480,580Z" />
9+
android:pathData="M480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM360,680L520,680Q553,680 576.5,656.5Q600,633 600,600L600,520Q600,487 576.5,463.5Q553,440 520,440L440,440L440,360L600,360L600,280L360,280L360,520L520,520Q520,520 520,520Q520,520 520,520L520,600Q520,600 520,600Q520,600 520,600L360,600L360,680Z" />
1010
</vector>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@
5656
<!--tile label-->
5757
<string name="coin_heads_label">Heads</string>
5858
<string name="coin_tails_label">Tails</string>
59+
<string name="coin_flip_count">Heads: %1$d Tails: %2$d</string>
5960
</resources>

0 commit comments

Comments
 (0)