This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MutableStateDemoWidget : GlanceAppWidget() { | |
| companion object { | |
| private val checkBoxKey = "IS_CHECKED" | |
| } | |
| override var stateDefinition: GlanceStateDefinition<*> = PreferencesGlanceStateDefinition | |
| override suspend fun provideGlance(context: Context, id: GlanceId) { | |
| provideContent { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| glanceAppWidget.updateAppWidgetState(context, id){ | |
| it[booleanPreferencesKey(checkBoxKey)] = isChecked | |
| } | |
| glanceAppWidget.update(context, id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val checkBoxKey = "IS_CHECKED" | |
| val prefs = currentState<Preferences>() | |
| val isChecked = prefs[booleanPreferencesKey(checkBoxKey)]!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override var stateDefinition: GlanceStateDefinition<*> = PreferencesGlanceStateDefinition |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UIResultDemoWidget: GlanceAppWidget() { | |
| override suspend fun provideGlance(context: Context, id: GlanceId) { | |
| provideContent { | |
| val uiResultState = remember { | |
| mutableStateOf<UIResult<String>>(UIResult.Loading) | |
| } | |
| val coroutineScope = rememberCoroutineScope() | |
| LaunchedEffect(key1 = Unit){ | |
| coroutineScope.launch { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sealed class UIResult<out T> { | |
| object Loading : UIResult<Nothing>() | |
| data class Success<T>(val data: T) : UIResult<T>() | |
| data class Error(val error: String) : UIResult<Nothing>() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MutableStateDemoWidget: GlanceAppWidget() { | |
| override suspend fun provideGlance(context: Context, id: GlanceId) { | |
| provideContent { | |
| val isCheck = remember { | |
| mutableStateOf(false) | |
| } | |
| Row(modifier = GlanceModifier.background(ColorProvider(Color.White, Color.Black))) { | |
| val checkText = if (isCheck.value) "Checked" else "Unchecked" | |
| CheckBox( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MonthCalendarDemoWidget : GlanceAppWidget() { | |
| override val sizeMode: SizeMode | |
| get() = SizeMode.Exact | |
| override suspend fun provideGlance(context: Context, id: GlanceId) { | |
| provideContent { | |
| val milliSecond = remember { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools"> | |
| <application | |
| ---- | |
| --- | |
| --- | |
| <receiver android:name=".appwidget.MonthCalendarDemoReceiver" | |
| android:exported="true"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:initialLayout="@layout/glance_default_loading_layout" | |
| android:minWidth="200dp" | |
| android:minHeight="120dp" | |
| android:minResizeWidth="200dp" | |
| android:minResizeHeight="120dp" | |
| android:resizeMode="horizontal|vertical" | |
| android:updatePeriodMillis="0" | |
| android:widgetCategory="home_screen"> |