Loading TEST_MAPPING +8 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,14 @@ "exclude-annotation": "org.junit.Ignore" } ] }, { "name": "WallpaperPickerGoogleTests", "options": [ { "exclude-annotation": "org.junit.Ignore" } ] } ] } res/layout/fragment_clock_settings.xml +3 −2 Original line number Diff line number Diff line Loading @@ -62,9 +62,10 @@ android:clipChildren="false"> <FrameLayout android:layout_width="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="22dp"> android:layout_marginBottom="22dp" android:layout_gravity="center_horizontal"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/tabs" Loading res/layout/picker_fragment_tab.xml +1 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ <TextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" Loading @@ -28,7 +27,5 @@ android:minHeight="36dp" android:gravity="center" android:background="@drawable/picker_fragment_tab_background" android:text="Placeholder for stable size calculation, please do not remove." android:maxLines="1" android:ellipsize="end" tools:ignore="HardcodedText" /> android:ellipsize="end" /> src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt +42 −13 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.customization.picker.color.ui.binder import android.content.res.Configuration import android.os.Bundle import android.os.Parcelable import android.view.View import android.widget.TextView import androidx.lifecycle.Lifecycle Loading Loading @@ -48,7 +50,7 @@ object ColorPickerBinder { view: View, viewModel: ColorPickerViewModel, lifecycleOwner: LifecycleOwner, ) { ): Binding { val colorTypeTabView: RecyclerView = view.requireViewById(R.id.color_type_tabs) val colorTypeTabSubheaderView: TextView = view.requireViewById(R.id.color_type_tab_subhead) val colorOptionContainerView: RecyclerView = view.requireViewById(R.id.color_options) Loading Loading @@ -94,17 +96,23 @@ object ColorPickerBinder { colorOptionAdapter.setItems(colorOptions) // the same recycler view is used for different color types tabs // the scroll state of each tab should be independent of others var indexToFocus = 0 colorOptions.forEachIndexed { index, colorOption -> if (colorOption.isSelected.value) { indexToFocus = index } if (layoutManagerSavedState != null) { colorOptionContainerView.post { (colorOptionContainerView.layoutManager as LinearLayoutManager) .onRestoreInstanceState(layoutManagerSavedState) layoutManagerSavedState = null } } else { var indexToFocus = colorOptions.indexOfFirst { it.isSelected.value } indexToFocus = if (indexToFocus < 0) 0 else indexToFocus val linearLayoutManager = object : LinearLayoutManager(view.context, HORIZONTAL, false) { override fun onLayoutCompleted(state: RecyclerView.State?) { super.onLayoutCompleted(state) scrollToPosition(indexToFocus) // scrollToPosition seems to be inconsistently moving // selected // color to different positions scrollToPositionWithOffset(indexToFocus, 0) } } colorOptionContainerView.layoutManager = linearLayoutManager Loading @@ -113,4 +121,25 @@ object ColorPickerBinder { } } } return object : Binding { override fun saveInstanceState(savedState: Bundle) { savedState.putParcelable( LAYOUT_MANAGER_SAVED_STATE, colorOptionContainerView.layoutManager?.onSaveInstanceState() ) } override fun restoreInstanceState(savedState: Bundle) { layoutManagerSavedState = savedState.getParcelable(LAYOUT_MANAGER_SAVED_STATE) } } } interface Binding { fun saveInstanceState(savedState: Bundle) fun restoreInstanceState(savedState: Bundle) } private val LAYOUT_MANAGER_SAVED_STATE: String = "layout_manager_state" private var layoutManagerSavedState: Parcelable? = null } src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt +25 −13 Original line number Diff line number Diff line Loading @@ -39,6 +39,8 @@ import kotlinx.coroutines.suspendCancellableCoroutine @OptIn(ExperimentalCoroutinesApi::class) class ColorPickerFragment : AppbarFragment() { private var binding: ColorPickerBinder.Binding? = null companion object { @JvmStatic fun newInstance(): ColorPickerFragment { Loading @@ -64,6 +66,8 @@ class ColorPickerFragment : AppbarFragment() { val wallpaperInfoFactory = injector.getCurrentWallpaperInfoFactory(requireContext()) val displayUtils: DisplayUtils = injector.getDisplayUtils(requireContext()) val wcViewModel = injector.getWallpaperColorsViewModel() binding = ColorPickerBinder.bind( view = view, viewModel = Loading @@ -77,6 +81,9 @@ class ColorPickerFragment : AppbarFragment() { .get(), lifecycleOwner = this, ) savedInstanceState?.let { binding?.restoreInstanceState(it) } ScreenPreviewBinder.bind( activity = requireActivity(), previewView = lockScreenView, Loading Loading @@ -161,6 +168,11 @@ class ColorPickerFragment : AppbarFragment() { return view } override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) binding?.saveInstanceState(savedInstanceState) } override fun getDefaultTitle(): CharSequence { return requireContext().getString(R.string.color_picker_title) } Loading Loading
TEST_MAPPING +8 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,14 @@ "exclude-annotation": "org.junit.Ignore" } ] }, { "name": "WallpaperPickerGoogleTests", "options": [ { "exclude-annotation": "org.junit.Ignore" } ] } ] }
res/layout/fragment_clock_settings.xml +3 −2 Original line number Diff line number Diff line Loading @@ -62,9 +62,10 @@ android:clipChildren="false"> <FrameLayout android:layout_width="wrap_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="22dp"> android:layout_marginBottom="22dp" android:layout_gravity="center_horizontal"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/tabs" Loading
res/layout/picker_fragment_tab.xml +1 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ <TextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" Loading @@ -28,7 +27,5 @@ android:minHeight="36dp" android:gravity="center" android:background="@drawable/picker_fragment_tab_background" android:text="Placeholder for stable size calculation, please do not remove." android:maxLines="1" android:ellipsize="end" tools:ignore="HardcodedText" /> android:ellipsize="end" />
src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt +42 −13 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.customization.picker.color.ui.binder import android.content.res.Configuration import android.os.Bundle import android.os.Parcelable import android.view.View import android.widget.TextView import androidx.lifecycle.Lifecycle Loading Loading @@ -48,7 +50,7 @@ object ColorPickerBinder { view: View, viewModel: ColorPickerViewModel, lifecycleOwner: LifecycleOwner, ) { ): Binding { val colorTypeTabView: RecyclerView = view.requireViewById(R.id.color_type_tabs) val colorTypeTabSubheaderView: TextView = view.requireViewById(R.id.color_type_tab_subhead) val colorOptionContainerView: RecyclerView = view.requireViewById(R.id.color_options) Loading Loading @@ -94,17 +96,23 @@ object ColorPickerBinder { colorOptionAdapter.setItems(colorOptions) // the same recycler view is used for different color types tabs // the scroll state of each tab should be independent of others var indexToFocus = 0 colorOptions.forEachIndexed { index, colorOption -> if (colorOption.isSelected.value) { indexToFocus = index } if (layoutManagerSavedState != null) { colorOptionContainerView.post { (colorOptionContainerView.layoutManager as LinearLayoutManager) .onRestoreInstanceState(layoutManagerSavedState) layoutManagerSavedState = null } } else { var indexToFocus = colorOptions.indexOfFirst { it.isSelected.value } indexToFocus = if (indexToFocus < 0) 0 else indexToFocus val linearLayoutManager = object : LinearLayoutManager(view.context, HORIZONTAL, false) { override fun onLayoutCompleted(state: RecyclerView.State?) { super.onLayoutCompleted(state) scrollToPosition(indexToFocus) // scrollToPosition seems to be inconsistently moving // selected // color to different positions scrollToPositionWithOffset(indexToFocus, 0) } } colorOptionContainerView.layoutManager = linearLayoutManager Loading @@ -113,4 +121,25 @@ object ColorPickerBinder { } } } return object : Binding { override fun saveInstanceState(savedState: Bundle) { savedState.putParcelable( LAYOUT_MANAGER_SAVED_STATE, colorOptionContainerView.layoutManager?.onSaveInstanceState() ) } override fun restoreInstanceState(savedState: Bundle) { layoutManagerSavedState = savedState.getParcelable(LAYOUT_MANAGER_SAVED_STATE) } } } interface Binding { fun saveInstanceState(savedState: Bundle) fun restoreInstanceState(savedState: Bundle) } private val LAYOUT_MANAGER_SAVED_STATE: String = "layout_manager_state" private var layoutManagerSavedState: Parcelable? = null }
src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt +25 −13 Original line number Diff line number Diff line Loading @@ -39,6 +39,8 @@ import kotlinx.coroutines.suspendCancellableCoroutine @OptIn(ExperimentalCoroutinesApi::class) class ColorPickerFragment : AppbarFragment() { private var binding: ColorPickerBinder.Binding? = null companion object { @JvmStatic fun newInstance(): ColorPickerFragment { Loading @@ -64,6 +66,8 @@ class ColorPickerFragment : AppbarFragment() { val wallpaperInfoFactory = injector.getCurrentWallpaperInfoFactory(requireContext()) val displayUtils: DisplayUtils = injector.getDisplayUtils(requireContext()) val wcViewModel = injector.getWallpaperColorsViewModel() binding = ColorPickerBinder.bind( view = view, viewModel = Loading @@ -77,6 +81,9 @@ class ColorPickerFragment : AppbarFragment() { .get(), lifecycleOwner = this, ) savedInstanceState?.let { binding?.restoreInstanceState(it) } ScreenPreviewBinder.bind( activity = requireActivity(), previewView = lockScreenView, Loading Loading @@ -161,6 +168,11 @@ class ColorPickerFragment : AppbarFragment() { return view } override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) binding?.saveInstanceState(savedInstanceState) } override fun getDefaultTitle(): CharSequence { return requireContext().getString(R.string.color_picker_title) } Loading