1 /*
2  * Copyright 2021 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  *      http://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 androidx.glance.appwidget.macrobenchmark.target
18 
19 import android.content.Context
20 import androidx.glance.GlanceId
21 import androidx.glance.GlanceModifier
22 import androidx.glance.LocalSize
23 import androidx.glance.appwidget.GlanceAppWidget
24 import androidx.glance.appwidget.GlanceAppWidgetReceiver
25 import androidx.glance.appwidget.SizeMode
26 import androidx.glance.appwidget.Tracing
27 import androidx.glance.appwidget.provideContent
28 import androidx.glance.layout.Column
29 import androidx.glance.layout.fillMaxSize
30 import androidx.glance.text.Text
31 import kotlin.math.roundToInt
32 
33 open class BasicAppWidget : GlanceAppWidget() {
34     init {
35         // Ensure tracing is enabled before starting updates.
36         Tracing.enabled.set(true)
37     }
38 
39     override val sizeMode: SizeMode = SizeMode.Single
40 
provideGlancenull41     override suspend fun provideGlance(
42         context: Context,
43         id: GlanceId,
44     ) {
45         provideContent {
46             Column(GlanceModifier.fillMaxSize()) {
47                 val size = LocalSize.current
48                 Text(
49                     " Current size: ${size.width.value.roundToInt()} dp x " +
50                         "${size.height.value.roundToInt()} dp"
51                 )
52             }
53         }
54     }
55 }
56 
57 class BasicAppWidgetReceiver : GlanceAppWidgetReceiver() {
58     override val glanceAppWidget: GlanceAppWidget = BasicAppWidget()
59 }
60