Slide 1

Slide 1 text

What's new in Jetpack

Slide 2

Slide 2 text

Room, Navigation, and more.. Architecture

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

@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

Slide 5

Slide 5 text

@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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Baseline Profiles, JankStats, and more… Performance

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

WindowManager, AppCompat, and more… User Interface

Slide 20

Slide 20 text

● WindowMetrics ● Foldable ● SlidingPaneLayoutの改善 WindowManager

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

● DropHelper DragAndDrop

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

val appLocale = LocaleListCompat.forLanguageTags("ja") AppCompatDelegate.setApplicationLocales(appLocale) アプリ言語設定

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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