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