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