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

What's New in Android - I/O Extended Yangon 2018

What's New in Android - I/O Extended Yangon 2018

Talk from I/O Extended Yangon 2018.

Aung Kyaw Paing

July 08, 2018
Tweet

More Decks by Aung Kyaw Paing

Other Decks in Technology

Transcript

  1. What’s new in Android?
    Photo Ⓒ Rami Al-zayat

    View full-size slide

  2. What’s new in Android P?
    Photo Ⓒ Lauren Robert

    View full-size slide

  3. Notch Support
    Photo Ⓒ Google

    View full-size slide

  4. Notch Support
    - DisplayCount class
    - getDisplayCutout() method
    - New window attribute, layoutInDisplayCutoutMode
    - LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
    - LAYOUT_IN_DISPLAY_CUTOUT_SHORT EDGES
    - LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER

    View full-size slide

  5. LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
    - The notch has to be contained in System Bar
    - If not, the window won’t overlap it

    View full-size slide

  6. LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
    - Can extends into notch
    - Developer has to handle drawing

    View full-size slide

  7. LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
    - Will never overlaps

    View full-size slide

  8. Notch Support
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    val windowAttributes = window.attributes
    windowAttributes.layoutInDisplayCutoutMode =
    WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT
    }

    View full-size slide

  9. Notification
    - Person API
    - Can now display Image
    - Reply drafts
    - Group conversations support
    - Semantic Action (Reply, Mark as
    read, thumbs up… etc.)
    - Smart Reply
    Photo Ⓒ Google

    View full-size slide

  10. Notification
    // create new Person
    val sender = Person()
    .setName(name)
    .setUri(uri)
    .setIcon(null)
    .build()
    // create image message
    val message = Message("Picture", time, sender)
    .setData("image/";, imageUri)
    val style = Notification.MessagingStyle(getUser())
    .addMessage("Check this out!", 0, sender)
    .addMessage(message)

    View full-size slide

  11. Notification Channel
    - Can block entire “groups” of channel
    - Can check if blocked via isBlocked
    - New policies

    View full-size slide

  12. TextView
    Photo Ⓒ Best practices for text on Android ( Google IO / 18 )

    View full-size slide

  13. Photo Ⓒ Best practices for text on Android ( Google IO / 18 )

    View full-size slide

  14. PreComputed Text
    // UI thread
    val params: PrecomputedText.Params = textView.getTextMetricsParams()
    val ref = WeakReference(textView)
    executor.execute {
    // background thread
    val text = PrecomputedText.create("Hello", params)
    val textView = ref.get()
    textView?.post {
    // UI thread
    val textViewRef = ref.get()
    textViewRef?.text = text
    }
    }

    View full-size slide

  15. Magnifier
    fun onTouchEvent(event: MotionEvent): Boolean {
    when (event.actionMasked) {
    MotionEvent.ACTION_DOWN ->
    magnifier.show(event.x, event.y)
    MotionEvent.ACTION_MOVE ->
    magnifier.show(event.x, event.y)
    MotionEvent.ACTION_UP ->
    magnifier.dismiss()
    }
    }

    View full-size slide

  16. Smart Linkify

    View full-size slide

  17. Smart Linkify
    // UI thread
    val text: Spannable = ...
    val request = TextLinks.Request.Builder(text)
    val ref = WeakReference(textView)
    executor.execute {
    // background thread
    TextClassifier.generateLinks(request).apply(text)
    val textView = ref.get()
    textView?.post {
    // UI thread
    val textViewRef = ref.get()
    textViewRef?.text = text
    }
    }

    View full-size slide

  18. Fingerprint Auth

    View full-size slide

  19. And….
    - Indoor positioning
    - Multi-camera support
    - ImageDecoder
    - AnimatedImageDrawable
    - Client side encryptions for backups
    - New accessibility features
    - Autofill improvements
    - And Many more!

    View full-size slide

  20. What’s new in Android Support Library?
    Photo Ⓒ Leo Fosdal

    View full-size slide

  21. Major Refactor
    android.support.v4.*
    android.support.v7.*
    android.support.v9.*
    android.support.v14.*

    View full-size slide

  22. Major Refactor
    android.support.*
    androidx.*

    View full-size slide

  23. Major Refactor
    Available in Android Studio Canary Channel

    View full-size slide

  24. Major Refactor
    https://developer.android.com/topic/libraries/support-library/refactor

    View full-size slide

  25. Android KTX
    https://github.com/android/android-ktx

    View full-size slide

  26. Android KTX
    sharedPreferences.edit {
    putBoolean("key", value)
    putLong("key2", value2)
    }
    val args = bundleOf {
    "key" to 1,
    "key2" to true
    }

    View full-size slide

  27. Android JetPack
    https://developer.android.com/jetpack/

    View full-size slide

  28. Slices
    - UI templates with interactive contents
    - Used in Google Search, Google Assistant

    View full-size slide

  29. Slices
    fun createSliceWithGridRow(sliceUri: Uri): Slice {
    // Create the parent builder.
    return list(context, sliceUri, ListBuilder.INFINITY) {
    header {
    setTitle("Famous restaurants")
    setPrimaryAction(SliceAction(pendingIntent, icon, "Famous restaurants"))
    }
    gridRow {
    cell {
    addImage(image1, LARGE_IMAGE)
    addTitleText("Top Restaurant")
    addText("0.3 mil")
    setContentIntent(intent1)
    }
    cell {
    addImage(image2, LARGE_IMAGE)
    addTitleText("Fast and Casual")
    addText("0.5 mil")
    setContentIntent(intent2)
    }
    }
    }
    }

    View full-size slide

  30. Actions
    - Can recommend actions to users
    - Increases discoverability

    View full-size slide

  31. RecyclerView ListAdapter
    - Uses DiffUtils
    - Automatic Animation

    View full-size slide

  32. class MovieRecyclerViewAdapter :
    ListAdapter() {
    }
    RecyclerView ListAdapter

    View full-size slide

  33. RecyclerView ListAdapter
    companion object {
    private val MOVIE_DIFF_CALLBACK = object : DiffUtil.ItemCallback() {
    override fun areItemsTheSame(item1: Movie, item2: Movie): Boolean {
    return item1.id == item2.id
    }
    override fun areContentsTheSame(item1: Movie, item2: Movie): Boolean {
    return item1 == item2
    }
    }
    }

    View full-size slide

  34. class MovieRecyclerViewAdapter :
    ListAdapter(MOVIE_DIFF_CALLBACK) {
    companion object {
    private val MOVIE_DIFF_CALLBACK = object : DiffUtil.ItemCallback() {
    override fun areItemsTheSame(item1: Movie, item2: Movie): Boolean {
    return item1.id == item2.id
    }
    override fun areContentsTheSame(item1: Movie, item2: Movie): Boolean {
    return item1 == item2
    }
    }
    }
    }
    RecyclerView ListAdapter

    View full-size slide

  35. movieListLiveData.observe(this, Observer {itemList ->
    movieRecyclerViewAdapter.submitList(itemList)
    })
    RecyclerView ListAdapter

    View full-size slide

  36. RecyclerView Selection
    - Allow select/deselect multiple items in list
    SelectionTracker tracker = new SelectionTracker.Builder<>(
    "my-selection-id",
    recyclerView,
    new StableIdKeyProvider(recyclerView),
    new MyDetailsLookup(recyclerView),
    StorageStrategy.createLongStorage())
    .build();

    View full-size slide

  37. Material Components
    https://material.io/

    View full-size slide

  38. BottomAppBar

    View full-size slide

  39. BottomAppBar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    android:id="@+id/bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:navigationIcon="@drawable/ic_menu_24"/>
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_anchor="@id/bar"/>

    View full-size slide

  40. MaterialButton

    View full-size slide

  41. MaterialButton
    android:id="@+id/material_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_label_enabled"/>

    View full-size slide

  42. MaterialCardView

    View full-size slide

  43. MaterialCardView
    style="@style/Widget.MaterialComponents.CardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/mtrl_card_spacing"
    android:layout_marginTop="@dimen/mtrl_card_spacing"
    android:layout_marginRight="@dimen/mtrl_card_spacing"
    android:minHeight="200dp">


    View full-size slide

  44. Chips
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:chipText="@string/hello_world"/>
    style="@style/Widget.MaterialComponents.Chip.Entry"
    style="@style/Widget.MaterialComponents.Chip.Filter"
    style="@style/Widget.MaterialComponents.Chip.Choice"

    View full-size slide

  45. Chips
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    View full-size slide

  46. Android Arch Components
    - Paging Library
    - WorkManager
    - Navigation

    View full-size slide

  47. - Use for enqueuing background works
    - JobScheduler for API 23+
    - Firebase JobDispatcher (or) custom AlarmManager + Broadcast
    Receiver for backport
    WorkManager

    View full-size slide

  48. val workManager = WorkManager.getInstance()
    val workRequest = OneTimeWorkRequest.Builder(SyncWorker::class.java).build()
    workManager.enqueue(workRequest)
    WorkManager

    View full-size slide

  49. val workManager = WorkManager.getInstance()
    val workConstraints = Constraints.Builder()
    .setRequiredNetworkType(NetworkType.METERED)
    .setRequiresCharging(true)
    .setRequiresStorageNotLow(false)
    .build()
    val workRequest = OneTimeWorkRequest.Builder(SyncWorker::class.java)
    .setConstraints(workConstraints)
    .build()
    workManager.enqueue(workRequest)
    WorkManager

    View full-size slide

  50. val workManager = WorkManager.getInstance()
    val workRequest = OneTimeWorkRequest.Builder(SyncWorker::class.java).build()
    workManager.enqueue(workRequest)
    WorkManager

    View full-size slide

  51. val workManager = WorkManager.getInstance()
    val workRequest = OneTimeWorkRequest.Builder(SyncWorker::class.java).build()
    workManager.enqueue(workRequest)
    val workStatusLiveData = workManager.getStatusById(workRequest.id)
    workStatusLiveData.observe(this, Observer { workStatus ->
    when (workStatus?.state) {
    State.ENQUEUED -> TODO()
    State.RUNNING -> TODO()
    State.SUCCEEDED -> TODO()
    State.FAILED -> TODO()
    State.BLOCKED -> TODO()
    State.CANCELLED -> TODO()
    }
    })
    WorkManager

    View full-size slide

  52. val workManager = WorkManager.getInstance()
    val workRequest = OneTimeWorkRequest.Builder(SyncWorker::class.java).build()
    workManager.enqueue(workRequest)
    workManager.cancelWorkById(workRequest.id)
    WorkManager

    View full-size slide

  53. WorkManager
    val workManager = WorkManager.getInstance()
    val request1 = OneTimeWorkRequest.Builder(FooWorker::class.java).build()
    val request2 = OneTimeWorkRequest.Builder(BarWorker::class.java).build()
    val request3 = OneTimeWorkRequest.Builder(BazWorker::class.java).build()
    workManager.beginWith(request1, request2).then(request3).enqueue()

    View full-size slide

  54. Navigation Arch Component
    - Single Activity, Multiple Fragment
    - Uses “Stack”, last-in first out structure
    - Deep Link has same stack

    View full-size slide

  55. Navigation Arch Component

    View full-size slide

  56. Navigation Arch Component

    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    app:startDestination=“@id/blankFragment">
    android:id="@+id/blankFragment"
    android:name="com.example.cashdog.cashdog.BlankFragment"
    android:label="fragment_blank"
    tools:layout="@layout/fragment_blank" />
    android:id="@+id/blankFragment2"
    android:name="com.example.cashdog.cashdog.BlankFragment2"
    android:label="Blank2"
    tools:layout="@layout/fragment_blank_fragment2" />

    View full-size slide

  57. Navigation Arch Component

    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    app:startDestination=“@id/blankFragment">
    android:id="@+id/blankFragment"
    android:name="com.example.cashdog.cashdog.BlankFragment"
    android:label="fragment_blank"
    tools:layout="@layout/fragment_blank" >
    android:id="@+id/action_blankFragment_to_blankFragment2"
    app:destination="@id/blankFragment2" />

    android:id="@+id/blankFragment2"
    android:name="com.example.cashdog.cashdog.BlankFragment2"
    android:label="fragment_blank_fragment2"
    tools:layout="@layout/fragment_blank_fragment2" />

    View full-size slide

  58. Navigation Arch Component
    ?xml version="1.0" encoding="utf-8"?>
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/my_nav_host_fragment"
    android:name="androidx.navigation.fragment.NavHostFragment"
    app:navGraph="@navigation/nav_graph"
    app:defaultNavHost="true"
    />

    View full-size slide

  59. Navigation Arch Component
    override fun onSupportNavigateUp()
    = findNavController(R.id.nav_host_fragment).navigateUp()

    View full-size slide

  60. Navigation Arch Component
    button.setOnClickListener(
    Navigation.createNavigateOnClickListener(R.id.next_fragment, null)
    )

    View full-size slide

  61. android:label="@string/details"
    android:name="com.example.android.myapp.DetailsFragment" />
    Navigation Arch Component -
    NavigationView(Drawer)

    View full-size slide

  62. android:label="@string/details"
    android:name="com.example.android.myapp.DetailsFragment" />
    android:id="@id/details_page_fragment"
    android:icon="@drawable/ic_details"
    android:title="@string/details" />
    Navigation Arch Component -
    NavigationView(Drawer)

    View full-size slide

  63. android:label="@string/details"
    android:name="com.example.android.myapp.DetailsFragment" />
    android:id="@id/details_page_fragment"
    android:icon="@drawable/ic_details"
    android:title="@string/details" />
    val navController = Navigation.findNavController(this, R.id.nav_host_fragment)
    val navigationView = findViewById(R.id.nav_view)
    navigationView.setupWithNavController(navController)
    Navigation Arch Component -
    NavigationView(Drawer)

    View full-size slide

  64. Navigation Arch Component - Arguments
    android:id="@+id/confirmationFragment"
    android:name="com.example.cashdog.cashdog.ConfirmationFragment"
    android:label="fragment_confirmation"
    tools:layout="@layout/fragment_confirmation">

    View full-size slide

  65. Navigation Arch Component - Arguments
    android:id="@+id/confirmationFragment"
    android:name="com.example.cashdog.cashdog.ConfirmationFragment"
    android:label="fragment_confirmation"
    tools:layout="@layout/fragment_confirmation">

    var bundle = bundleOf("amount" to amount)
    view.findNavController().navigate(R.id.confirmationAction, bundle)

    View full-size slide

  66. Navigation Arch Component - Arguments
    android:id="@+id/confirmationFragment"
    android:name="com.example.cashdog.cashdog.ConfirmationFragment"
    android:label="fragment_confirmation"
    tools:layout="@layout/fragment_confirmation">

    var bundle = bundleOf("amount" to amount)
    view.findNavController().navigate(R.id.confirmationAction, bundle)
    val tv = view.findViewById(R.id.textViewAmount)
    tv.text = arguments.getString("amount")

    View full-size slide

  67. Navigation Arch Component - Safe Args
    apply plugin: 'com.android.application'
    apply plugin: 'androidx.navigation.safeargs'
    android {
    //...
    }

    View full-size slide

  68. Navigation Arch Component - Safe Args
    android:id="@+id/confirmationFragment"
    android:name="com.example.buybuddy.buybuddy.ConfirmationFragment"
    android:label="fragment_confirmation"
    tools:layout="@layout/fragment_confirmation">


    View full-size slide

  69. Navigation Arch Component - Safe Args
    android:id="@+id/specifyAmountFragment"
    android:name="com.example.buybuddy.buybuddy.SpecifyAmountFragment"
    android:label="fragment_specify_amount"
    tools:layout="@layout/fragment_blank" >
    android:id="@+id/action_specify_to_confirm"
    app:destination="@id/confirmationFragment" />

    android:id="@+id/confirmationFragment"
    android:name="com.example.buybuddy.buybuddy.ConfirmationFragment"
    android:label="fragment_confirmation"
    tools:layout="@layout/fragment_confirmation">
    >

    View full-size slide

  70. Navigation Arch Component - Safe Args
    override fun onClick(v: View?) {
    val amount = 100
    val action = SpecifyAmountFragmentDirections.confirmationAction(amount)
    v.findNavController().navigate(action)
    }

    View full-size slide

  71. Navigation Arch Component - Safe Args
    override fun onClick(v: View?) {
    val amount = 100
    val action = SpecifyAmountFragmentDirections.confirmationAction(amount)
    v.findNavController().navigate(action)
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    val tv: TextView = view.findViewById(R.id.textViewAmount)
    val amount = ConfirmationFragmentArgs.fromBundle(arguments).amount
    tv.text = amount.toString()
    }

    View full-size slide

  72. https://github.com/googlesamples/android-sunflower

    View full-size slide

  73. ConstraintLayout 1.1
    - Barrier
    - Group
    - Circular constraints
    - Chains
    - Constraint set

    View full-size slide

  74. ConstraintLayout 2.0
    - ConstraintProperties
    - MotionLayout
    - Better Optimizers

    View full-size slide

  75. - Kotlin Support
    - New APIs
    Testing

    View full-size slide

  76. - Kotlin Support
    - New APIs
    assertEquals(view.visibility, View.VISIBLE)
    Testing

    View full-size slide

  77. - Kotlin Support
    - New APIs
    assertEquals(view.visibility, View.VISIBLE)
    “Failed Expected 0 but was 16”
    Testing

    View full-size slide

  78. - Kotlin Support
    - New APIs
    assertEquals(view.visibility, View.VISIBLE)
    Testing

    View full-size slide

  79. - Kotlin Support
    - New APIs
    assertThat(view).isVisible()
    Testing

    View full-size slide

  80. - Kotlin Support
    - New APIs
    assertThat(view).isVisible()
    “Failed, view was not visible”
    Testing

    View full-size slide

  81. Testing
    - Roboelectric to be packaged inside androidx.test
    - Roboelectric semantics will be same as Espresso
    http://robolectric.org/blog/2018/05/09/robolectric-4-0-alpha/

    View full-size slide

  82. Testing
    - Roboelectric to be packaged inside androidx.test
    - Roboelectric semantics will be same as Espresso
    - Will be able to run UI test in local JVM
    http://robolectric.org/blog/2018/05/09/robolectric-4-0-alpha/

    View full-size slide

  83. Project Nitrogen

    View full-size slide

  84. What’s new in Android Development Tools?
    Photo Ⓒ Fleur Treurniet

    View full-size slide

  85. App Bundle
    - A new publishing format, instead of APK
    - Minimized APK depends on user’s device
    - Deliver downloadable “dynamic feature”

    View full-size slide

  86. D8
    - New dex-ing tool
    - Default already on Android Studio 3.1
    - Manually turn on by adding android.enableD8=true in
    gradle.properties

    View full-size slide

  87. R8
    - Better Proguard
    - Can include proguard rules in java library module by placing
    inside “META-INF/proguard”

    View full-size slide

  88. Emulator
    - Saving states (Cold boot / Hot boot)
    - AMD CPU support
    - Notch emulation
    - Sceneform emulation

    View full-size slide

  89. Android Studio Canary
    - Navigation Arch Component Support
    - MotionLayout Support
    - Better Profiler
    - WebP support

    View full-size slide

  90. Android Studio on ChromeOS

    View full-size slide

  91. Play Store
    - Digital Rights Management(DRM) metadata
    - App now have to be complaint with GDPR
    - Algorithm changes
    - Must have minimum API level 26 by end of August 2018

    View full-size slide