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

What's new in Jetpack / I/O Extended Japan 2022

What's new in Jetpack / I/O Extended Japan 2022

80a3a3857a55f154d23acb705eff72cc?s=128

star_zero

June 05, 2022
Tweet

More Decks by star_zero

Other Decks in Programming

Transcript

  1. What's new in Jetpack

  2. Room, Navigation, and more.. Architecture

  3. • KSPサポート • Auto Migrations • Relational Query Methods •

    Paging 3.0サポート(androidx.room:room-paging) • Kotlinへの書き換え Room
  4. @Database( entities = [ /* .. */ ], version =

    3, autoMigrations = [ AutoMigration(from = 1, to = 2), AutoMigration( from = 2, to = 3, spec = AppDatabase.AutoMigration2to3::class ) ] ) abstract class AppDatabase : RoomDatabase() { @RenameTable(fromTableName = "user", toTableName = "users") class AutoMigration2to3 : AutoMigrationSpec } Auto Migrations
  5. @Query( "SELECT * FROM user " + "JOIN book on

    user.id = book.user_id" ) fun getUserAndBook(): Map<User, List<Book>> @MapInfo(keyColumn = "userName", valueColumn = "bookName") @Query( "SELECT user.name AS userName, book.name AS bookName FROM user " + "JOIN book on user.id = book.user_id" ) fun getUserAndBookNames(): Map<String, List<String>> Relational Query Methods
  6. • Rx, GuavaのサポートがStable • LoadResult.Invalidの追加 • 新しいEvent Listener Paging 3

  7. adapter.addOnPagesUpdatedListener { // ... } lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { adapter.onPagesUpdatedFlow.collect

    { // ... } } } Event Listener
  8. • Multiple Back Stacksサポート • 2ペインレイアウトサポート (AbstractListDetailFragment) • Kotlinへの書き換え Navigation

  9. class ListDetailFragment: AbstractListDetailFragment() { override fun onCreateListPaneView(/* */): View {

    return inflater.inflate(R.layout.list_pane, container, false) } override fun onListPaneViewCreated(/* */) { super.onListPaneViewCreated(view, savedInstanceState) val recyclerView = view as RecyclerView recyclerView.adapter = ListDetailAdapter(/* */) } override fun onCreateDetailPaneNavHostFragment(): NavHostFragment { return NavHostFragment.create(R.navigation.list_detail_nav_graph) } } AbstractListDetailFragment
  10. • SharedPreferencesの代替 • MAD SKills: http://goo.gle/mad-skills-datastore DataStore

  11. • Jetpackライブラリを使った設計ガイド • MAD SKills: http://goo.gle/mad-skills-architecture Architecture

  12. Baseline Profiles, JankStats, and more… Performance

  13. • Jankの追跡 • ユーザーの状態把握 • 毎Frameで結果をレポート JankStats

  14. val metricsStateHolder = PerformanceMetricsState.getForHierarchy(view) val jankStats = JankStats.createAndTrack( window =

    window, executor = Dispatchers.Default.asExecutor(), frameListener = { frameData -> if (frameData.isJank) { // ... } } ) metricsStateHolder.state?.addState("Activity", javaClass.simpleName) JankStats
  15. • baseline-profile.txt • 初回起動時の最適化 • 一部Jetpackライブラリには追加済み Baseline Profiles

  16. • 起動やスクロールのパフォーマンス計測 • TraceSectionMetric / AudioUnderrunMetric • Baseline Profilesの生成 Macrobenchmark

  17. TraceSectionMetric benchmarkRule.measureRepeated( packageName = TARGET_PACKAGE, metrics = listOf( FrameTimingMetric(), TraceSectionMetric("RV

    CreateView"), TraceSectionMetric("RV OnBindView"), ), // ... } trace("RV OnBindView") { // ... }
  18. • debuggable falseでパフォーマンスプロファイリング可能 • API Level 14 Tracing

  19. WindowManager, AppCompat, and more… User Interface

  20. • WindowMetrics • Foldable • SlidingPaneLayoutの改善 WindowManager

  21. WindowMetrics val currentWindowMetrics = WindowMetricsCalculator.getOrCreate() .computeCurrentWindowMetrics(this) val maximumWindowMetrics = WindowMetricsCalculator.getOrCreate()

    .computeMaximumWindowMetrics(this)
  22. Foldable lifecycleScope.launch { lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { WindowInfoTracker.getOrCreate(activity) .windowLayoutInfo(activity) .collect { layoutInfo

    -> val foldingFeature = layoutInfo.displayFeatures.firstOrNull() as? FoldingFeature foldingFeature?.state // => FLAT, HALF_OPENED foldingFeature?.orientation // => VERTICAL, HORIZONTAL foldingFeature?.bounds // > Rect } } }
  23. • DropHelper DragAndDrop

  24. DragAndDrop val options = DropHelper.Options.Builder() .setHighlightColor(highlightColor) .setHighlightCornerRadiusPx(cornerRadiusPx) .build() DropHelper.configureView( activity,

    targetView, arrayOf(ClipDescription.MIMETYPE_TEXT_PLAIN), options, ) { view, payload -> // ... }
  25. • Emoji2サポート • アプリごとの言語設定 AppCompat

  26. val appLocale = LocaleListCompat.forLanguageTags("ja") AppCompatDelegate.setApplicationLocales(appLocale) <service android:name="androidx.appcompat.app.AppLocalesMetadataHolderService" android:enabled="false" android:exported="false"> <meta-data

    android:name="autoStoreLocales" android:value="true" /> </service> アプリ言語設定
  27. • 1.2 Beta • Nested Scrollとの相互互換 • Downloadable Fonts •

    Lazy Layout • and more… Jetpack Compose
  28. Thank you! Android, Kotlin GDE he / him @STAR_ZERO https://www.youtube.com/watch

    ?v=jTd82lcuHTU Resources Kenji Abe