Skip to content

Commit 4dc3b2e

Browse files
committed
Align the AppWidgets showcase entrypoint to highlight canonical layout samples.
The main "AppWidgets" page now displays link to the canonical layout showcase page and then below it, demonstrates the functionality to pin and show widget information.
1 parent 92e5cd4 commit 4dc3b2e

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

samples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Available Samples
22

33
- [App Widgets](user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/AppWidgets.kt):
4-
Showcases how to pin widget within the app. Check the launcher widget menu for all the app widgets samples
4+
Showcases how to pin widgets within the app and provides a catalog of well-designed canonical widget layouts for inspiration.
55
- [Call Notification Sample](connectivity/callnotification/src/main/java/com/example/platform/connectivity/callnotification/CallNotificationSample.kt):
66
Sample demonstrating how to make incoming call notifications and in call notifications
77
- [Camera Preview](camera/camera2/src/main/java/com/example/platform/camera/preview/Camera2Preview.kt):

samples/user-interface/appwidgets/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
<receiver
157157
android:name=".rv.weather.WeatherForecastAppWidget"
158158
android:enabled="@bool/weather_appwidget_enabled"
159+
android:label="@string/remote_views_weather"
159160
android:exported="false">
160161
<intent-filter>
161162
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

samples/user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/AppWidgets.kt

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import android.content.Context
2323
import android.content.Intent
2424
import android.os.Build
2525
import androidx.annotation.RequiresApi
26+
import androidx.annotation.StringRes
2627
import androidx.compose.foundation.Image
2728
import androidx.compose.foundation.background
2829
import androidx.compose.foundation.layout.Arrangement
@@ -33,7 +34,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
3334
import androidx.compose.foundation.layout.padding
3435
import androidx.compose.foundation.lazy.LazyColumn
3536
import androidx.compose.foundation.lazy.items
36-
import androidx.compose.material3.Button
3737
import androidx.compose.material3.Card
3838
import androidx.compose.material3.ExperimentalMaterial3Api
3939
import androidx.compose.material3.MaterialTheme
@@ -43,13 +43,14 @@ import androidx.compose.ui.Modifier
4343
import androidx.compose.ui.platform.LocalContext
4444
import androidx.compose.ui.res.painterResource
4545
import androidx.compose.ui.res.stringResource
46+
import androidx.compose.ui.text.font.FontWeight
4647
import androidx.compose.ui.unit.dp
4748
import com.example.platform.ui.appwidgets.glance.layout.CanonicalLayoutActivity
4849
import com.google.android.catalog.framework.annotations.Sample
4950

5051
@Sample(
5152
name = "App Widgets",
52-
description = "Showcases how to pin widget within the app. Check the launcher widget menu for all the app widgets samples",
53+
description = "Showcases how to pin widgets within the app and provides a catalog of well-designed canonical widget layouts for inspiration.",
5354
documentation = "https://developer.android.com/develop/ui/views/appwidgets/overview",
5455
tags = ["App Widgets"],
5556
)
@@ -76,11 +77,18 @@ fun AppWidgetsList(widgetProviders: List<AppWidgetProviderInfo>) {
7677
verticalArrangement = Arrangement.spacedBy(16.dp),
7778
) {
7879
item {
79-
AppInfoText()
80+
InfoText(R.string.placeholder_pin_app_widget)
8081
}
8182

8283
item {
83-
CanonicalLayoutsRow()
84+
InfoText(
85+
resId = R.string.placeholder_tap_to_add_to_home,
86+
fontWeight = FontWeight.SemiBold
87+
)
88+
}
89+
90+
item {
91+
CanonicalLayoutPinActivityCard()
8492
}
8593

8694
// If the launcher does not support pinning request show a banner
@@ -90,17 +98,41 @@ fun AppWidgetsList(widgetProviders: List<AppWidgetProviderInfo>) {
9098
}
9199
}
92100

101+
item {
102+
InfoText(
103+
resId = R.string.placeholder_tap_to_pin,
104+
fontWeight = FontWeight.SemiBold
105+
)
106+
}
107+
93108
items(widgetProviders) { providerInfo ->
94109
WidgetInfoCard(providerInfo)
95110
}
96111
}
97112
}
98113

99114
@Composable
100-
private fun CanonicalLayoutsRow() {
115+
private fun CanonicalLayoutPinActivityCard() {
101116
val context = LocalContext.current
102-
Button(onClick = { CanonicalLayoutActivity.start(context) }) {
103-
Text("Canonical layout examples")
117+
Card(
118+
modifier = Modifier
119+
.fillMaxWidth(),
120+
onClick = { CanonicalLayoutActivity.start(context) },
121+
) {
122+
val preview = painterResource(id = R.drawable.cl_activity_row_hero_image)
123+
Column(modifier = Modifier.padding(16.dp)) {
124+
Text(
125+
text = "☆ Canonical widget layouts",
126+
style = MaterialTheme.typography.titleMedium,
127+
fontWeight = FontWeight.Bold
128+
)
129+
Text(
130+
text = "Explore and pin the recommended, intentionally designed widget samples",
131+
style = MaterialTheme.typography.bodyMedium,
132+
maxLines = 3,
133+
)
134+
Image(painter = preview, contentDescription = null)
135+
}
104136
}
105137
}
106138

@@ -142,9 +174,13 @@ private fun PinUnavailableBanner() {
142174
}
143175

144176
@Composable
145-
private fun AppInfoText() {
177+
private fun InfoText(
178+
@StringRes resId: Int,
179+
fontWeight: FontWeight = FontWeight.Normal
180+
) {
146181
Text(
147-
text = stringResource(id = R.string.placeholder_app_widget),
182+
text = stringResource(id = resId),
183+
fontWeight = fontWeight,
148184
modifier = Modifier
149185
.fillMaxWidth(),
150186
)
@@ -183,7 +219,8 @@ private fun WidgetInfoCard(providerInfo: AppWidgetProviderInfo) {
183219
Column(modifier = Modifier.padding(end = 8.dp)) {
184220
Text(
185221
text = label,
186-
style = MaterialTheme.typography.titleSmall,
222+
style = MaterialTheme.typography.titleMedium,
223+
fontWeight = FontWeight.Bold
187224
)
188225
Text(
189226
text = description,

samples/user-interface/appwidgets/src/main/res/values/strings.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
<string name="app_name">AppWidget</string>
1818
<string name="placeholder_app_widget_pin">Pin an App Widget:</string>
1919
<string name="placeholder_app_widget_pin_unavailable">Pinning is not supported in the default launcher</string>
20-
<string name="placeholder_app_widget">Sample to demonstrate how to get the app\'s appwidgets info and request the user to pin them in the launcher.\n\nTap any of the items below to request the launcher to pin them:</string>
21-
22-
<string name="weather">Weather</string>
20+
<string name="placeholder_pin_app_widget">Sample to demonstrate how to get the app\'s appwidgets info and request the user to pin them in the launcher.</string>
21+
<string name="placeholder_tap_to_add_to_home">Tap \"Add to home\" button on any of the items in the canonical widget layouts demo page to pin:</string>
22+
<string name="placeholder_tap_to_pin">Or tap on any of the items below to request the launcher to pin them:</string>
23+
<string name="remote_views_weather">RemoteViews Weather</string>
2324
<string name="glance_weather">Glance Weather</string>
2425
<string name="app_widget_weather_description">Widget for weather forecast</string>
25-
<string name="glance_widget_weather_description">Glance Widget for weather forecast</string>
2626
<string name="icon_for_weather_content_description">Icon for weather</string>
2727
<string name="city_tokyo">Tokyo</string>
2828
<string name="mostly_cloudy">Mostly cloudy</string>

0 commit comments

Comments
 (0)