diff options
author | Sherry Zhou <yuandizhou@google.com> | 2023-05-31 16:11:26 +0000 |
---|---|---|
committer | Sherry Zhou <yuandizhou@google.com> | 2023-06-01 16:35:43 +0000 |
commit | ee0d7e367c32f3bb1dbcc4552a9754f9b393af66 (patch) | |
tree | 0dc873faaf0d18ffc15fb2edf7ea95c6bf4c23a1 /src/com/android/customization/picker/clock/ui/view | |
parent | f27b52773b0fed7afd203771846088c21aee16a9 (diff) | |
download | ThemePicker-ee0d7e367c32f3bb1dbcc4552a9754f9b393af66.tar.gz |
Fix clock size in carousel is wrong in foldable
The cause of this bug is that when we have splitshade in foldable, we
override screen_preview_width with
screen_preview_width_for_2_pane_small_width for wallpaper preview in
carousel but not for the clock part.
Test: manual
Bug: 283117384
Change-Id: I58cf1fb9ce9ca5d8a25ed520be9e80ba1f9ae94a
Diffstat (limited to 'src/com/android/customization/picker/clock/ui/view')
-rw-r--r-- | src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt index 04ad81fd..c856112e 100644 --- a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt +++ b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt @@ -23,12 +23,14 @@ import android.view.ViewGroup import android.widget.FrameLayout import androidx.constraintlayout.helper.widget.Carousel import androidx.constraintlayout.motion.widget.MotionLayout +import androidx.constraintlayout.widget.ConstraintSet import androidx.core.view.doOnPreDraw import androidx.core.view.get import androidx.core.view.isNotEmpty import com.android.customization.picker.clock.shared.ClockSize import com.android.systemui.plugins.ClockController import com.android.wallpaper.R +import com.android.wallpaper.picker.FixedWidthDisplayRatioFrameLayout import java.lang.Float.max class ClockCarouselView( @@ -70,7 +72,12 @@ class ClockCarouselView( clockSize: ClockSize, clockIds: List<String>, onClockSelected: (clockId: String) -> Unit, + isTwoPaneAndSmallWidth: Boolean, ) { + if (isTwoPaneAndSmallWidth) { + overrideScreenPreviewWidth() + } + adapter = ClockCarouselAdapter(clockSize, clockIds, clockViewFactory, onClockSelected) carousel.setAdapter(adapter) carousel.refresh() @@ -244,6 +251,51 @@ class ClockCarouselView( } } + private fun overrideScreenPreviewWidth() { + val overrideWidth = + context.resources.getDimensionPixelSize( + R.dimen.screen_preview_width_for_2_pane_small_width + ) + itemViewIds.forEach { id -> + val itemView = motionLayout.requireViewById<FrameLayout>(id) + val itemViewLp = itemView.layoutParams + itemViewLp.width = overrideWidth + itemView.layoutParams = itemViewLp + + getClockScaleViewId(id)?.let { + val scaleView = motionLayout.requireViewById<FixedWidthDisplayRatioFrameLayout>(it) + val scaleViewLp = scaleView.layoutParams + scaleViewLp.width = overrideWidth + scaleView.layoutParams = scaleViewLp + } + } + + val previousConstaintSet = motionLayout.getConstraintSet(R.id.previous) + val startConstaintSet = motionLayout.getConstraintSet(R.id.start) + val nextConstaintSet = motionLayout.getConstraintSet(R.id.next) + val constaintSetList = + listOf<ConstraintSet>(previousConstaintSet, startConstaintSet, nextConstaintSet) + constaintSetList.forEach { constraintSet -> + itemViewIds.forEach { id -> + constraintSet.getConstraint(id)?.let { constraint -> + val layout = constraint.layout + if ( + constraint.layout.mWidth == + context.resources.getDimensionPixelSize(R.dimen.screen_preview_width) + ) { + layout.mWidth = overrideWidth + } + if ( + constraint.layout.widthMax == + context.resources.getDimensionPixelSize(R.dimen.screen_preview_width) + ) { + layout.widthMax = overrideWidth + } + } + } + } + } + private class ClockCarouselAdapter( val clockSize: ClockSize, val clockIds: List<String>, @@ -360,6 +412,15 @@ class ClockCarouselView( companion object { const val CLOCK_CAROUSEL_VIEW_SCALE = 0.5f + val itemViewIds = + listOf( + R.id.item_view_0, + R.id.item_view_1, + R.id.item_view_2, + R.id.item_view_3, + R.id.item_view_4 + ) + fun getScalingUpScale(progress: Float) = CLOCK_CAROUSEL_VIEW_SCALE + progress * (1f - CLOCK_CAROUSEL_VIEW_SCALE) |