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

[Anton Minashkin] Android Slices: Searchify you...

[Anton Minashkin] Android Slices: Searchify your app

Presentation from GDG DevFest Ukraine 2018 - the biggest community-driven Google tech conference in the CEE.

Learn more at: https://devfest.gdg.org.ua

__

Slices is the new API introduced as part of Android P (and a Jetpack). The main aim of it is to provide yet another way for app to present it content remotely. Lets discuss how we can use it to build interactive Google Search results on Android and make better integration with Google Assistant.

Google Developers Group Lviv

October 12, 2018
Tweet

More Decks by Google Developers Group Lviv

Other Decks in Technology

Transcript

  1. #dfua Slices Support for Slices is built into Android Jetpack

    and can extend all the way back to Android 4.4
  2. #dfua Example class MySliceProvider : SliceProvider() { override fun onMapIntentToUri(intent:

    Intent?): Uri {...} override fun onBindSlice(sliceUri: Uri): Slice? {...} private fun createActivityAction(): SliceAction? {...} override fun onSlicePinned(sliceUri: Uri?) {...} override fun onSliceUnpinned(sliceUri: Uri?) {...} }
  3. #dfua Example class MySliceProvider : SliceProvider() { override fun onMapIntentToUri(intent:

    Intent?): Uri {...} override fun onBindSlice(sliceUri: Uri): Slice? {...} private fun createActivityAction(): SliceAction? {...} override fun onSlicePinned(sliceUri: Uri?) {...} override fun onSliceUnpinned(sliceUri: Uri?) {...} }
  4. #dfua Example class MySliceProvider : SliceProvider() { override fun onMapIntentToUri(intent:

    Intent?): Uri {...} override fun onBindSlice(sliceUri: Uri): Slice? {...} private fun createActivityAction(): SliceAction? {...} override fun onSlicePinned(sliceUri: Uri?) {...} override fun onSliceUnpinned(sliceUri: Uri?) {...} }
  5. #dfua Example class MySliceProvider : SliceProvider() { override fun onMapIntentToUri(intent:

    Intent?): Uri {...} override fun onBindSlice(sliceUri: Uri): Slice? {...} private fun createActivityAction(): SliceAction? {...} override fun onSlicePinned(sliceUri: Uri?) {...} override fun onSliceUnpinned(sliceUri: Uri?) {...} }
  6. #dfua Example class MySliceProvider : SliceProvider() { override fun onMapIntentToUri(intent:

    Intent?): Uri {...} override fun onBindSlice(sliceUri: Uri): Slice? {...} private fun createActivityAction(): SliceAction? {...} override fun onSlicePinned(sliceUri: Uri?) {...} override fun onSliceUnpinned(sliceUri: Uri?) {...} }
  7. #dfua Example class MySliceProvider : SliceProvider() { override fun onMapIntentToUri(intent:

    Intent?): Uri {...} override fun onBindSlice(sliceUri: Uri): Slice? {...} private fun createActivityAction(): SliceAction? {...} override fun onSlicePinned(sliceUri: Uri?) {...} override fun onSliceUnpinned(sliceUri: Uri?) {...} }
  8. #dfua onBindSlice override fun onBindSlice(sliceUri: Uri): Slice? { val activityAction

    = createActivityAction() return if (sliceUri.path == "/hello") { list(context, sliceUri, ListBuilder.INFINITY) { row { primaryAction = activityAction title = "Hello World." } } } else {...} }
  9. #dfua onBindSlice override fun onBindSlice(sliceUri: Uri): Slice? { val activityAction

    = createActivityAction() return if (sliceUri.path == "/hello") { list(context, sliceUri, ListBuilder.INFINITY) { row { primaryAction = activityAction title = "Hello World." } } } else {...} }
  10. #dfua Dynamic Slices list(context, sliceUri, ListBuilder.INFINITY) { row { primaryAction

    = toastAndIncrementAction title = "Count: ${MyBroadcastReceiver.receivedCount}" subtitle = "Click me" } }
  11. #dfua Dynamic Slices list(context, sliceUri, ListBuilder.INFINITY) { row { primaryAction

    = toastAndIncrementAction title = "Count: ${MyBroadcastReceiver.receivedCount}" subtitle = "Click me" } }
  12. #dfua Dynamic Slices class MyBroadcastReceiver : BroadcastReceiver() { override fun

    onReceive(context: Context, intent: Intent) { ... } companion object { var receivedCount = 0 } }
  13. #dfua Dynamic Slices class MyBroadcastReceiver : BroadcastReceiver() { override fun

    onReceive(context: Context, intent: Intent) { ... } companion object { var receivedCount = 0 } }
  14. #dfua Dynamic Slices override fun onReceive(context: Context, intent: Intent) {

    if (intent.hasExtra(Slice.EXTRA_TOGGLE_STATE)) { Toast.makeText(...).show() receivedCount++; context.contentResolver.notifyChange(sliceUri, null) } }
  15. #dfua Dynamic Slices override fun onReceive(context: Context, intent: Intent) {

    if (intent.hasExtra(Slice.EXTRA_TOGGLE_STATE)) { Toast.makeText(...).show() receivedCount++; context.contentResolver.notifyChange(sliceUri, null) } }
  16. #dfua Dynamic Slices override fun onReceive(context: Context, intent: Intent) {

    if (intent.hasExtra(Slice.EXTRA_TOGGLE_STATE)) { Toast.makeText(...).show() receivedCount++; context.contentResolver.notifyChange(sliceUri, null) } }
  17. #dfua SliceAction A SliceAction contains a label along with a

    PendingIntent and is one of the following: • Icon button • Default toggle • Custom toggle (a drawable with an on/off state)
  18. #dfua SliceAction return list(context, wifiUri, ListBuilder.INFINITY) { setAccentColor(0xff4285) // Specify

    color for tinting icons / controls. row { title = "Wi-Fi" primaryAction = wifiAction addEndItem(toggleAction) } }
  19. #dfua SliceAction return list(context, wifiUri, ListBuilder.INFINITY) { setAccentColor(0xff4285) // Specify

    color for tinting icons / controls. row { title = "Wi-Fi" primaryAction = wifiAction addEndItem(toggleAction) } }
  20. #dfua SliceAction return list(context, wifiUri, ListBuilder.INFINITY) { setAccentColor(0xff4285) // Specify

    color for tinting icons / controls. row { title = "Wi-Fi" primaryAction = wifiAction addEndItem(toggleAction) } }
  21. #dfua SliceAction return list(context, wifiUri, ListBuilder.INFINITY) { setAccentColor(0xff4285) // Specify

    color for tinting icons / controls. row { title = "Wi-Fi" primaryAction = wifiAction addEndItem(toggleAction) } }