YouTube2Text

3 things to improve your Android app experience: Edge to Edge, Predictive Back, and Glance — Transcript

by Android Developers · 5,696 words · 852 segments · language en · Watch on YouTube

Full transcript

  1. 0:05howdy everyone and Welcome to our
  2. 0:07Workshop improve the user experience of
  3. 0:09your Android application I'm Summers
  4. 0:11Pitman a developer relations engineer
  5. 0:13here at Google I'm Ash noi also
  6. 0:16developer relations engineer at Google
  7. 0:19and today we're going to tell you how to
  8. 0:20improve the experience of your Android
  9. 0:22app by adding edgo Edge design
  10. 0:24predictive back animations and a widget
  11. 0:27built using jetpack gland and we're
  12. 0:29going to add all of these to the
  13. 0:30socialite application one of our many
  14. 0:33code examples on GitHub Ash would you
  15. 0:35like to start with edge to edge yes I
  16. 0:37would thank you so much okay so for our
  17. 0:40first Cod laab we are going to handle
  18. 0:42edgo Edge enforcements in Android
  19. 0:4515 our social light app will start off
  20. 0:48looking like this where it will not be
  21. 0:50edgo Edge the system bars which are the
  22. 0:53status bar at the top and the navigation
  23. 0:55bar at the bottom are opaque and content
  24. 0:58draws Between the Bars
  25. 1:00at the end of the Cod lab social light
  26. 1:02will look like this it will be edge to
  27. 1:04edge the bars will be transparent and
  28. 1:06the app background will literally draw
  29. 1:08from one edge of the screen to the
  30. 1:11other socialite will also be backwards
  31. 1:14compatible and will fix a few issues
  32. 1:16along the way we're making this change
  33. 1:18because an internal Google user study
  34. 1:20found that users significantly prefer
  35. 1:23edgo Edge screens over non- edgo Edge
  36. 1:26screens and users feel these screens are
  37. 1:29more satisfying and
  38. 1:31premium okay so let's jump into the code
  39. 1:34lab uh so we have this pathway improve
  40. 1:37the user experience of your Android app
  41. 1:39you'll want to locate this pathway here
  42. 1:42and then uh The edgo Edge code lab is
  43. 1:45just the first one which I have pulled
  44. 1:47up
  45. 1:47here before you begin you are going to
  46. 1:51need whoops an Android 15 beta 1 or
  47. 1:55higher test device and
  48. 1:58SDK then you're going to get the starter
  49. 2:00code which you can get from this link
  50. 2:02here or by running these get
  51. 2:06commands and then run socialite and
  52. 2:09investigate it and then meet me in part
  53. 2:12three so I already have socialite
  54. 2:15downloaded and running on my app on my
  55. 2:19device and I can see that I am targeting
  56. 2:21SDK 34 or in other words Android 14 and
  57. 2:25social light is not edgo Edge you can
  58. 2:28see that the system bars are opaque at
  59. 2:30the top and the bottom and uh that is
  60. 2:33the case for every
  61. 2:35screen so let's go ahead and Target uh
  62. 2:39Android 15 and see what
  63. 2:49happens okay we're sinking and running
  64. 2:51so since we're working with a preview
  65. 2:54we've set Target SDK preview to vanilla
  66. 2:56ice cream if you're from the future
  67. 2:58you're probably going to set this to
  68. 2:59Target SDK
  69. 3:0335 uh let's
  70. 3:08see I'm going to uninstall and
  71. 3:13reinstall it's always a good first
  72. 3:15troubleshooting
  73. 3:23step no
  74. 3:31I'm going to switch to a different
  75. 3:32device see if that
  76. 3:48works all right let me just run this app
  77. 3:52again make sure it works
  78. 4:01okay it does so after we have enforced
  79. 4:06edgo Edge by targeting Android 15 we see
  80. 4:09that socialite is now indeed edge to
  81. 4:12edge and you might think that our work
  82. 4:14here is done so the first collab is over
  83. 4:17but that's not the case there's actually
  84. 4:19two issues we need to fix and both of
  85. 4:22these issues are best seen in three
  86. 4:24button navigation mode so I'm going to
  87. 4:26go to the settings app here and change
  88. 4:29it to three button
  89. 4:31navigation and switch back uh and then
  90. 4:34you can probably see the first issue
  91. 4:35best in dark mode so let me switch to
  92. 4:38that okay so now in dark mode we see
  93. 4:41that there is this white band at the
  94. 4:43bottom with the three button uh system
  95. 4:46navigation this is in fact a translucent
  96. 4:49band so in Android 15 the default for
  97. 4:52Jester navigation and for the status bar
  98. 4:55at the top are to be transparent but for
  99. 4:57three button navigation it will be
  100. 4:59translucent and this is to ensure uh
  101. 5:02accessibility this is the first issue
  102. 5:04we're going to fix because in our app it
  103. 5:06would actually look better if this band
  104. 5:08were removed and the three button here
  105. 5:10were just transparent instead so that's
  106. 5:13the first issue we'll fix the second
  107. 5:15issue is if we go to one of the
  108. 5:17conversation screens say dog
  109. 5:19conversation uh we can see the three
  110. 5:21button is again translucent here and
  111. 5:23then there's also this input bar that is
  112. 5:26now hidden behind the three button
  113. 5:28navigation um and this happened after
  114. 5:31targeting Android 15 and it's because
  115. 5:34this custom composable is not handling
  116. 5:36insets so this is the second issue we'll
  117. 5:39fix all right back to fixing the first
  118. 5:42issue we're going to go over to our main
  119. 5:45activity and remove the translucent
  120. 5:48three button
  121. 5:54navigation okay I have set window is
  122. 5:57navigation bar contrast and force to
  123. 6:00false uh this API only impacts three
  124. 6:03Guster navigation it does not impact um
  125. 6:07or it only impacts three button
  126. 6:09navigation it does not impact Jester
  127. 6:11navigation and by setting it to false I
  128. 6:13removed the translucency so now it is
  129. 6:16transparent you might think that this
  130. 6:19background here is not now just colored
  131. 6:21to be brown like the app bar here but
  132. 6:24that's not the case it is instead
  133. 6:26transparent and what we're seeing
  134. 6:28instead is the apps navigation bar
  135. 6:31background drawing all the way down to
  136. 6:33the bottom so this brings us to our
  137. 6:36second issue that we're going to fix you
  138. 6:38might be wondering why on this screen
  139. 6:41the apps navigation bar is not hidden
  140. 6:44behind the three button navigation bar
  141. 6:46but on one of the conversation screens
  142. 6:49our custom input bar is all of a sudden
  143. 6:52hiding behind the three button
  144. 6:54navigation bar um and that's because the
  145. 6:59uh on the previous
  146. 7:01screen this is a material 3 uh
  147. 7:05composable along with the app bar here
  148. 7:08and material 3 composes automatically
  149. 7:11handle insets for us so a lot of this
  150. 7:14work is taken care of for us uh but our
  151. 7:17custom composes like this input bar here
  152. 7:20do not automatically handle insets for
  153. 7:22us so let's go ahead and handle insets
  154. 7:26to fix this second issue this input bar
  155. 7:29you can find under UI chat and chat
  156. 7:33screen it is defined around line
  157. 7:36415 we can see that it takes content
  158. 7:39padding and then it applies this content
  159. 7:42padding to the Row mod uh the row
  160. 7:46composable where this composable
  161. 7:48contains all the the buttons here right
  162. 7:53now content padding is set to zero DP so
  163. 7:56the only padding that's being applied is
  164. 7:58this 16 DP so you're just seeing 16 DP
  165. 8:01padding
  166. 8:03here uh and we can see that zero is
  167. 8:06being passed in here if we go to where
  168. 8:08input bar is called at line 214 so here
  169. 8:13we're passing in zero to simulate that
  170. 8:15we're not handling
  171. 8:17insets so I'm going to go ahead and
  172. 8:19handle insets and then explain the Cod
  173. 8:26change all right
  174. 8:30I have set in padding I've made a copy
  175. 8:32of the in padding and set the top to Zer
  176. 8:35DP what am I doing here let's walk
  177. 8:37through this code real quick so input
  178. 8:39bar is located within a scaffold if you
  179. 8:43are familiar with scaffold you know that
  180. 8:45scaffold contains uh padding values
  181. 8:48which we are calling here inner padding
  182. 8:51padding values allows you to set padding
  183. 8:54on your content to ensure that content
  184. 8:55is not hidden behind the system bars or
  185. 8:58between other elements in the scaffold
  186. 9:01like the top app bar or a app navigation
  187. 9:04bar in this case for our custom input
  188. 9:09bar we want to handle insets at the
  189. 9:12bottom and at the left and right hand
  190. 9:14edges but we do not need to account for
  191. 9:17the status bar or for the top at bar so
  192. 9:20for that reason we're making a copy of
  193. 9:22the padding values or the copy of inner
  194. 9:24padding and setting the uh top to zero
  195. 9:31DP uh which we've done on this line
  196. 9:35here okay so copy is actually an
  197. 9:39internal method for socialite you might
  198. 9:41want to create something similar to for
  199. 9:43your app it does what it says it takes a
  200. 9:46copy of padding values and use uses the
  201. 9:49existing padding values for start end
  202. 9:52and bottom um but since we've supplied a
  203. 9:55different top padding value of Zer DP it
  204. 9:58will use that instead of the existing
  205. 10:00top padding and social light has already
  206. 10:03finished building and running and we see
  207. 10:05that now insets are properly handled
  208. 10:07this input bar is no longer being hidden
  209. 10:09by the three button navigation uh and
  210. 10:12this is the this is the case if you
  211. 10:14rotate your phone as
  212. 10:16well um because edge to edge is not just
  213. 10:18drawing from top to bottom it's also
  214. 10:20left to right so you'll want to consider
  215. 10:22what your phone looks like in landscape
  216. 10:24mode you can see that the send Arrow
  217. 10:26here is not all the way over to the
  218. 10:29right it's taking into account the three
  219. 10:30buttons which are now on the right hand
  220. 10:34side so if there is one takeaway from
  221. 10:37this edgo Edge code lab this is it um
  222. 10:41there's a good chance that somewhere in
  223. 10:43your app there's going to be a button or
  224. 10:45a custom view or a composable that's not
  225. 10:48handling insets and you'll need to
  226. 10:50handle insets you'll want to see uh
  227. 10:53you'll want to consider handling
  228. 10:54insights at the top of the screen at the
  229. 10:56bottom of the screen on the leftand
  230. 10:58edges and the right hand
  231. 11:00edges so we don't have time to go over
  232. 11:03this section in the Cod laab for this
  233. 11:06Workshop but I do want to point it out
  234. 11:09uh section five of the collab is uh
  235. 11:11optional additional edgo Edge
  236. 11:13considerations for your app so these are
  237. 11:16considerations that don't necessarily
  238. 11:18apply to socialite but they might apply
  239. 11:20to your app um so please give this a
  240. 11:23look to see if anything is relevant to
  241. 11:25you it talks about what to do if you're
  242. 11:27using material 3 components mat iial 2
  243. 11:29components
  244. 11:31views uh what if you have scrolling
  245. 11:34content uh how to handle the display
  246. 11:37cutout or the the camera cutout and some
  247. 11:40code samples for that in addition to
  248. 11:43testing things like caption
  249. 11:46bars okay but back to the Cod
  250. 11:51lab so uh we have now made social light
  251. 11:55compatible with the Android 15 edgo Edge
  252. 11:57enforcements there is now just one more
  253. 12:00line of code that we need to make social
  254. 12:02light backwards compatible um in an edgo
  255. 12:05edge way and we want to do this because
  256. 12:07again users prefer edgo Edge screens so
  257. 12:10for that we're going to go to main
  258. 12:11activity and we're going to call enable
  259. 12:13edgo Edge enable edge to edge comes from
  260. 12:17Android X
  261. 12:19activity this is one line of code that
  262. 12:22encapsulates the 100 lines of code you
  263. 12:25previously needed to make your app Edge
  264. 12:29to Edge in a backwards compatible way so
  265. 12:31you no longer need that 100 lines of
  266. 12:33code you just need this one enable edge
  267. 12:36to edge line of
  268. 12:38code all right and with that we have
  269. 12:42finished the first edge to edge Cod laab
  270. 12:45and we are going to move on to the
  271. 12:46predictive Cod lab so one out of three
  272. 12:49Cod laabs
  273. 12:52done uh thank
  274. 12:57you all right so for the predictive back
  275. 13:00Cod lab uh we already have the code
  276. 13:02downloaded we are again using socialite
  277. 13:05if you open up the predictive back Cod
  278. 13:06lab which is in that pathway you're
  279. 13:08going to again meet me in step three for
  280. 13:11predictive act you're going to need just
  281. 13:12your navigation
  282. 13:16enabled and then it's easier to see the
  283. 13:18predictive back animations in light
  284. 13:19theme so we'll use light theme let's
  285. 13:22look at what social light looks like
  286. 13:24without predictive back animation so if
  287. 13:26I swipe back here we can see an
  288. 13:29animation is not playing you can tell
  289. 13:30I'm swiping back cuz you see the back
  290. 13:32arrow uh as soon as I lift my finger
  291. 13:35then an animation
  292. 13:37plays uh in
  293. 13:42contrast uh if I or not in contrast in
  294. 13:45addition if I go to one of the
  295. 13:47conversation screens uh say sheep and I
  296. 13:49swipe back and animation does not play
  297. 13:52until I lift my finger and then
  298. 13:55navigation composes default Crossfade
  299. 13:58animation play
  300. 13:59so predictive back is all about playing
  301. 14:01animations while you swipe back we're
  302. 14:04going to add two predictive back
  303. 14:05animations to this app and then
  304. 14:07customize one of those
  305. 14:09animations so for that we're going to go
  306. 14:11to our Android manifest and
  307. 14:14add
  308. 14:16android enable onback and vote callback
  309. 14:20and set that equal to
  310. 14:24True okay so now when I swipe back I see
  311. 14:28a preview of where I'm going before I
  312. 14:31swipe back which allows me to cancel if
  313. 14:34I need to uh to potentially prevent me
  314. 14:36from accidentally leaving my app this
  315. 14:39animation here is called the back to
  316. 14:41home animation it is not new it has been
  317. 14:45available since Android 13 but what is
  318. 14:48new is that it is no longer behind a
  319. 14:50developer option starting
  320. 14:53today so
  321. 14:56yeah if you are on in Android uh 15 beta
  322. 15:011 Test device like I am you can still
  323. 15:04test the uh back to home animation
  324. 15:06you'll just need to go into your
  325. 15:07developer options and enable the
  326. 15:10predictive back animations developer
  327. 15:12option so this option controls three
  328. 15:15animations it's back to home cross
  329. 15:17activity and cross task it does not
  330. 15:20control the navigation compose uh cross
  331. 15:23fade animation and this is the option
  332. 15:26here that is being removed uh starting
  333. 15:29today in Android 15 beta
  334. 15:312 Okay so let's look at that second
  335. 15:35animation uh now if I swipe back from
  336. 15:38this uh chat screen I can see a cross
  337. 15:42fade animation slowly play out if I
  338. 15:44slowly swipe back so that's again
  339. 15:46navigation composes default
  340. 15:48animation uh we all we had to do was add
  341. 15:51android enable onback and vot call back
  342. 15:53equal to true and then in the Cod lab it
  343. 15:57also asks you to update a library
  344. 15:59dependency which I did ahead of time to
  345. 16:02save time so you'll also need to update
  346. 16:04your navigation composed dependency to
  347. 16:072.8.0 alpha2 or
  348. 16:11higher so this is the second animation
  349. 16:13that we're going to customize I think it
  350. 16:15looks pretty good but we can make it
  351. 16:17look
  352. 16:18better so for that we are going to go to
  353. 16:21chat
  354. 16:22screen
  355. 16:24nope we are going to go to main because
  356. 16:27that's where our nav host St and we're
  357. 16:29going to add a few animations into the
  358. 16:31nav
  359. 16:34host okay so I've added two animations
  360. 16:37in here let's walk through this I've
  361. 16:40added a pop exit transition and a pop
  362. 16:42enter transition I could have also
  363. 16:45specified exit transition and enter
  364. 16:47transition those would have played if
  365. 16:50the pop variants weren't
  366. 16:52specified uh so what this does focusing
  367. 16:54on the pop enter transition first this
  368. 16:57is a transition for this sheep's uh
  369. 17:00conversation as it as it transitions out
  370. 17:04it will scale out and fade out quickly
  371. 17:08and then it will fully fade out before
  372. 17:10the entering chats
  373. 17:12animation scales in and Fades in uh
  374. 17:17after a slight DeLay So if we swipe back
  375. 17:20slowly it kind of looks like this this
  376. 17:21exits quickly the chat screen comes in
  377. 17:24and then if we swipe back quickly it
  378. 17:26looks like that we recommend to use use
  379. 17:29this transition for your full screen
  380. 17:31surfaces that are not shared element
  381. 17:34transitions both with um compos and for
  382. 17:38fragments so with that we've done all
  383. 17:41the coding portions of the predictive
  384. 17:43back code lab we're now going to talk
  385. 17:45about some additional considerations
  386. 17:47that again don't apply to social light
  387. 17:49but may apply to your app um the first
  388. 17:52one is around this back to home
  389. 17:54animation here it is very easy to
  390. 17:57accidentally disable this back to home
  391. 17:59animation if you uh intercept back at
  392. 18:03your main
  393. 18:04activity so for that reason we recommend
  394. 18:07that you do not intercept back in your
  395. 18:08main activity or in your root activity
  396. 18:10because then you'll disable the system
  397. 18:12back to home
  398. 18:14animation I'm going to pop over to the
  399. 18:17predictive back Cod lab to look at uh to
  400. 18:20show some apis for the other
  401. 18:25considerations okay so for this cab
  402. 18:28we've been talking a lot about compose
  403. 18:31uh social light is built fully in compos
  404. 18:32but predictive back is also supported
  405. 18:34with fragments um including shared
  406. 18:36element transitions so you'll use one of
  407. 18:39these existing fragment apis like set
  408. 18:42custom animations or set shared element
  409. 18:45enter transition and then if you are
  410. 18:47using these apis be sure to use animator
  411. 18:50and Android X transitions or one of the
  412. 18:53material Motions like material shared
  413. 18:55axis material fade through or material
  414. 18:58fade
  415. 18:59do not use animation or framework
  416. 19:01transitions so again animation and
  417. 19:04framework transitions don't work with
  418. 19:05predictive back but animator and Android
  419. 19:08X Transitions and most material motions
  420. 19:12do uh and another note on fragments
  421. 19:15there are no default cross fragment uh
  422. 19:17transitions like we have with compose so
  423. 19:20for those transitions you'll need to
  424. 19:22code them in yourself using one of these
  425. 19:25apis also we have support for both
  426. 19:28material view components and a handful
  427. 19:30of material composed components and
  428. 19:33finally last but not least we have
  429. 19:35support for shared element transitions
  430. 19:37in
  431. 19:39compose okay so that wraps up the
  432. 19:41predictive back Cod laab and with that I
  433. 19:44will hand it off to Summers to talk
  434. 19:46about
  435. 19:54glance all right let's create a widget
  436. 19:56using glance for social
  437. 19:59so um like the edgo edge and predictive
  438. 20:02back code Labs we are still in Android
  439. 20:06Studio we're still on Android um 15
  440. 20:09though this Cod lab can actually be done
  441. 20:11with Android 12 or higher um there are a
  442. 20:14few extra things that you should be
  443. 20:15aware of though you won't necessarily
  444. 20:17need among them are basic Hilt knowledge
  445. 20:20we're not going to be using Hilt
  446. 20:22directly but several of the call of the
  447. 20:25objects that we interact with are
  448. 20:27instantiated and accessed user Hil all
  449. 20:29right so let's begin this is the widget
  450. 20:33we are going to add to social life it is
  451. 20:35a favorite contact widget where you can
  452. 20:37put a picture of your favorite contact
  453. 20:39on the screen additionally this widget
  454. 20:41will tell you whether or not you have a
  455. 20:43new message so um like before you can
  456. 20:46get the code for this code lab from our
  457. 20:48GitHub repository um if you've already
  458. 20:51done the edgo edge and predictive back
  459. 20:53code Labs the widget code lab will build
  460. 20:56on top of them as well
  461. 20:59so let's get started actually adding a
  462. 21:01widget uh widget is a part of your
  463. 21:04application that lives inside of an app
  464. 21:06widget host normally this is a home
  465. 21:08screen though it's not required to be
  466. 21:10one um certain information screens and
  467. 21:13the Act and the Android assistant will
  468. 21:16also be able to display widgets um
  469. 21:19jetpack glance is our is Google's new
  470. 21:22recommended way for writing new widgets
  471. 21:24it is in release candidate one right now
  472. 21:28and and will be released for a final
  473. 21:31version soon the way that widgets are
  474. 21:34created is by implementing an app widget
  475. 21:36provider and a remote view with some
  476. 21:39widget information and then setting them
  477. 21:41up in your Android manifest as a
  478. 21:44receiver element um this receiver should
  479. 21:47be exported it should handle the app
  480. 21:50android.app widget. actiona widget
  481. 21:52update action intend and also you should
  482. 21:55pass the app widget provider info file
  483. 21:59in as a metadata element with the
  484. 22:02Android app widget provider name and a
  485. 22:04reference to the
  486. 22:07widget all right so how do we get glance
  487. 22:10in our project well the first thing we
  488. 22:11want to do is make sure that we've added
  489. 22:13glance to our Libs versions. Tomo file
  490. 22:17this is the version catalog
  491. 22:22in this is the version catalog in a
  492. 22:26gradal project um in this particular
  493. 22:29instance we're using the release
  494. 22:30candidate we will also be updating the
  495. 22:32code lab to reference the release
  496. 22:33candidate then you reference the glance
  497. 22:37app widget and glance material 3 modules
  498. 22:41in your version catalog or build.gradle
  499. 22:43file and then you can add them to your
  500. 22:47build.gradle
  501. 22:50file as
  502. 22:54dependencies scrolling keep scrolling
  503. 22:59and you can add them in your
  504. 23:00build.gradle file as
  505. 23:06dependencies all right um if you're just
  506. 23:10adding this to your file this will be
  507. 23:11where you resynchronize your um project
  508. 23:14all right so widgets are written in
  509. 23:17remote views and when you use glance you
  510. 23:19can extend the glance app widget class
  511. 23:21to create these remote views using a CO
  512. 23:23a composed style API using glance
  513. 23:26composes and your app rdet provid
  514. 23:29instead you extend the glance app widget
  515. 23:32receiver class so let's add those to our
  516. 23:35project now um if you open the socialite
  517. 23:38app widget file this is an
  518. 23:41implementation of the glance app widget
  519. 23:44class and it calls this provide glance
  520. 23:46and it provides overrides this provide
  521. 23:48glance method um so for our first widget
  522. 23:53we just want to add a simple hello world
  523. 23:54message and we can do that by create
  524. 23:57using the glance composable text then
  525. 23:59Hello World um we need to imp we need to
  526. 24:04import
  527. 24:06this composable and we want to make sure
  528. 24:08that we use the Android x. glance
  529. 24:10composable and not the compos and not
  530. 24:12the androidex composed material 3
  531. 24:14composable glance composes and Jetpack
  532. 24:17composes are not mutually um creative
  533. 24:21Additionally you want to make sure that
  534. 24:22you provide this method this content in
  535. 24:24the provide content
  536. 24:27method so to repeat that to implement a
  537. 24:30widget using glance you want to extend
  538. 24:32the glance app widget class you want to
  539. 24:34override the provide glance method and
  540. 24:36you want to provide your composes using
  541. 24:38the provide content method in your
  542. 24:40widget next you will want to implement
  543. 24:42the glance app widget receiver
  544. 24:52class oh no and we have that
  545. 24:55implementation stubbed out as the
  546. 24:57socialite app widget receiver in our
  547. 25:00code
  548. 25:01lab um the socialite app widget rece the
  549. 25:03glance app widget receiver
  550. 25:05implementations have this property that
  551. 25:07you need to override called glance app
  552. 25:08widget receiver and normally this should
  553. 25:11just be a no arguments invocation of
  554. 25:15your so of your app widget in our case
  555. 25:17this will be the socialite app widget
  556. 25:20all right so we've implemented our
  557. 25:21glance app widget we've implemented our
  558. 25:23glance app widget receiver the next
  559. 25:25thing we want to do is create our app um
  560. 25:27our app widget provider information XML
  561. 25:30file and we can do that by going into
  562. 25:32our XML resources F folder and
  563. 25:37adding a new XML resource file we'll
  564. 25:40name this
  565. 25:41socialite app widget or socialite widget
  566. 25:47info we will set our root element to app
  567. 25:50widget
  568. 25:52provider and then we will create
  569. 25:55it all right so let's switch back to the
  570. 25:57code real
  571. 25:59quick the app widget provider
  572. 26:02information is a file that tells the
  573. 26:04Android operating system and your app
  574. 26:06widget host information about your
  575. 26:08widget um it tells you whether or not
  576. 26:10the widget's resizable how large it can
  577. 26:12be resized to what it's minimum size is
  578. 26:16whether or not there's a configuration
  579. 26:17activity um what features your widget
  580. 26:20supports in this case we saying that you
  581. 26:22don't require configuration to add your
  582. 26:23widget to your home screen and that the
  583. 26:25widget can be reconfigured after you add
  584. 26:28it we add a preview image to our app
  585. 26:31widget picker and then we also set an
  586. 26:33initial layout in this case this is a
  587. 26:35layout that is provided by the glance
  588. 26:41Library all right and then the last step
  589. 26:44that we want to do is associate all of
  590. 26:46these guys together in our Android
  591. 26:48manifest XML
  592. 26:52file and like I said before we create a
  593. 26:55receiver we make it the socialite app
  594. 26:58which
  595. 26:58receiver we want to make sure that this
  596. 27:02receiver is
  597. 27:05exported and we want to give it a
  598. 27:09label since this is our favorite contact
  599. 27:11widget we'll use the favorite contact
  600. 27:13label then we want to implement the
  601. 27:16intent
  602. 27:22filters and we want to add a action name
  603. 27:29android.app
  604. 27:31widget.
  605. 27:32action. apppp widget
  606. 27:42update and then we also want to
  607. 27:44associate our meta our we want to add a
  608. 27:47metadata element that Associates the app
  609. 27:49widget info file so
  610. 27:52metadata
  611. 27:53name android.app widget. provider
  612. 27:59and then resource at xmls socialite
  613. 28:04widget
  614. 28:05info all right and we'll just double
  615. 28:07check that with our code lab that looks
  616. 28:10good and now when we rerun our socialite
  617. 28:12application we should see in our widget
  618. 28:15picker that we have the social light
  619. 28:18widget
  620. 28:23available ah there it is
  621. 28:28all right we have added our hello world
  622. 28:30widget to our screen you might notice a
  623. 28:32few things one of the things is that it
  624. 28:34doesn't match our preview image we'll
  625. 28:37get to that we'll update it in a moment
  626. 28:39and also it doesn't really seem to have
  627. 28:41a lot of the things we say a good widget
  628. 28:43should have it doesn't have a
  629. 28:45well-defined shape it's kind of hard to
  630. 28:47read it's not really jiving with our
  631. 28:50background theme so the next thing we
  632. 28:51want to do is we want to improve the
  633. 28:54design of our
  634. 28:55widget so when we're thinking about the
  635. 28:59design of our widget we want to think of
  636. 29:00something that keeps the content fresh
  637. 29:02we want to think about something that
  638. 29:04minimizes re the awkward resizing um
  639. 29:07layouts and we also want it to have pick
  640. 29:10up the colors from other widgets in the
  641. 29:11host background um glance provide
  642. 29:14several composes that make this really
  643. 29:16easy let's start by adding a scaffold
  644. 29:18composable to our glance app
  645. 29:21widget um the scaffold composable is
  646. 29:24provided by the glance library and it's
  647. 29:25a simple API for displaying the widget
  648. 29:28UI it includes a title bar and it also
  649. 29:30has some basic padding for its body um
  650. 29:33and it also sets the default color to
  651. 29:35your widget background theme all right
  652. 29:37so let's go back to the socialite app
  653. 29:38widget and add the following code
  654. 29:58and then we fix our Imports
  655. 30:34that that's
  656. 31:11oops okay so what we've done is we've
  657. 31:14done a small refactor we've moved our
  658. 31:16application compos our widget composable
  659. 31:19out of provide content into its own
  660. 31:21composable function we've wrapped it in
  661. 31:23the glance theme composable which allows
  662. 31:25it to which allows our widget to pick up
  663. 31:27the themes from from that are provided
  664. 31:29from glands and then we've added the
  665. 31:31scaffold we've given it a title bar
  666. 31:33we've given the title bar a icon and a
  667. 31:37title socialite and also we've moved our
  668. 31:39hello world text composable into the
  669. 31:41body of the app widget so when we
  670. 31:44relaunch the application and read the
  671. 31:46widget to our home screen we should see
  672. 31:48these updated these updated Design
  673. 31:51Elements appear
  674. 32:01all right good this is a great first
  675. 32:04step so we see that the widget now has a
  676. 32:06background and it's picking up our
  677. 32:08Widget theme from other colors now let's
  678. 32:10switch it over to dark
  679. 32:12mode and the widget automatically adapts
  680. 32:15to that but we see that our text style
  681. 32:17is not quite right we can fix this by
  682. 32:20adding a text style to our text
  683. 32:25composable
  684. 32:35and then we give it a color and we will
  685. 32:37get from our glance
  686. 32:39theme the ons surface color
  687. 32:45token and now we rerun the
  688. 32:52application and we replace our widget
  689. 33:02and now in dark mode our color of our
  690. 33:05text composable is much more legible
  691. 33:07than it was
  692. 33:08before let's go back to our code
  693. 33:11lab so this is all part of Dynamic Color
  694. 33:15where your app widget picks up hints of
  695. 33:18the color from the surrounding
  696. 33:19environment in your home screen launcher
  697. 33:22uh the background and it makes sure that
  698. 33:23your app widget matches the themes of
  699. 33:26your app IC ions as well as your other
  700. 33:30widgets all right so now that we've
  701. 33:32improved the design let's talk a little
  702. 33:34bit about the state of our application
  703. 33:36and how we're going to get the users to
  704. 33:39select their favorite contact from it
  705. 33:42what we want to think about is when a
  706. 33:44user adds a widget to their home screen
  707. 33:46that requires configuration we need to
  708. 33:48add a zero State this is a state that
  709. 33:50should prompt users to do some sort of
  710. 33:53configuration action and then once this
  711. 33:56action is done the widget should update
  712. 33:58itself to show its final layout and
  713. 34:01we're going to do that now um in the Cod
  714. 34:04lab I go into a lot more detail about
  715. 34:06how this data is stored and how it's
  716. 34:08processed um but what you really need to
  717. 34:11know for this demonstration is that
  718. 34:13we're going to use this widget model and
  719. 34:15we're going to use a widget model
  720. 34:16repository class the widget model
  721. 34:18repository class is a class that's
  722. 34:20managed with Hilt and we're going to use
  723. 34:21a getter a Hil getter to get that so
  724. 34:24let's add the zero state to our widget
  725. 34:27and let's also add the repository to our
  726. 34:31provide glance
  727. 34:33method so going back to our
  728. 34:37code all right and cleaning up our
  729. 34:50Imports and moving this down
  730. 34:53here all right so when provide glance is
  731. 34:56called it's provided a widget ID and we
  732. 34:59need to unwrap the glance ID and make it
  733. 35:02a widget ID and then we're going to get
  734. 35:04a reference to our um widget model
  735. 35:06repository which lets us update and
  736. 35:09receive updates from our um widget data
  737. 35:13then we're going to update our content
  738. 35:15repository so that we can pass this V
  739. 35:18the widget repository in our content
  740. 35:21composable to so that we can pass the
  741. 35:23widget repository
  742. 35:25in and then we fix the
  743. 35:55Imports all right so now we load the
  744. 35:58model from our repository and we're
  745. 36:00going to replace our um content method
  746. 36:04with this win block this wind block will
  747. 36:08switch on whether we have a loading
  748. 36:11state or if we have um or if we have an
  749. 36:14actual widget
  750. 36:24model and we're going to use a zero
  751. 36:26state composable that is provided by the
  752. 36:29Cod lab so now
  753. 36:33our and then we need to fix this one
  754. 36:36last thing repository widget ID all
  755. 36:39right so now when our widget ID is when
  756. 36:41our widget is loaded it will get an get
  757. 36:43a reference to our repository load the
  758. 36:46model for the widget and if the model is
  759. 36:49not available display a zero State and
  760. 36:51if the model is available we'll go back
  761. 36:53to displaying our hello world code so
  762. 36:54let's relaunch relaunch our application
  763. 37:00replace our
  764. 37:11widget all right and now we're seeing
  765. 37:13our zero state so if we select choose
  766. 37:15the option to select our favorite
  767. 37:16contact it brings up our configuration
  768. 37:19activity and then when we select our
  769. 37:22contact nothing happens we haven't
  770. 37:25actually added the ability to we haven't
  771. 37:27actually updated our repository from our
  772. 37:29content from our configuration activity
  773. 37:31so let's open the social light app
  774. 37:33widget configuration act
  775. 37:43activity and in the contact row on click
  776. 37:47Handler we are going to do several
  777. 37:50things first we are going
  778. 37:54to first we are going to launch a new
  779. 37:57codage
  780. 37:58we're going to call create or update in
  781. 37:59our widget model repository with our new
  782. 38:01widget model this has the app widget ID
  783. 38:05the contacts ID the contacts name the
  784. 38:07contacts icon and fals to say that they
  785. 38:09have no unread messages then we're going
  786. 38:11to call socialite app widget update all
  787. 38:14which will update all instances of the
  788. 38:15app widget on our home screen and
  789. 38:17finally we're going to set the state of
  790. 38:20the configuration activity so that the
  791. 38:23um Android operating system knows that
  792. 38:25the widget was configured
  793. 38:34and we will import fix our
  794. 38:53Imports and we will rerun our
  795. 38:55application
  796. 39:07and now when we select our favorite
  797. 39:12contact the widget sees that the widget
  798. 39:16model in the background has updated and
  799. 39:18we have our state update from the police
  800. 39:21selector favorite contact to the hello
  801. 39:23world and the last thing we want to do
  802. 39:24is we want to go back to our socialite
  803. 39:26app widget
  804. 39:29and we want to replace this text
  805. 39:31composable with our favorite contact
  806. 39:34composable and
  807. 39:45that fix our Imports
  808. 40:11I and now when we rerun our application
  809. 40:13for the last
  810. 40:20time oh there is an error
  811. 40:31and now when we reun rerun our
  812. 40:33application for the last
  813. 40:37time when we select our favorite
  814. 40:42contact our widget updates and so now
  815. 40:45that that we have a widget model saved
  816. 40:46in the database and our widget updates
  817. 40:49the glance composable recomposes the
  818. 40:51widget and it shows our widget with its
  819. 40:53new default State and if we go to the
  820. 40:56socialite app and we go to the dog and
  821. 40:59we send it a
  822. 41:02message when the dog responds in a few
  823. 41:04seconds we'll see that our widget States
  824. 41:06updated updates to say that we have a
  825. 41:14message see that our widget State
  826. 41:16updates to say that we have a message
  827. 41:31ah there it goes all right so and now
  828. 41:34when we click on the widget we read our
  829. 41:37message and the widget updates to say
  830. 41:39that there are no new messages um in the
  831. 41:41code lab we also do cover uh maintaining
  832. 41:43and updating your data to keep your
  833. 41:45State uh in sync as well as to clean up
  834. 41:48any data that happens that any data that
  835. 41:50happens to get orphaned when you close
  836. 41:51the dog or when you close the when you
  837. 41:54remove the widget all right and with
  838. 41:55that we've added a widget to social
  839. 41:57we've added edge-to-edge design and
  840. 41:59we've added a predictive back animation
  841. 42:01Ash would you like to come up and help
  842. 42:03us close
  843. 42:08outk you so much all yeah as summer said
  844. 42:11we've added edge to edge predictive back
  845. 42:13and glance to socialite now socialite is
  846. 42:16looking much more premium and satisfying
  847. 42:19than it did before we hope that you can
  848. 42:21take these learnings back to your
  849. 42:23application thank you all again very
  850. 42:26much
  851. 42:30[Applause]
  852. 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.