Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Glance App Widget

Glance App Widget

Slides about Google's At a Glance Compose library for making widgets for Android.

Avatar for iona bartishvili

iona bartishvili

October 19, 2022
Tweet

Other Decks in Technology

Transcript

  1. about me Android @ TBC Bank, Student at BTU 2+

    years experience, Business and Retail Mobile banks IonaBartishvili1 IonaBartishvili
  2. Content What is Widget? How Android Widget Works How the

    Glance Works Pros of the Glance 1. 2. 3. 4. 4. Problems
  3. Widgets can have configuration activities. this activity automatically starts when

    user places widget to the home screen for the first time and also everytime when user edits the widget (reconfiguration) configuration
  4. In Android, we have AppWidgetReceiver in order to control the

    widget's "Lifecycle" AppWidgetReceiver is a simple BroadcastReciever that receives only the event broadcasts that are relevant to the widget, such as when the widget is updated, deleted, enabled, and disabled. How Android Widget Works?
  5. ONUPDATE() WidgetReciever methods Also called when the user adds the

    widget, so it should perform the essential setup. However, if you have declared a configuration activity without the configuration_optional flag, this method is not called when the user adds the widget, but is called for the subsequent updates. This is called to update the widget at intervals defined by the updatePeriodMillis attribute in the AppWidgetProviderInfo.
  6. WARNING ! WidgetReciever methods updatePeriodMillis does not support values smaller

    than 30 minutes. However, if you want to disable periodic updates, you can specify 0.
  7. TAKE INTO ACCOUNT WidgetReciever methods Updating widget content can be

    computationally expensive. To save battery consumption, you can optimize the update type, frequency, and timing.
  8. ON_APP_WIDGET_OPTIONS_CHANGED() WidgetReciever methods This is called when the widget is

    first placed and any time the widget is resized. Use this callback to show or hide content based on the widget's size ranges. ONDELETED() This is called every time a widget is deleted from the widget host.
  9. ONENABLED() WidgetReciever methods This is called when an instance the

    widget is created for the first time. For example, if the user adds two instances of your widget, this is only called the first time. If you need to open a new database or perform another setup that only needs to occur once for all widget instances, then this is a good place to do it. ONDISABLED() This is called when the last instance of your widget is deleted from the widget host. This is where you should clean up any work done in onEnabled(Context),
  10. In Glance widget, we have possibility to use Compose Runtime

    functions and make Widget's UI with Composable Functions. Yeah, whatever, you don't say... How about Glance COmpose?
  11. Glance != Jetpack Compose glance uses Compose runtime which is

    mapper bridge between compose syle code syntax and Legacy Android RemoteViews. So, we don't have composition, recomposition, sideEffects, no remember {} ...
  12. Bcs of that, Limitations So we have limitations regarding the

    UI of Glance. we can use only Several Composable widgets. available images: Box, Row, Column, Text, Button, LazyColumn, Image, Spacer. No Compose Modifier, we have GlanceModifier.
  13. State Management In Glance Widget, we have a little model

    of state management via GlanceStateDefinition. it uses DataStore under the hood.
  14. action run callbacks Instead of Intents and PendingIntents, we have

    ActionRunCallbacks wich is much more convenient. starting the activity starting service action for sending the broadcast and running the custom action we have several existing action callbacks for
  15. action run callbacks Instead of Intents and PendingIntents, we have

    ActionRunCallbacks wich is much more convenient. starting the activity starting service action for sending the broadcast and running the custom action we have several existing action callbacks for
  16. Size Modes Glance has Size Modes that represent the current

    sizes for the widget. we have 3 different SizeMode
  17. Interop With RemoteViews Similar to how Jetpack Compose supports interoperability

    with Android Views, Glance provides a way to add RemoteViews to a Glance composition. Simply wrap them in AndroidRemoteViews.
  18. Problems No Live edit or Glance Widget @Preview 's Debugging

    and testing is a pain in the ass No Remote Image Loading the minSDK is 21, we are currently only supporting compatibility till SDK v23. widget round corner support for <SDK 23 NO ROUND CORNERS updating the glance widget is possible only with coroutines