Skip to content

Commit 584b9d6

Browse files
[Crane] Use strings from resources for semantics
1 parent 4b88b09 commit 584b9d6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Crane/app/src/main/java/androidx/compose/samples/crane/calendar/Calendar.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import androidx.compose.material.MaterialTheme
3636
import androidx.compose.material.Surface
3737
import androidx.compose.material.Text
3838
import androidx.compose.runtime.Composable
39+
import androidx.compose.samples.crane.R
3940
import androidx.compose.samples.crane.calendar.model.CalendarDay
4041
import androidx.compose.samples.crane.calendar.model.CalendarMonth
4142
import androidx.compose.samples.crane.calendar.model.DayOfWeek
@@ -48,6 +49,7 @@ import androidx.compose.samples.crane.util.SemiRect
4849
import androidx.compose.ui.Alignment
4950
import androidx.compose.ui.Modifier
5051
import androidx.compose.ui.graphics.Color
52+
import androidx.compose.ui.res.stringResource
5153
import androidx.compose.ui.semantics.SemanticsPropertyKey
5254
import androidx.compose.ui.semantics.SemanticsPropertyReceiver
5355
import androidx.compose.ui.semantics.clearAndSetSemantics
@@ -150,7 +152,7 @@ private fun Day(
150152
onClick = { onDayClicked(day) },
151153
onClickEnabled = enabled,
152154
backgroundColor = day.status.color(MaterialTheme.colors),
153-
onClickLabel = "select"
155+
onClickLabel = stringResource(id = R.string.click_label_select)
154156
) {
155157
DayStatusContainer(status = day.status) {
156158
Text(
@@ -189,13 +191,16 @@ private fun DayContainer(
189191
content: @Composable () -> Unit
190192
) {
191193
// What if this doesn't fit the screen? - LayoutFlexible(1f) + LayoutAspectRatio(1f)
194+
val stateDescriptionLabel = stringResource(
195+
if (selected) R.string.state_descr_selected else R.string.state_descr_not_selected
196+
)
192197
Surface(
193198
modifier = modifier
194199
.size(width = CELL_SIZE, height = CELL_SIZE)
195200
.then(
196201
if (onClickEnabled) {
197202
modifier.semantics {
198-
stateDescription = if (selected) "Selected" else "Not selected"
203+
stateDescription = stateDescriptionLabel
199204
}
200205
} else {
201206
modifier.clearAndSetSemantics { }

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@
2121
<string name="cd_back">Back</string>
2222
<string name="cd_loading">Loading</string>
2323
<string name="cd_drawer">Open drawer</string>
24+
<string name="click_label_select">select</string>
25+
<string name="state_descr_selected">Selected</string>
26+
<string name="state_descr_not_selected">Not selected</string>
2427
</resources>

0 commit comments

Comments
 (0)