Support Library 28.0.0 Alpha 1に触れてみる

Support Library 28.0.0 Alpha 1に触れてみる

Support Library 28.0.0 Alpha 1に触れてみる

文字起こし
https://github.com/operando/Notes/tree/master/Mercari_Meetup_for_Mobile_App_Engineer_in_Fukuoka

Mercari Meetup for Mobile App Engineer in Fukuoka
https://mercari.connpass.com/event/83957/

E77b6a5f919f7366d94f21eee9a014f5?s=128

operandoOS

April 25, 2018
Tweet

Transcript

  1. Support Library
 28.0.0 Alpha 1ʹ
 ৮ΕͯΈΔ Mercari Meetup for 


    Mobile App Engineer
 in Fukuoka
  2. About Me • AndroidΤϯδχΞ • ϝϧΧϦ → ι΢κ΢ → ϝϧΧϦ

    • ϓϩήʔϚʔ໨ࢦͯ͠·͢ʂ • Discord : operandoOS • Steam : operandoOS
  3. Support Library
 28.0.0 Alpha 1

  4. Support Library 28.0.0 Alpha 1 https://developer.android.com/ topic/libraries/support-library/ revisions.html#28-0-0-alpha1

  5. • όά΋͋Δ͠ɺAPI surfaceมΘΔ͔΋ͳͷͰʂ • Կ͕ى͖ͯ΋ͼͬ͘Γ͠ͳ͍ʂ͘Β͍ͷؾ࣋ͪͰ ࢼ͆͢ Support Library 28.0.0 Alpha

    1
  6. Important changes

  7. androidx: Hello World! • package name͕androidxʹͳΔ • Android KTX͔Β࠾༻͞Ε࢝Ίͨ΍ͭ •

    ৽͍͠Support Library͔ΒͳΔ • heifwriter,recyclerview-selection
  8. Split libraries “split parts of support-core-ui, support-core-utils, and 
 support-compat

    into smaller libraries”
  9. Split libraries • ґଘؔ܎Λ੾Γ཭ͨ͢Ίʹখ͍͞Libraryʹ
 ෼ׂ͢Δ • Google's Maven RepositoryΛݟΔͱ
 Ͳͷ୯ҐͰLibrary͕͋Δͷ͔Θ͔Δ

    • https://dl.google.com/dl/android/maven2/ index.html
  10. New APIs

  11. recyclerview-selection • ৄ͘͠ॻ͍ͯ͘Εͨkgmyshin͞Μͷݟͯʂ • Support Library 28.0.0 alpha৽APIͷ recyclerview-selectionΛ࢖ͬͯΈͨ •

    https://inside.dmm.com/entry/ 2018/03/22/recyclerview-selection
  12. HeifWriter • High Efficiency Image File Format • iOS͸iOS11͔Β࠾༻ͯ͠Δ •

    Android PͰ΋ެࣜαϙʔτ • HeifWriter͸HEIF-formatͰॻ͖ࠐΈ͕Ͱ͖Δ • Read΋Support LibraryͰग़Δ͜ͱظ଴͍ͨ͠ʂ
  13. HeifWriter https://developer.android.com/reference/ androidx/heifwriter/HeifWriter.html

  14. New application theme Theme.MaterialComponents

  15. Theme.MaterialComponents <style name="Theme.MaterialComponents"
 parent="Base.Theme.MaterialComponents"/> <style name="Base.Theme.MaterialComponents"
 parent="Base.V14.Theme.MaterialComponents"/> <style name=“Base.V14.Theme.MaterialComponents" parent="Platform.MaterialComponents">

    ... </style>
  16. Theme.MaterialComponents • Theme.MaterialComponentsͷఆٛ • https://github.com/material-components/material- components-android/blob/master/lib/java/android/ support/design/theme/res/values/themes.xml#L28 • Base.V14.Theme.MaterialComponentsͷఆٛ •

    https://github.com/material-components/material- components-android/blob/master/lib/java/android/ support/design/theme/res/values/themes_base.xml#L33
  17. New components • BottomAppBar • Chip • ChipGroup • MaterialButton

    • MaterialCardView
  18. New components • ίʔυ͸Material Components for AndroidΛ ࢀর͢Δͱྑͦ͞͏ • https://github.com/material-components/

    material-components-android
  19. MaterialButton • rippleColorͱ͔strokeͷઃఆ͕Ͱ͖Δ • selectorͱ͔ॻ͔ͳͯ͘ྑ͘ͳΓͦ͏ͳͷͰ ૉ੖Β͍͠ʂ • 4ܥͰrippleColorͰഎܠ৭͕ృΓͭͿ͞ΕΔ bugͬΆ͍ͷ͕͋Δ

  20. MaterialButton <android.support.design.button.MaterialButton android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:minHeight="48dp" android:text="Hello World!" app:cornerRadius="4dp" app:icon="@drawable/ic_android_black_24dp"

    app:rippleColor="#00ff00" />
  21. MaterialButton

  22. MaterialButton <android.support.design.button.MaterialButton android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:minHeight="48dp" android:text="Hello World!" app:cornerRadius="4dp" app:icon="@drawable/ic_android_black_24dp"

    app:rippleColor="#00ff00" app:strokeColor="@color/colorPrimary" app:strokeWidth="4dp" />
  23. MaterialButton

  24. New components • ঺հ͠ͳ͔ͬͨComponentͷ࢖͍ํ͸ҎԼΛಡΉ ͱॻ͍ͯ͋Γ·͢ʂ • Exploring the v28 Android

    Design Support Library Additions • https://medium.com/google-developer- experts/exploring-the-v28-android-design- support-library-2c96c6031ae8
  25. Slices

  26. What are Slices? “Slices provides a framework for apps to

    embed templated content from other apps.”
  27. What are Slices? • ͱ͋ΔղઆϒϩάͰGoogle Assistantͱ͔ʹࣗ਎ͷ ΞϓϦͷ৘ใΛPluginతʹఏڙͰ͖ΔΑ͏ʹ͢ΔAPI
 ͱ͍͏Ծઆ͕ॻ͔ΕͯΔ • PluginΛఏڙ͢ΔͷʹՁ஋͕͋ΔΞϓϦ͸ࢼͯ͠


    ΈΔͱ͍͍͔΋ • PluginΛ׆༻ͯ͠໘ന͍ΞϓϦΛ࡞ΕΔ͔΋
  28. What are Slices? • ·ͩṖʹแ·ΕͯΔAPI • ͍ͨͩ͢͝ڵຯਂ͍ • Android P

    Preview 2ʹظ଴ʂ • ·ͩPreview 1ͳͷͰAPI͸όΪʔ
  29. What are Slices? • ଞਓͷΞϓϦ͕ఏڙ͢ΔSliceΛࣗ਎ͷΞϓϦʹ
 දࣔ͢Δ͜ͱͰɺଞਓͷΞϓϦͷUI΍ػೳ͕
 ࣗ਎ͷΞϓϦͰ࢖͑Δײ • ͦͷٯ΋Ͱ͖Δ =

    ࣗ਎ͷΞϓϦ͕SliceΛఏڙ͢Δ • UI͸͋Δఔ౓ܾ·ͬͨܗ • Slice Provide AppͱSlice Host App
  30. Slice Provide App • SliceProviderΛ࣮૷͢Δ • SliceProvider͸ContentProviderΛܧঝͨ͠΋ͷ • Format BuilderΈ͍ͨͳͷͰUI(Slice)Λ࡞Δ

    • SliceProvider͕Uri or IntentʹԠͨ͡SliceΛฦ͢
  31. Slice Host App • SliceManagerʹUri or IntentΛ౉͠ SliceProviderͱbind͢Δ • SliceProvider͔Βฦ͖ͬͯͨSliceΛ

    SliceViewʹηοτ͢Δ
  32. Slicesͷେ·ͳ͔ྲྀΕ

  33. Slices & Permission • SliceProvider͔ΒSliceΛऔಘ͢Δʹ͸Permission͕ඞཁ • Permissionʹؔ͢ΔAPIपΓ͕·ͩṖ͍͠ɺόΪʔ • ͜Μͳײͬ͡Ά͍ʂͷཧղͰOKɻมΘΔ͔΋͠Εͳ͍͠

  34. Slices & Permission • Permission͑ͪ͞ΌΜͱϢʔβ͕ঝೝ͢Ε͹
 ͲͷΞϓϦͰ΋SliceProviderΛఏڙͯ͠Δ
 ΞϓϦ͔ΒSliceΛऔಘͰ͖Δ • Slice Host

    App͕୯ҰΞϓϦ or શͯͷΞϓϦͷ SliceΛऔಘͰ͖ΔΑ͏ʹ͢Δ͔Ͳ͏͔
  35. Slices & Permission

  36. Slices Support Library • com.android.support:slices-builders • Slice Provide AppͷͨΊͷAPI •

    com.android.support:slices-view • Slice Host AppͷͨΊͷAPI • com.android.support:slices-core • Slices APIͷίΞ
  37. Slice Provide Appͷ࣮૷

  38. SliceProviderͷ࣮૷ • onBindSliceͰUriʹԠͨ͡SliceΛฦ͢ • Slice͸BuilderΛ࢖ͬͯ࡞Δ • ListBuilder,GridBuilderͳͲ͕͋Δ • ͋Δఔ౓ܾ·ͬͨUIͷϑΥʔϚοτͰදݱ͢Δ

  39. SliceProviderͷ࣮૷ class SampleSliceProvider : SliceProvider() { private var counter =

    0 override fun onCreateSliceProvider(): Boolean { return true } override fun onBindSlice(sliceUri: Uri): Slice { return when (sliceUri.path) { "/time" -> createTimeSlice(sliceUri) else -> createTimeSlice(sliceUri) } } }
  40. SliceProviderͷ࣮૷ private fun createTimeSlice(uri: Uri): Slice = ListBuilder(context, uri) .apply

    { counter++ setHeader( ListBuilder.HeaderBuilder(this) .setTitle("What's the time now?") ) addRow( ListBuilder.RowBuilder(this) .setTitle("It is ${SimpleDateFormat(“HH:mm") .format(Calendar.getInstance().time)}”) ) addRow( ListBuilder.RowBuilder(this) .setTitle("Slice has called $counter times") ) } .build()
  41. SliceProviderΛAndroidManifestʹఆٛ <?xml version="1.0" encoding="utf-8"?> <manifest> <application ... > <provider android:name=".SampleSliceProvider"

    android:authorities="com.os.operando.slice_provider" android:exported="true" /> </application> </manifest>
  42. SliceProviderΛAndroidManifestʹఆٛ • exported="true"ͯ͠ͳ͍ͱɺSliceManagerͰ bind͢Δ࣌ʹམͪΔͷͰ͚ͭͯΔ • ެ։ͨ͠ΒPermissionͱ͔ؔ܎ͳ͍ͷͰ͸ʁ
 ͬͯؾ࣋ͪ • υΩϡϝϯυ͕·ͩᐆດͳͷͰbug͔΋ʁ

  43. Slice Provide Appͷ࣮૷

  44. ϨΠΞ΢τʹSliceViewΛ௥Ճ • SliceΛදࣔ͢ΔView • https://developer.android.com/reference/ androidx/slice/widget/SliceView.html

  45. ϨΠΞ΢τʹSliceViewΛ௥Ճ <androidx.slice.widget.SliceView android:id="@+id/sliceView" android:layout_width="match_parent" android:layout_height="wrap_content" />

  46. PermissionͷνΣοΫ + ೝՄ • ͜͜͸௕͍ͷͱɺbugͬΆ͍ͷ͕͋ΔͨΊׂѪ • ࠓޙAPIมΘΓͦ͏ͳงғؾ

  47. PermissionͷνΣοΫ + ೝՄ • Slice Provide AppͷSliceProviderʹΞΫηεͰ͖Δ Α͏ʹ͢ΔͨΊʹɺ಺෦࣮૷Ͱ͸ ContextWrapper#grantUriPermissionϝιουΛ ࢖ͬͯɺผύοέʔδͰ΋ΞΫηεͰ͖ΔΑ͏ʹ


    ͯ͠ΔͬΆ͍ʁ
  48. Sliceͷදࣔ • SliceManagerΛ࢖༻ͯ͠UriΛ࢖ͬͯ SliceProviderΛbind͢Δ • SliceProvider͔Βฦ͖ͬͯͨSliceΛ SliceViewʹηοτ͢Δ

  49. Sliceͷදࣔ val slice = sliceManager.bindSlice(sliceUri) sliceView.setSlice(slice)

  50. SliceϢʔεέʔε • ঎඼ݕࡧ݁ՌΛSliceͰฦ͢ • ϝϧΧϦ • Slice Provide Appଆ •

    ػೳΛPlguinͱͯ͠ఏڙ͢ΔΠϝʔδ
  51. SliceϢʔεέʔε • ൃݴͳͲΛτϦΨʔʹSliceΛදࣔ͢Δ • LINEɺGoogle Assistant • ϝοηʔδϯάɺΞγετ • Slice

    Host Appଆ
  52. Android P Slice • Android PͰ͸SliceManagerService͕ଘࡏ͢Δ • ͭ·ΓɺSystem ServiceͷҰछ

  53. SliceͷṖ • SliceProviderΛఏڙ͢ΔΞϓϦͷ೺Ѳ • SliceProvider͕൓Ԡ͢ΔUriͷFormatͷ೺Ѳ • ͲΜͳΞϓϦ͕ͲΜͳSliceΛఏڙͯ͠Δͷ͔
 ஌Δํ๏͕ͳ͍ؾ͕͢Δ

  54. SliceΛ͞Βʹਂ͘஌Δ • Android P Slices: the missing documentation — part

    1 and 2 • https://blog.novoda.com/android-p-slices- missing-documentation-part-1/ • https://blog.novoda.com/android-p-slices- missing-documentation-part-2/
  55. SliceΛ͞Βʹਂ͘஌Δ • Sample App • https://github.com/novoda/spikes/tree/ master/sliceanddice • https://github.com/operando/ Android_Support_Library_Sample

  56. Support Library 28.0.0 Alpha 1·ͱΊ • ண࣮ʹ͍͍API͸૿͑ͯΔ • Android P

    Preview 2͕ग़ͨΒ·ͨΨϥοͱ มΘΓͦ͏ • ਂ͘ௐ΂Δͱ৽͍͠Կ͔͕ݟ͑ͯ͘Δʂ͔΋...
  57. Thanks!!