Fix preview for 2 pane small width (2/n)
For the case of 2 pane and small width, we need to enlarge the preview
width.
Test: manually tested see bug
Bug: 281015900
Change-Id: I13e4e8846708c123e7c3ddd08ebb3a6c0731bc98
diff --git a/res/layout/clock_carousel_view.xml b/res/layout/clock_carousel_view.xml
index f1c959c..9add933 100644
--- a/res/layout/clock_carousel_view.xml
+++ b/res/layout/clock_carousel_view.xml
@@ -17,4 +17,4 @@
<com.android.customization.picker.clock.ui.view.ClockCarouselView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="@dimen/screen_preview_height" />
\ No newline at end of file
+ android:layout_height="match_parent" />
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 9f5d736..4392ebf 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -161,6 +161,7 @@
<dimen name="clock_carousel_guideline_margin">100dp</dimen>
<dimen name="clock_carousel_item_card_width">100dp</dimen>
<dimen name="clock_carousel_item_card_height">108dp</dimen>
+ <dimen name="clock_carousel_guideline_margin_for_2_pane_small_width">83dp</dimen>
<!-- Clock color and size button -->
<dimen name="clock_color_size_button_min_height">32dp</dimen>
diff --git a/src/com/android/customization/module/DefaultCustomizationSections.java b/src/com/android/customization/module/DefaultCustomizationSections.java
index 56d1d56..6a5f2f6 100644
--- a/src/com/android/customization/module/DefaultCustomizationSections.java
+++ b/src/com/android/customization/module/DefaultCustomizationSections.java
@@ -99,7 +99,8 @@
CurrentWallpaperInfoFactory wallpaperInfoFactory,
DisplayUtils displayUtils,
CustomizationPickerViewModel customizationPickerViewModel,
- WallpaperInteractor wallpaperInteractor) {
+ WallpaperInteractor wallpaperInteractor,
+ boolean isTwoPaneAndSmallWidth) {
List<CustomizationSectionController<?>> sectionControllers = new ArrayList<>();
// Wallpaper section.
@@ -116,7 +117,8 @@
mClockViewFactory,
wallpaperPreviewNavigator,
sectionNavigationController,
- wallpaperInteractor)
+ wallpaperInteractor,
+ isTwoPaneAndSmallWidth)
: new ScreenPreviewSectionController(
activity,
lifecycleOwner,
@@ -125,7 +127,8 @@
wallpaperColorsViewModel,
displayUtils,
wallpaperPreviewNavigator,
- wallpaperInteractor));
+ wallpaperInteractor,
+ isTwoPaneAndSmallWidth));
sectionControllers.add(
new ConnectedSectionController(
diff --git a/src/com/android/customization/picker/preview/ui/section/PreviewWithClockCarouselSectionController.kt b/src/com/android/customization/picker/preview/ui/section/PreviewWithClockCarouselSectionController.kt
index 593179d..5941e3d 100644
--- a/src/com/android/customization/picker/preview/ui/section/PreviewWithClockCarouselSectionController.kt
+++ b/src/com/android/customization/picker/preview/ui/section/PreviewWithClockCarouselSectionController.kt
@@ -25,6 +25,8 @@
import android.view.ViewStub
import androidx.activity.ComponentActivity
import androidx.constraintlayout.helper.widget.Carousel
+import androidx.constraintlayout.widget.ConstraintLayout
+import androidx.constraintlayout.widget.Guideline
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.get
@@ -61,6 +63,7 @@
wallpaperPreviewNavigator: WallpaperPreviewNavigator,
private val navigationController: CustomizationSectionNavigationController,
wallpaperInteractor: WallpaperInteractor,
+ private val isTwoPaneAndSmallWidth: Boolean,
) :
ScreenPreviewSectionController(
activity,
@@ -71,6 +74,7 @@
displayUtils,
wallpaperPreviewNavigator,
wallpaperInteractor,
+ isTwoPaneAndSmallWidth,
) {
private val viewModel =
@@ -99,6 +103,23 @@
carouselViewStub.layoutResource = R.layout.clock_carousel_view
val carouselView = carouselViewStub.inflate() as ClockCarouselView
+ if (isTwoPaneAndSmallWidth) {
+ val guidelineMargin =
+ context.resources.getDimensionPixelSize(
+ R.dimen.clock_carousel_guideline_margin_for_2_pane_small_width
+ )
+
+ val guidelineStart = carouselView.requireViewById<Guideline>(R.id.guideline_start)
+ var layoutParams = guidelineStart.layoutParams as ConstraintLayout.LayoutParams
+ layoutParams.guideBegin = guidelineMargin
+ guidelineStart.layoutParams = layoutParams
+
+ val guidelineEnd = carouselView.requireViewById<Guideline>(R.id.guideline_end)
+ layoutParams = guidelineEnd.layoutParams as ConstraintLayout.LayoutParams
+ layoutParams.guideEnd = guidelineMargin
+ guidelineEnd.layoutParams = layoutParams
+ }
+
// TODO (b/270716937) We should handle the single clock case in the clock carousel
// itself
val singleClockViewStub: ViewStub = view.requireViewById(R.id.single_clock_view_stub)