3 things to improve your Android app experience: Edge to Edge, Predictive Back, and Glance — Transcript
Full transcript
- 0:05howdy everyone and Welcome to our
- 0:07Workshop improve the user experience of
- 0:09your Android application I'm Summers
- 0:11Pitman a developer relations engineer
- 0:13here at Google I'm Ash noi also
- 0:16developer relations engineer at Google
- 0:19and today we're going to tell you how to
- 0:20improve the experience of your Android
- 0:22app by adding edgo Edge design
- 0:24predictive back animations and a widget
- 0:27built using jetpack gland and we're
- 0:29going to add all of these to the
- 0:30socialite application one of our many
- 0:33code examples on GitHub Ash would you
- 0:35like to start with edge to edge yes I
- 0:37would thank you so much okay so for our
- 0:40first Cod laab we are going to handle
- 0:42edgo Edge enforcements in Android
- 0:4515 our social light app will start off
- 0:48looking like this where it will not be
- 0:50edgo Edge the system bars which are the
- 0:53status bar at the top and the navigation
- 0:55bar at the bottom are opaque and content
- 0:58draws Between the Bars
- 1:00at the end of the Cod lab social light
- 1:02will look like this it will be edge to
- 1:04edge the bars will be transparent and
- 1:06the app background will literally draw
- 1:08from one edge of the screen to the
- 1:11other socialite will also be backwards
- 1:14compatible and will fix a few issues
- 1:16along the way we're making this change
- 1:18because an internal Google user study
- 1:20found that users significantly prefer
- 1:23edgo Edge screens over non- edgo Edge
- 1:26screens and users feel these screens are
- 1:29more satisfying and
- 1:31premium okay so let's jump into the code
- 1:34lab uh so we have this pathway improve
- 1:37the user experience of your Android app
- 1:39you'll want to locate this pathway here
- 1:42and then uh The edgo Edge code lab is
- 1:45just the first one which I have pulled
- 1:47up
- 1:47here before you begin you are going to
- 1:51need whoops an Android 15 beta 1 or
- 1:55higher test device and
- 1:58SDK then you're going to get the starter
- 2:00code which you can get from this link
- 2:02here or by running these get
- 2:06commands and then run socialite and
- 2:09investigate it and then meet me in part
- 2:12three so I already have socialite
- 2:15downloaded and running on my app on my
- 2:19device and I can see that I am targeting
- 2:21SDK 34 or in other words Android 14 and
- 2:25social light is not edgo Edge you can
- 2:28see that the system bars are opaque at
- 2:30the top and the bottom and uh that is
- 2:33the case for every
- 2:35screen so let's go ahead and Target uh
- 2:39Android 15 and see what
- 2:49happens okay we're sinking and running
- 2:51so since we're working with a preview
- 2:54we've set Target SDK preview to vanilla
- 2:56ice cream if you're from the future
- 2:58you're probably going to set this to
- 2:59Target SDK
- 3:0335 uh let's
- 3:08see I'm going to uninstall and
- 3:13reinstall it's always a good first
- 3:15troubleshooting
- 3:23step no
- 3:31I'm going to switch to a different
- 3:32device see if that
- 3:48works all right let me just run this app
- 3:52again make sure it works
- 4:01okay it does so after we have enforced
- 4:06edgo Edge by targeting Android 15 we see
- 4:09that socialite is now indeed edge to
- 4:12edge and you might think that our work
- 4:14here is done so the first collab is over
- 4:17but that's not the case there's actually
- 4:19two issues we need to fix and both of
- 4:22these issues are best seen in three
- 4:24button navigation mode so I'm going to
- 4:26go to the settings app here and change
- 4:29it to three button
- 4:31navigation and switch back uh and then
- 4:34you can probably see the first issue
- 4:35best in dark mode so let me switch to
- 4:38that okay so now in dark mode we see
- 4:41that there is this white band at the
- 4:43bottom with the three button uh system
- 4:46navigation this is in fact a translucent
- 4:49band so in Android 15 the default for
- 4:52Jester navigation and for the status bar
- 4:55at the top are to be transparent but for
- 4:57three button navigation it will be
- 4:59translucent and this is to ensure uh
- 5:02accessibility this is the first issue
- 5:04we're going to fix because in our app it
- 5:06would actually look better if this band
- 5:08were removed and the three button here
- 5:10were just transparent instead so that's
- 5:13the first issue we'll fix the second
- 5:15issue is if we go to one of the
- 5:17conversation screens say dog
- 5:19conversation uh we can see the three
- 5:21button is again translucent here and
- 5:23then there's also this input bar that is
- 5:26now hidden behind the three button
- 5:28navigation um and this happened after
- 5:31targeting Android 15 and it's because
- 5:34this custom composable is not handling
- 5:36insets so this is the second issue we'll
- 5:39fix all right back to fixing the first
- 5:42issue we're going to go over to our main
- 5:45activity and remove the translucent
- 5:48three button
- 5:54navigation okay I have set window is
- 5:57navigation bar contrast and force to
- 6:00false uh this API only impacts three
- 6:03Guster navigation it does not impact um
- 6:07or it only impacts three button
- 6:09navigation it does not impact Jester
- 6:11navigation and by setting it to false I
- 6:13removed the translucency so now it is
- 6:16transparent you might think that this
- 6:19background here is not now just colored
- 6:21to be brown like the app bar here but
- 6:24that's not the case it is instead
- 6:26transparent and what we're seeing
- 6:28instead is the apps navigation bar
- 6:31background drawing all the way down to
- 6:33the bottom so this brings us to our
- 6:36second issue that we're going to fix you
- 6:38might be wondering why on this screen
- 6:41the apps navigation bar is not hidden
- 6:44behind the three button navigation bar
- 6:46but on one of the conversation screens
- 6:49our custom input bar is all of a sudden
- 6:52hiding behind the three button
- 6:54navigation bar um and that's because the
- 6:59uh on the previous
- 7:01screen this is a material 3 uh
- 7:05composable along with the app bar here
- 7:08and material 3 composes automatically
- 7:11handle insets for us so a lot of this
- 7:14work is taken care of for us uh but our
- 7:17custom composes like this input bar here
- 7:20do not automatically handle insets for
- 7:22us so let's go ahead and handle insets
- 7:26to fix this second issue this input bar
- 7:29you can find under UI chat and chat
- 7:33screen it is defined around line
- 7:36415 we can see that it takes content
- 7:39padding and then it applies this content
- 7:42padding to the Row mod uh the row
- 7:46composable where this composable
- 7:48contains all the the buttons here right
- 7:53now content padding is set to zero DP so
- 7:56the only padding that's being applied is
- 7:58this 16 DP so you're just seeing 16 DP
- 8:01padding
- 8:03here uh and we can see that zero is
- 8:06being passed in here if we go to where
- 8:08input bar is called at line 214 so here
- 8:13we're passing in zero to simulate that
- 8:15we're not handling
- 8:17insets so I'm going to go ahead and
- 8:19handle insets and then explain the Cod
- 8:26change all right
- 8:30I have set in padding I've made a copy
- 8:32of the in padding and set the top to Zer
- 8:35DP what am I doing here let's walk
- 8:37through this code real quick so input
- 8:39bar is located within a scaffold if you
- 8:43are familiar with scaffold you know that
- 8:45scaffold contains uh padding values
- 8:48which we are calling here inner padding
- 8:51padding values allows you to set padding
- 8:54on your content to ensure that content
- 8:55is not hidden behind the system bars or
- 8:58between other elements in the scaffold
- 9:01like the top app bar or a app navigation
- 9:04bar in this case for our custom input
- 9:09bar we want to handle insets at the
- 9:12bottom and at the left and right hand
- 9:14edges but we do not need to account for
- 9:17the status bar or for the top at bar so
- 9:20for that reason we're making a copy of
- 9:22the padding values or the copy of inner
- 9:24padding and setting the uh top to zero
- 9:31DP uh which we've done on this line
- 9:35here okay so copy is actually an
- 9:39internal method for socialite you might
- 9:41want to create something similar to for
- 9:43your app it does what it says it takes a
- 9:46copy of padding values and use uses the
- 9:49existing padding values for start end
- 9:52and bottom um but since we've supplied a
- 9:55different top padding value of Zer DP it
- 9:58will use that instead of the existing
- 10:00top padding and social light has already
- 10:03finished building and running and we see
- 10:05that now insets are properly handled
- 10:07this input bar is no longer being hidden
- 10:09by the three button navigation uh and
- 10:12this is the this is the case if you
- 10:14rotate your phone as
- 10:16well um because edge to edge is not just
- 10:18drawing from top to bottom it's also
- 10:20left to right so you'll want to consider
- 10:22what your phone looks like in landscape
- 10:24mode you can see that the send Arrow
- 10:26here is not all the way over to the
- 10:29right it's taking into account the three
- 10:30buttons which are now on the right hand
- 10:34side so if there is one takeaway from
- 10:37this edgo Edge code lab this is it um
- 10:41there's a good chance that somewhere in
- 10:43your app there's going to be a button or
- 10:45a custom view or a composable that's not
- 10:48handling insets and you'll need to
- 10:50handle insets you'll want to see uh
- 10:53you'll want to consider handling
- 10:54insights at the top of the screen at the
- 10:56bottom of the screen on the leftand
- 10:58edges and the right hand
- 11:00edges so we don't have time to go over
- 11:03this section in the Cod laab for this
- 11:06Workshop but I do want to point it out
- 11:09uh section five of the collab is uh
- 11:11optional additional edgo Edge
- 11:13considerations for your app so these are
- 11:16considerations that don't necessarily
- 11:18apply to socialite but they might apply
- 11:20to your app um so please give this a
- 11:23look to see if anything is relevant to
- 11:25you it talks about what to do if you're
- 11:27using material 3 components mat iial 2
- 11:29components
- 11:31views uh what if you have scrolling
- 11:34content uh how to handle the display
- 11:37cutout or the the camera cutout and some
- 11:40code samples for that in addition to
- 11:43testing things like caption
- 11:46bars okay but back to the Cod
- 11:51lab so uh we have now made social light
- 11:55compatible with the Android 15 edgo Edge
- 11:57enforcements there is now just one more
- 12:00line of code that we need to make social
- 12:02light backwards compatible um in an edgo
- 12:05edge way and we want to do this because
- 12:07again users prefer edgo Edge screens so
- 12:10for that we're going to go to main
- 12:11activity and we're going to call enable
- 12:13edgo Edge enable edge to edge comes from
- 12:17Android X
- 12:19activity this is one line of code that
- 12:22encapsulates the 100 lines of code you
- 12:25previously needed to make your app Edge
- 12:29to Edge in a backwards compatible way so
- 12:31you no longer need that 100 lines of
- 12:33code you just need this one enable edge
- 12:36to edge line of
- 12:38code all right and with that we have
- 12:42finished the first edge to edge Cod laab
- 12:45and we are going to move on to the
- 12:46predictive Cod lab so one out of three
- 12:49Cod laabs
- 12:52done uh thank
- 12:57you all right so for the predictive back
- 13:00Cod lab uh we already have the code
- 13:02downloaded we are again using socialite
- 13:05if you open up the predictive back Cod
- 13:06lab which is in that pathway you're
- 13:08going to again meet me in step three for
- 13:11predictive act you're going to need just
- 13:12your navigation
- 13:16enabled and then it's easier to see the
- 13:18predictive back animations in light
- 13:19theme so we'll use light theme let's
- 13:22look at what social light looks like
- 13:24without predictive back animation so if
- 13:26I swipe back here we can see an
- 13:29animation is not playing you can tell
- 13:30I'm swiping back cuz you see the back
- 13:32arrow uh as soon as I lift my finger
- 13:35then an animation
- 13:37plays uh in
- 13:42contrast uh if I or not in contrast in
- 13:45addition if I go to one of the
- 13:47conversation screens uh say sheep and I
- 13:49swipe back and animation does not play
- 13:52until I lift my finger and then
- 13:55navigation composes default Crossfade
- 13:58animation play
- 13:59so predictive back is all about playing
- 14:01animations while you swipe back we're
- 14:04going to add two predictive back
- 14:05animations to this app and then
- 14:07customize one of those
- 14:09animations so for that we're going to go
- 14:11to our Android manifest and
- 14:14add
- 14:16android enable onback and vote callback
- 14:20and set that equal to
- 14:24True okay so now when I swipe back I see
- 14:28a preview of where I'm going before I
- 14:31swipe back which allows me to cancel if
- 14:34I need to uh to potentially prevent me
- 14:36from accidentally leaving my app this
- 14:39animation here is called the back to
- 14:41home animation it is not new it has been
- 14:45available since Android 13 but what is
- 14:48new is that it is no longer behind a
- 14:50developer option starting
- 14:53today so
- 14:56yeah if you are on in Android uh 15 beta
- 15:011 Test device like I am you can still
- 15:04test the uh back to home animation
- 15:06you'll just need to go into your
- 15:07developer options and enable the
- 15:10predictive back animations developer
- 15:12option so this option controls three
- 15:15animations it's back to home cross
- 15:17activity and cross task it does not
- 15:20control the navigation compose uh cross
- 15:23fade animation and this is the option
- 15:26here that is being removed uh starting
- 15:29today in Android 15 beta
- 15:312 Okay so let's look at that second
- 15:35animation uh now if I swipe back from
- 15:38this uh chat screen I can see a cross
- 15:42fade animation slowly play out if I
- 15:44slowly swipe back so that's again
- 15:46navigation composes default
- 15:48animation uh we all we had to do was add
- 15:51android enable onback and vot call back
- 15:53equal to true and then in the Cod lab it
- 15:57also asks you to update a library
- 15:59dependency which I did ahead of time to
- 16:02save time so you'll also need to update
- 16:04your navigation composed dependency to
- 16:072.8.0 alpha2 or
- 16:11higher so this is the second animation
- 16:13that we're going to customize I think it
- 16:15looks pretty good but we can make it
- 16:17look
- 16:18better so for that we are going to go to
- 16:21chat
- 16:22screen
- 16:24nope we are going to go to main because
- 16:27that's where our nav host St and we're
- 16:29going to add a few animations into the
- 16:31nav
- 16:34host okay so I've added two animations
- 16:37in here let's walk through this I've
- 16:40added a pop exit transition and a pop
- 16:42enter transition I could have also
- 16:45specified exit transition and enter
- 16:47transition those would have played if
- 16:50the pop variants weren't
- 16:52specified uh so what this does focusing
- 16:54on the pop enter transition first this
- 16:57is a transition for this sheep's uh
- 17:00conversation as it as it transitions out
- 17:04it will scale out and fade out quickly
- 17:08and then it will fully fade out before
- 17:10the entering chats
- 17:12animation scales in and Fades in uh
- 17:17after a slight DeLay So if we swipe back
- 17:20slowly it kind of looks like this this
- 17:21exits quickly the chat screen comes in
- 17:24and then if we swipe back quickly it
- 17:26looks like that we recommend to use use
- 17:29this transition for your full screen
- 17:31surfaces that are not shared element
- 17:34transitions both with um compos and for
- 17:38fragments so with that we've done all
- 17:41the coding portions of the predictive
- 17:43back code lab we're now going to talk
- 17:45about some additional considerations
- 17:47that again don't apply to social light
- 17:49but may apply to your app um the first
- 17:52one is around this back to home
- 17:54animation here it is very easy to
- 17:57accidentally disable this back to home
- 17:59animation if you uh intercept back at
- 18:03your main
- 18:04activity so for that reason we recommend
- 18:07that you do not intercept back in your
- 18:08main activity or in your root activity
- 18:10because then you'll disable the system
- 18:12back to home
- 18:14animation I'm going to pop over to the
- 18:17predictive back Cod lab to look at uh to
- 18:20show some apis for the other
- 18:25considerations okay so for this cab
- 18:28we've been talking a lot about compose
- 18:31uh social light is built fully in compos
- 18:32but predictive back is also supported
- 18:34with fragments um including shared
- 18:36element transitions so you'll use one of
- 18:39these existing fragment apis like set
- 18:42custom animations or set shared element
- 18:45enter transition and then if you are
- 18:47using these apis be sure to use animator
- 18:50and Android X transitions or one of the
- 18:53material Motions like material shared
- 18:55axis material fade through or material
- 18:58fade
- 18:59do not use animation or framework
- 19:01transitions so again animation and
- 19:04framework transitions don't work with
- 19:05predictive back but animator and Android
- 19:08X Transitions and most material motions
- 19:12do uh and another note on fragments
- 19:15there are no default cross fragment uh
- 19:17transitions like we have with compose so
- 19:20for those transitions you'll need to
- 19:22code them in yourself using one of these
- 19:25apis also we have support for both
- 19:28material view components and a handful
- 19:30of material composed components and
- 19:33finally last but not least we have
- 19:35support for shared element transitions
- 19:37in
- 19:39compose okay so that wraps up the
- 19:41predictive back Cod laab and with that I
- 19:44will hand it off to Summers to talk
- 19:46about
- 19:54glance all right let's create a widget
- 19:56using glance for social
- 19:59so um like the edgo edge and predictive
- 20:02back code Labs we are still in Android
- 20:06Studio we're still on Android um 15
- 20:09though this Cod lab can actually be done
- 20:11with Android 12 or higher um there are a
- 20:14few extra things that you should be
- 20:15aware of though you won't necessarily
- 20:17need among them are basic Hilt knowledge
- 20:20we're not going to be using Hilt
- 20:22directly but several of the call of the
- 20:25objects that we interact with are
- 20:27instantiated and accessed user Hil all
- 20:29right so let's begin this is the widget
- 20:33we are going to add to social life it is
- 20:35a favorite contact widget where you can
- 20:37put a picture of your favorite contact
- 20:39on the screen additionally this widget
- 20:41will tell you whether or not you have a
- 20:43new message so um like before you can
- 20:46get the code for this code lab from our
- 20:48GitHub repository um if you've already
- 20:51done the edgo edge and predictive back
- 20:53code Labs the widget code lab will build
- 20:56on top of them as well
- 20:59so let's get started actually adding a
- 21:01widget uh widget is a part of your
- 21:04application that lives inside of an app
- 21:06widget host normally this is a home
- 21:08screen though it's not required to be
- 21:10one um certain information screens and
- 21:13the Act and the Android assistant will
- 21:16also be able to display widgets um
- 21:19jetpack glance is our is Google's new
- 21:22recommended way for writing new widgets
- 21:24it is in release candidate one right now
- 21:28and and will be released for a final
- 21:31version soon the way that widgets are
- 21:34created is by implementing an app widget
- 21:36provider and a remote view with some
- 21:39widget information and then setting them
- 21:41up in your Android manifest as a
- 21:44receiver element um this receiver should
- 21:47be exported it should handle the app
- 21:50android.app widget. actiona widget
- 21:52update action intend and also you should
- 21:55pass the app widget provider info file
- 21:59in as a metadata element with the
- 22:02Android app widget provider name and a
- 22:04reference to the
- 22:07widget all right so how do we get glance
- 22:10in our project well the first thing we
- 22:11want to do is make sure that we've added
- 22:13glance to our Libs versions. Tomo file
- 22:17this is the version catalog
- 22:22in this is the version catalog in a
- 22:26gradal project um in this particular
- 22:29instance we're using the release
- 22:30candidate we will also be updating the
- 22:32code lab to reference the release
- 22:33candidate then you reference the glance
- 22:37app widget and glance material 3 modules
- 22:41in your version catalog or build.gradle
- 22:43file and then you can add them to your
- 22:47build.gradle
- 22:50file as
- 22:54dependencies scrolling keep scrolling
- 22:59and you can add them in your
- 23:00build.gradle file as
- 23:06dependencies all right um if you're just
- 23:10adding this to your file this will be
- 23:11where you resynchronize your um project
- 23:14all right so widgets are written in
- 23:17remote views and when you use glance you
- 23:19can extend the glance app widget class
- 23:21to create these remote views using a CO
- 23:23a composed style API using glance
- 23:26composes and your app rdet provid
- 23:29instead you extend the glance app widget
- 23:32receiver class so let's add those to our
- 23:35project now um if you open the socialite
- 23:38app widget file this is an
- 23:41implementation of the glance app widget
- 23:44class and it calls this provide glance
- 23:46and it provides overrides this provide
- 23:48glance method um so for our first widget
- 23:53we just want to add a simple hello world
- 23:54message and we can do that by create
- 23:57using the glance composable text then
- 23:59Hello World um we need to imp we need to
- 24:04import
- 24:06this composable and we want to make sure
- 24:08that we use the Android x. glance
- 24:10composable and not the compos and not
- 24:12the androidex composed material 3
- 24:14composable glance composes and Jetpack
- 24:17composes are not mutually um creative
- 24:21Additionally you want to make sure that
- 24:22you provide this method this content in
- 24:24the provide content
- 24:27method so to repeat that to implement a
- 24:30widget using glance you want to extend
- 24:32the glance app widget class you want to
- 24:34override the provide glance method and
- 24:36you want to provide your composes using
- 24:38the provide content method in your
- 24:40widget next you will want to implement
- 24:42the glance app widget receiver
- 24:52class oh no and we have that
- 24:55implementation stubbed out as the
- 24:57socialite app widget receiver in our
- 25:00code
- 25:01lab um the socialite app widget rece the
- 25:03glance app widget receiver
- 25:05implementations have this property that
- 25:07you need to override called glance app
- 25:08widget receiver and normally this should
- 25:11just be a no arguments invocation of
- 25:15your so of your app widget in our case
- 25:17this will be the socialite app widget
- 25:20all right so we've implemented our
- 25:21glance app widget we've implemented our
- 25:23glance app widget receiver the next
- 25:25thing we want to do is create our app um
- 25:27our app widget provider information XML
- 25:30file and we can do that by going into
- 25:32our XML resources F folder and
- 25:37adding a new XML resource file we'll
- 25:40name this
- 25:41socialite app widget or socialite widget
- 25:47info we will set our root element to app
- 25:50widget
- 25:52provider and then we will create
- 25:55it all right so let's switch back to the
- 25:57code real
- 25:59quick the app widget provider
- 26:02information is a file that tells the
- 26:04Android operating system and your app
- 26:06widget host information about your
- 26:08widget um it tells you whether or not
- 26:10the widget's resizable how large it can
- 26:12be resized to what it's minimum size is
- 26:16whether or not there's a configuration
- 26:17activity um what features your widget
- 26:20supports in this case we saying that you
- 26:22don't require configuration to add your
- 26:23widget to your home screen and that the
- 26:25widget can be reconfigured after you add
- 26:28it we add a preview image to our app
- 26:31widget picker and then we also set an
- 26:33initial layout in this case this is a
- 26:35layout that is provided by the glance
- 26:41Library all right and then the last step
- 26:44that we want to do is associate all of
- 26:46these guys together in our Android
- 26:48manifest XML
- 26:52file and like I said before we create a
- 26:55receiver we make it the socialite app
- 26:58which
- 26:58receiver we want to make sure that this
- 27:02receiver is
- 27:05exported and we want to give it a
- 27:09label since this is our favorite contact
- 27:11widget we'll use the favorite contact
- 27:13label then we want to implement the
- 27:16intent
- 27:22filters and we want to add a action name
- 27:29android.app
- 27:31widget.
- 27:32action. apppp widget
- 27:42update and then we also want to
- 27:44associate our meta our we want to add a
- 27:47metadata element that Associates the app
- 27:49widget info file so
- 27:52metadata
- 27:53name android.app widget. provider
- 27:59and then resource at xmls socialite
- 28:04widget
- 28:05info all right and we'll just double
- 28:07check that with our code lab that looks
- 28:10good and now when we rerun our socialite
- 28:12application we should see in our widget
- 28:15picker that we have the social light
- 28:18widget
- 28:23available ah there it is
- 28:28all right we have added our hello world
- 28:30widget to our screen you might notice a
- 28:32few things one of the things is that it
- 28:34doesn't match our preview image we'll
- 28:37get to that we'll update it in a moment
- 28:39and also it doesn't really seem to have
- 28:41a lot of the things we say a good widget
- 28:43should have it doesn't have a
- 28:45well-defined shape it's kind of hard to
- 28:47read it's not really jiving with our
- 28:50background theme so the next thing we
- 28:51want to do is we want to improve the
- 28:54design of our
- 28:55widget so when we're thinking about the
- 28:59design of our widget we want to think of
- 29:00something that keeps the content fresh
- 29:02we want to think about something that
- 29:04minimizes re the awkward resizing um
- 29:07layouts and we also want it to have pick
- 29:10up the colors from other widgets in the
- 29:11host background um glance provide
- 29:14several composes that make this really
- 29:16easy let's start by adding a scaffold
- 29:18composable to our glance app
- 29:21widget um the scaffold composable is
- 29:24provided by the glance library and it's
- 29:25a simple API for displaying the widget
- 29:28UI it includes a title bar and it also
- 29:30has some basic padding for its body um
- 29:33and it also sets the default color to
- 29:35your widget background theme all right
- 29:37so let's go back to the socialite app
- 29:38widget and add the following code
- 29:58and then we fix our Imports
- 30:34that that's
- 31:11oops okay so what we've done is we've
- 31:14done a small refactor we've moved our
- 31:16application compos our widget composable
- 31:19out of provide content into its own
- 31:21composable function we've wrapped it in
- 31:23the glance theme composable which allows
- 31:25it to which allows our widget to pick up
- 31:27the themes from from that are provided
- 31:29from glands and then we've added the
- 31:31scaffold we've given it a title bar
- 31:33we've given the title bar a icon and a
- 31:37title socialite and also we've moved our
- 31:39hello world text composable into the
- 31:41body of the app widget so when we
- 31:44relaunch the application and read the
- 31:46widget to our home screen we should see
- 31:48these updated these updated Design
- 31:51Elements appear
- 32:01all right good this is a great first
- 32:04step so we see that the widget now has a
- 32:06background and it's picking up our
- 32:08Widget theme from other colors now let's
- 32:10switch it over to dark
- 32:12mode and the widget automatically adapts
- 32:15to that but we see that our text style
- 32:17is not quite right we can fix this by
- 32:20adding a text style to our text
- 32:25composable
- 32:35and then we give it a color and we will
- 32:37get from our glance
- 32:39theme the ons surface color
- 32:45token and now we rerun the
- 32:52application and we replace our widget
- 33:02and now in dark mode our color of our
- 33:05text composable is much more legible
- 33:07than it was
- 33:08before let's go back to our code
- 33:11lab so this is all part of Dynamic Color
- 33:15where your app widget picks up hints of
- 33:18the color from the surrounding
- 33:19environment in your home screen launcher
- 33:22uh the background and it makes sure that
- 33:23your app widget matches the themes of
- 33:26your app IC ions as well as your other
- 33:30widgets all right so now that we've
- 33:32improved the design let's talk a little
- 33:34bit about the state of our application
- 33:36and how we're going to get the users to
- 33:39select their favorite contact from it
- 33:42what we want to think about is when a
- 33:44user adds a widget to their home screen
- 33:46that requires configuration we need to
- 33:48add a zero State this is a state that
- 33:50should prompt users to do some sort of
- 33:53configuration action and then once this
- 33:56action is done the widget should update
- 33:58itself to show its final layout and
- 34:01we're going to do that now um in the Cod
- 34:04lab I go into a lot more detail about
- 34:06how this data is stored and how it's
- 34:08processed um but what you really need to
- 34:11know for this demonstration is that
- 34:13we're going to use this widget model and
- 34:15we're going to use a widget model
- 34:16repository class the widget model
- 34:18repository class is a class that's
- 34:20managed with Hilt and we're going to use
- 34:21a getter a Hil getter to get that so
- 34:24let's add the zero state to our widget
- 34:27and let's also add the repository to our
- 34:31provide glance
- 34:33method so going back to our
- 34:37code all right and cleaning up our
- 34:50Imports and moving this down
- 34:53here all right so when provide glance is
- 34:56called it's provided a widget ID and we
- 34:59need to unwrap the glance ID and make it
- 35:02a widget ID and then we're going to get
- 35:04a reference to our um widget model
- 35:06repository which lets us update and
- 35:09receive updates from our um widget data
- 35:13then we're going to update our content
- 35:15repository so that we can pass this V
- 35:18the widget repository in our content
- 35:21composable to so that we can pass the
- 35:23widget repository
- 35:25in and then we fix the
- 35:55Imports all right so now we load the
- 35:58model from our repository and we're
- 36:00going to replace our um content method
- 36:04with this win block this wind block will
- 36:08switch on whether we have a loading
- 36:11state or if we have um or if we have an
- 36:14actual widget
- 36:24model and we're going to use a zero
- 36:26state composable that is provided by the
- 36:29Cod lab so now
- 36:33our and then we need to fix this one
- 36:36last thing repository widget ID all
- 36:39right so now when our widget ID is when
- 36:41our widget is loaded it will get an get
- 36:43a reference to our repository load the
- 36:46model for the widget and if the model is
- 36:49not available display a zero State and
- 36:51if the model is available we'll go back
- 36:53to displaying our hello world code so
- 36:54let's relaunch relaunch our application
- 37:00replace our
- 37:11widget all right and now we're seeing
- 37:13our zero state so if we select choose
- 37:15the option to select our favorite
- 37:16contact it brings up our configuration
- 37:19activity and then when we select our
- 37:22contact nothing happens we haven't
- 37:25actually added the ability to we haven't
- 37:27actually updated our repository from our
- 37:29content from our configuration activity
- 37:31so let's open the social light app
- 37:33widget configuration act
- 37:43activity and in the contact row on click
- 37:47Handler we are going to do several
- 37:50things first we are going
- 37:54to first we are going to launch a new
- 37:57codage
- 37:58we're going to call create or update in
- 37:59our widget model repository with our new
- 38:01widget model this has the app widget ID
- 38:05the contacts ID the contacts name the
- 38:07contacts icon and fals to say that they
- 38:09have no unread messages then we're going
- 38:11to call socialite app widget update all
- 38:14which will update all instances of the
- 38:15app widget on our home screen and
- 38:17finally we're going to set the state of
- 38:20the configuration activity so that the
- 38:23um Android operating system knows that
- 38:25the widget was configured
- 38:34and we will import fix our
- 38:53Imports and we will rerun our
- 38:55application
- 39:07and now when we select our favorite
- 39:12contact the widget sees that the widget
- 39:16model in the background has updated and
- 39:18we have our state update from the police
- 39:21selector favorite contact to the hello
- 39:23world and the last thing we want to do
- 39:24is we want to go back to our socialite
- 39:26app widget
- 39:29and we want to replace this text
- 39:31composable with our favorite contact
- 39:34composable and
- 39:45that fix our Imports
- 40:11I and now when we rerun our application
- 40:13for the last
- 40:20time oh there is an error
- 40:31and now when we reun rerun our
- 40:33application for the last
- 40:37time when we select our favorite
- 40:42contact our widget updates and so now
- 40:45that that we have a widget model saved
- 40:46in the database and our widget updates
- 40:49the glance composable recomposes the
- 40:51widget and it shows our widget with its
- 40:53new default State and if we go to the
- 40:56socialite app and we go to the dog and
- 40:59we send it a
- 41:02message when the dog responds in a few
- 41:04seconds we'll see that our widget States
- 41:06updated updates to say that we have a
- 41:14message see that our widget State
- 41:16updates to say that we have a message
- 41:31ah there it goes all right so and now
- 41:34when we click on the widget we read our
- 41:37message and the widget updates to say
- 41:39that there are no new messages um in the
- 41:41code lab we also do cover uh maintaining
- 41:43and updating your data to keep your
- 41:45State uh in sync as well as to clean up
- 41:48any data that happens that any data that
- 41:50happens to get orphaned when you close
- 41:51the dog or when you close the when you
- 41:54remove the widget all right and with
- 41:55that we've added a widget to social
- 41:57we've added edge-to-edge design and
- 41:59we've added a predictive back animation
- 42:01Ash would you like to come up and help
- 42:03us close
- 42:08outk you so much all yeah as summer said
- 42:11we've added edge to edge predictive back
- 42:13and glance to socialite now socialite is
- 42:16looking much more premium and satisfying
- 42:19than it did before we hope that you can
- 42:21take these learnings back to your
- 42:23application thank you all again very
- 42:26much
- 42:30[Applause]
- 42:33oh
About this transcript
This page contains the full transcript of 3 things to improve your Android app experience: Edge to Edge, Predictive Back, and Glance by Android Developers, generated from the public captions YouTube serves with the video. The transcript has 5,696 words across 852 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.