-
Notifications
You must be signed in to change notification settings - Fork 60
/
RemoteViewInteropWidget.kt
42 lines (35 loc) · 1.32 KB
/
RemoteViewInteropWidget.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.husaynhakeem.glancesample.widget.interop
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import androidx.glance.GlanceModifier
import androidx.glance.LocalContext
import androidx.glance.appwidget.AndroidRemoteViews
import androidx.glance.appwidget.GlanceAppWidget
import androidx.glance.appwidget.GlanceAppWidgetReceiver
import androidx.glance.layout.Column
import androidx.glance.layout.fillMaxSize
import androidx.glance.layout.padding
import androidx.glance.text.Text
/**
* Widget that demonstrates the use of Glance UI components in interoperability with
* [android.widget.RemoteViews]. You can add existing remote views to a Glance composition by
* wrapping them in [AndroidRemoteViews]
*/
class RemoteViewInteropWidget : GlanceAppWidget() {
@Composable
override fun Content() {
Column(
modifier = GlanceModifier
.fillMaxSize()
.padding(8.dp)
) {
Text(text = "Above remote views")
val context = LocalContext.current
AndroidRemoteViews(remoteViews = RemoteViewWidget(context))
Text(text = "Below remote views")
}
}
}
class RemoteViewInteropWidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget: GlanceAppWidget = RemoteViewInteropWidget()
}