Skip to content

Commit b65b902

Browse files
authored
Merge pull request #280 from shamalip/main
Add an expressive 4-side cookie cut shaped toolbar layout sample using Glance
2 parents 902592b + 5a1994e commit b65b902

14 files changed

+635
-0
lines changed

Diff for: samples/user-interface/appwidgets/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The `layouts` directory contains following layout categories:
4141
* [toolbars](./src/main/java/com/example/platform/ui/appwidgets/glance/layout/toolbars)
4242
* [Toolbar with app name](./src/main/java/com/example/platform/ui/appwidgets/glance/layout/toolbars/ToolBarAppWidget.kt)
4343
* [Toolbar with search bar](./src/main/java/com/example/platform/ui/appwidgets/glance/layout/toolbars/SearchToolBarAppWidget.kt)
44+
* [Toolbar with expressive shape](./src/main/java/com/example/platform/ui/appwidgets/glance/layout/toolbars/ExpressiveToolbarAppWidget.kt)
4445

4546
Each of these layout categories contains a `layout` sub-directory that can be copied to your project
4647
to reuse the layouts in your code.

Diff for: samples/user-interface/appwidgets/src/main/AndroidManifest.xml

+15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@
3333

3434
<!-- Toolbar variants -->
3535

36+
<!-- Expressive Toolbar with a 4-sided cookie cut shape -->
37+
<receiver
38+
android:name=".glance.layout.toolbars.ExpressiveToolbarAppWidgetReceiver"
39+
android:enabled="@bool/glance_appwidget_available"
40+
android:exported="false"
41+
android:label="@string/sample_expressive_toolbar_app_widget_name">
42+
<intent-filter>
43+
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
44+
<action android:name="android.intent.action.LOCALE_CHANGED" />
45+
</intent-filter>
46+
<meta-data
47+
android:name="android.appwidget.provider"
48+
android:resource="@xml/sample_expressive_toolbar_widget_info" />
49+
</receiver>
50+
3651
<!-- Toolbar with header -->
3752
<receiver
3853
android:name=".glance.layout.toolbars.ToolBarAppWidgetReceiver"

Diff for: samples/user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/glance/layout/CanonicalLayoutActivity.kt

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import com.example.platform.ui.appwidgets.glance.layout.collections.ImageGridApp
5353
import com.example.platform.ui.appwidgets.glance.layout.collections.ImageTextListAppWidgetReceiver
5454
import com.example.platform.ui.appwidgets.glance.layout.text.LongTextAppWidgetReceiver
5555
import com.example.platform.ui.appwidgets.glance.layout.text.TextWithImageAppWidgetReceiver
56+
import com.example.platform.ui.appwidgets.glance.layout.toolbars.ExpressiveToolbarAppWidgetReceiver
5657
import com.example.platform.ui.appwidgets.glance.layout.toolbars.SearchToolBarAppWidgetReceiver
5758
import com.example.platform.ui.appwidgets.glance.layout.toolbars.ToolBarAppWidgetReceiver
5859
import kotlinx.coroutines.CoroutineScope
@@ -304,4 +305,10 @@ private val canonicalLayoutWidgets = listOf(
304305
imageRes = R.drawable.cl_activity_row_search_toolbar,
305306
receiver = SearchToolBarAppWidgetReceiver::class.java,
306307
),
308+
CanonicalLayoutRowData(
309+
rowTitle = R.string.cl_title_expressive_toolbar,
310+
rowDescription = R.string.cl_description_expressive_toolbar,
311+
imageRes = R.drawable.cl_activity_row_expressive_toolbar,
312+
receiver = ExpressiveToolbarAppWidgetReceiver::class.java,
313+
),
307314
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2023 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.platform.ui.appwidgets.glance.layout.toolbars
18+
19+
import android.content.Context
20+
import androidx.compose.runtime.Composable
21+
import androidx.glance.GlanceId
22+
import androidx.glance.GlanceTheme
23+
import androidx.glance.appwidget.GlanceAppWidget
24+
import androidx.glance.appwidget.GlanceAppWidgetReceiver
25+
import androidx.glance.appwidget.SizeMode
26+
import androidx.glance.appwidget.provideContent
27+
import com.example.platform.ui.appwidgets.R
28+
import com.example.platform.ui.appwidgets.glance.layout.toolbars.layout.ExpressiveToolBarButton
29+
import com.example.platform.ui.appwidgets.glance.layout.toolbars.layout.ExpressiveToolbarLayout
30+
import com.example.platform.ui.appwidgets.glance.layout.utils.ActionUtils.actionStartDemoActivity
31+
32+
/**
33+
* A sample [GlanceAppWidget] that demonstrates the [ExpressiveToolbarLayout] that uses a background
34+
* of 4-sided cookie shape.
35+
*
36+
* Uses an example of a notes app with quick actions for
37+
* - adding a note (primary),
38+
* - starting a new note with microphone,
39+
* - starting a new note with camera,
40+
* - deeplink to sharing notes,
41+
* - starting a new note by uploading a file.
42+
*/
43+
class ExpressiveToolbarAppWidget : GlanceAppWidget() {
44+
// Unlike the "Single" size mode, using "Exact" allows us to have better control over rendering in
45+
// different sizes. And, unlike the "Responsive" mode, it doesn't cause several views for each
46+
// supported size to be held in the widget host's memory.
47+
override val sizeMode: SizeMode = SizeMode.Exact
48+
49+
override suspend fun provideGlance(context: Context, id: GlanceId) {
50+
provideContent {
51+
GlanceTheme {
52+
WidgetContent()
53+
}
54+
}
55+
}
56+
57+
@Composable
58+
fun WidgetContent() {
59+
ExpressiveToolbarLayout(
60+
centerButton = ExpressiveToolBarButton(
61+
iconRes = R.drawable.sample_add_icon,
62+
contentDescription = "Add notes",
63+
onClick = actionStartDemoActivity("add notes button")
64+
),
65+
cornerButtons = listOf(
66+
ExpressiveToolBarButton(
67+
iconRes = R.drawable.sample_mic_icon,
68+
contentDescription = "mic",
69+
onClick = actionStartDemoActivity("mic button")
70+
),
71+
ExpressiveToolBarButton(
72+
iconRes = R.drawable.sample_camera_icon,
73+
contentDescription = "camera",
74+
onClick = actionStartDemoActivity("camera button")
75+
),
76+
ExpressiveToolBarButton(
77+
iconRes = R.drawable.sample_share_icon,
78+
contentDescription = "share",
79+
onClick = actionStartDemoActivity("share button")
80+
),
81+
ExpressiveToolBarButton(
82+
iconRes = R.drawable.sample_file_upload_icon,
83+
contentDescription = "file upload",
84+
onClick = actionStartDemoActivity("file upload button")
85+
),
86+
)
87+
)
88+
}
89+
}
90+
91+
class ExpressiveToolbarAppWidgetReceiver : GlanceAppWidgetReceiver() {
92+
override val glanceAppWidget: GlanceAppWidget = ExpressiveToolbarAppWidget()
93+
}

0 commit comments

Comments
 (0)