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

star_zero

June 05, 2022
Tweet

More Decks by star_zero

Other Decks in Programming

Transcript

  1. What's new
    in Jetpack

    View Slide

  2. Room, Navigation, and more..
    Architecture

    View Slide

  3. ● KSPサポート
    ● Auto Migrations
    ● Relational Query Methods
    ● Paging 3.0サポート(androidx.room:room-paging)
    ● Kotlinへの書き換え
    Room

    View Slide

  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

    View Slide

  5. @Query(
    "SELECT * FROM user " +
    "JOIN book on user.id = book.user_id"
    )
    fun getUserAndBook(): Map>
    @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>
    Relational Query Methods

    View Slide

  6. ● Rx, GuavaのサポートがStable
    ● LoadResult.Invalidの追加
    ● 新しいEvent Listener
    Paging 3

    View Slide

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

    View Slide

  8. ● Multiple Back Stacksサポート
    ● 2ペインレイアウトサポート (AbstractListDetailFragment)
    ● Kotlinへの書き換え
    Navigation

    View Slide

  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

    View Slide

  10. ● SharedPreferencesの代替
    ● MAD SKills: http://goo.gle/mad-skills-datastore
    DataStore

    View Slide

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

    View Slide

  12. Baseline Profiles, JankStats, and more…
    Performance

    View Slide

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

    View Slide

  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

    View Slide

  15. ● baseline-profile.txt
    ● 初回起動時の最適化
    ● 一部Jetpackライブラリには追加済み
    Baseline Profiles

    View Slide

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

    View Slide

  17. TraceSectionMetric
    benchmarkRule.measureRepeated(
    packageName = TARGET_PACKAGE,
    metrics = listOf(
    FrameTimingMetric(),
    TraceSectionMetric("RV CreateView"),
    TraceSectionMetric("RV OnBindView"),
    ),
    // ...
    }
    trace("RV OnBindView") {
    // ...
    }

    View Slide

  18. ● debuggable falseでパフォーマンスプロファイリング可能
    ● API Level 14
    Tracing

    View Slide

  19. WindowManager, AppCompat, and more…
    User Interface

    View Slide

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

    View Slide

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

    View Slide

  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
    }
    }
    }

    View Slide

  23. ● DropHelper
    DragAndDrop

    View Slide

  24. DragAndDrop
    val options = DropHelper.Options.Builder()
    .setHighlightColor(highlightColor)
    .setHighlightCornerRadiusPx(cornerRadiusPx)
    .build()
    DropHelper.configureView(
    activity,
    targetView,
    arrayOf(ClipDescription.MIMETYPE_TEXT_PLAIN),
    options,
    ) { view, payload ->
    // ...
    }

    View Slide

  25. ● Emoji2サポート
    ● アプリごとの言語設定
    AppCompat

    View Slide

  26. val appLocale = LocaleListCompat.forLanguageTags("ja")
    AppCompatDelegate.setApplicationLocales(appLocale)
    android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
    android:enabled="false"
    android:exported="false">
    android:name="autoStoreLocales"
    android:value="true" />

    アプリ言語設定

    View Slide

  27. ● 1.2 Beta
    ● Nested Scrollとの相互互換
    ● Downloadable Fonts
    ● Lazy Layout
    ● and more…
    Jetpack Compose

    View Slide

  28. Thank you!
    Android, Kotlin GDE
    he / him
    @STAR_ZERO
    https://www.youtube.com/watch
    ?v=jTd82lcuHTU
    Resources
    Kenji Abe

    View Slide