A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
0

Configure Feed

Select the types of activity you want to include in your feed.

add icon image and text support

authored by

razeeman and committed by
Joseph Hale
(Feb 26, 2024, 10:27 PM -0700) 4e72792a 75a5a448

+105 -10
+2
wear/build.gradle.kts
··· 66 66 implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1") 67 67 implementation("androidx.compose.material:material-icons-core:1.6.1") 68 68 implementation(project(":wearrpc")) 69 + implementation(project(":resources")) 69 70 70 71 // Dev Dependencies 71 72 implementation("androidx.wear:wear-tooling-preview:1.0.0") ··· 82 83 implementation("androidx.compose.ui:ui-tooling-preview:$compose_version") 83 84 implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1") 84 85 implementation("androidx.activity:activity-compose:1.3.1") 86 + implementation("androidx.appcompat:appcompat:1.6.0") 85 87 androidTestImplementation("androidx.compose.ui:ui-test-junit4:$compose_version") 86 88 debugImplementation("androidx.compose.ui:ui-tooling:$compose_version") 87 89 debugImplementation("androidx.compose.ui:ui-test-manifest:$compose_version")
+29 -10
wear/src/main/java/com/example/util/simpletimetracker/presentation/components/ActivityChip.kt
··· 5 5 */ 6 6 package com.example.util.simpletimetracker.presentation.components 7 7 8 + import androidx.compose.foundation.layout.IntrinsicSize 9 + import androidx.compose.foundation.layout.Row 8 10 import androidx.compose.foundation.layout.fillMaxWidth 11 + import androidx.compose.foundation.layout.height 9 12 import androidx.compose.foundation.layout.padding 10 13 import androidx.compose.runtime.Composable 11 14 import androidx.compose.ui.Modifier ··· 37 40 onToggleOn: () -> Unit = {}, 38 41 onToggleOff: () -> Unit = {}, 39 42 ) { 40 - val briefIcon = if (activity.icon.startsWith("ic_")) { 41 - "?" 42 - } else { 43 - activity.icon.substring(0, activity.icon.length.coerceAtMost(2)) 44 - } 45 43 val tagsList = if (tags.isNotEmpty()) { 46 44 tags.joinToString(", ") { it.name } 47 45 } else { ··· 58 56 .fillMaxWidth(0.9f) 59 57 .padding(top = 10.dp), 60 58 label = { 61 - Text( 62 - text = "$briefIcon : ${activity.name}" + tagString, 63 - maxLines = 1, 64 - overflow = TextOverflow.Ellipsis, 65 - ) 59 + Row( 60 + modifier = Modifier 61 + .height(IntrinsicSize.Min), 62 + ) { 63 + ActivityIcon( 64 + activityIcon = activity.icon, 65 + ) 66 + Text( 67 + text = activity.name + tagString, 68 + maxLines = 1, 69 + overflow = TextOverflow.Ellipsis, 70 + modifier = Modifier.padding(start = 2.dp) 71 + ) 72 + } 66 73 }, 67 74 secondaryLabel = { 68 75 if (startedAt != null) { ··· 130 137 @Composable 131 138 fun SampleSleep() { 132 139 ActivityChip(Activity(456, "Sleeping", "🛏️", 0xFFABCDEF)) 140 + } 141 + 142 + @Preview(device = WearDevices.LARGE_ROUND) 143 + @Composable 144 + fun SampleText() { 145 + ActivityChip(Activity(456, "Sleeping", "Zzzz", 0xFFABCDEF)) 146 + } 147 + 148 + @Preview(device = WearDevices.LARGE_ROUND) 149 + @Composable 150 + fun SampleIcon() { 151 + ActivityChip(Activity(456, "Sleeping", "ic_hotel_24px", 0xFFABCDEF)) 133 152 } 134 153 135 154 @Preview(device = WearDevices.LARGE_ROUND)
+65
wear/src/main/java/com/example/util/simpletimetracker/presentation/components/ActivityIcon.kt
··· 1 + package com.example.util.simpletimetracker.presentation.components 2 + 3 + import android.util.TypedValue 4 + import android.view.Gravity 5 + import androidx.appcompat.widget.AppCompatTextView 6 + import androidx.compose.foundation.layout.aspectRatio 7 + import androidx.compose.foundation.layout.fillMaxHeight 8 + import androidx.compose.foundation.layout.height 9 + import androidx.compose.foundation.layout.width 10 + import androidx.compose.runtime.Composable 11 + import androidx.compose.ui.Modifier 12 + import androidx.compose.ui.graphics.toArgb 13 + import androidx.compose.ui.platform.LocalContext 14 + import androidx.compose.ui.res.painterResource 15 + import androidx.compose.ui.unit.dp 16 + import androidx.compose.ui.viewinterop.AndroidView 17 + import androidx.core.widget.TextViewCompat 18 + import androidx.wear.compose.material.Icon 19 + import androidx.wear.compose.material.LocalContentColor 20 + import com.example.util.simpletimetracker.R 21 + 22 + @Composable 23 + fun ActivityIcon( 24 + activityIcon: String, 25 + ) { 26 + val context = LocalContext.current 27 + val iconIsImage = activityIcon.startsWith("ic_") 28 + 29 + if (iconIsImage) { 30 + val iconDrawableRes = context.resources 31 + .getIdentifier(activityIcon, "drawable", context.packageName) 32 + .takeIf { it != 0 } 33 + ?: R.drawable.unknown 34 + Icon( 35 + painter = painterResource(iconDrawableRes), 36 + contentDescription = null, 37 + modifier = Modifier 38 + .fillMaxHeight() 39 + .height(1.dp), 40 + ) 41 + } else { 42 + val textColor = LocalContentColor.current.toArgb() 43 + AndroidView( 44 + factory = { context -> 45 + val view = AppCompatTextView(context) 46 + view.gravity = Gravity.CENTER 47 + view.setTextColor(textColor) 48 + TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration( 49 + view, 50 + 1, 51 + 100, 52 + 1, 53 + TypedValue.COMPLEX_UNIT_SP, 54 + ) 55 + view 56 + }, 57 + modifier = Modifier 58 + .aspectRatio(1f) 59 + .width(0.dp), 60 + update = { 61 + it.text = activityIcon 62 + }, 63 + ) 64 + } 65 + }
+9
wear/src/main/res/drawable/unknown.xml
··· 1 + <vector xmlns:android="http://schemas.android.com/apk/res/android" 2 + android:width="24dp" 3 + android:height="24dp" 4 + android:viewportWidth="24" 5 + android:viewportHeight="24"> 6 + <path 7 + android:fillColor="#FF000000" 8 + android:pathData="M10,19H13V22H10V19M12,2C17.35,2.22 19.68,7.62 16.5,11.67C15.67,12.67 14.33,13.33 13.67,14.17C13,15 13,16 13,17H10C10,15.33 10,13.92 10.67,12.92C11.33,11.92 12.67,11.33 13.5,10.67C15.92,8.43 15.32,5.26 12,5A3,3 0,0 0,9 8H6A6,6 0,0 1,12 2Z"/> 9 + </vector>