Merge "fix(text preference): fix preview block ui broken in SUW" into main
diff --git a/res/layout/accessibility_text_reading_preview.xml b/res/layout/accessibility_text_reading_preview.xml
index f76bb1c..95ea2e4 100644
--- a/res/layout/accessibility_text_reading_preview.xml
+++ b/res/layout/accessibility_text_reading_preview.xml
@@ -19,17 +19,17 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="@dimen/settingslib_illustration_padding"
- android:paddingEnd="@dimen/text_reading_preview_padding_end"
- android:paddingStart="@dimen/text_reading_preview_padding_start">
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart">
<LinearLayout
+ android:id="@+id/preview_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/accessibility_text_reading_preview"
android:clipChildren="true"
android:orientation="vertical"
- android:paddingVertical="@dimen/text_reading_preview_background_padding_vertical"
- android:paddingHorizontal="@dimen/text_reading_preview_background_padding_horizontal">
+ android:padding="18dp">
<TextView
android:id="@+id/preview_label"
diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml
index d829637..647ba6c 100644
--- a/res/values-land/dimens.xml
+++ b/res/values-land/dimens.xml
@@ -22,7 +22,9 @@
<dimen name="notif_channel_panel_max_height">300dp</dimen>
<!-- Text Reading Settings -->
- <dimen name="text_reading_preview_padding_start">64dp</dimen>
- <dimen name="text_reading_preview_padding_end">64dp</dimen>
- <dimen name="text_reading_preview_background_padding_horizontal">72dp</dimen>
+ <dimen name="text_reading_preview_layout_padding_horizontal_min">64dp</dimen>
+ <dimen name="text_reading_preview_background_padding_horizontal_min">72dp</dimen>
+
+ <dimen name="text_reading_preview_layout_padding_horizontal_min_suw">24dp</dimen>
+ <dimen name="text_reading_preview_background_padding_horizontal_min_suw">24dp</dimen>
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index fc202a5..6c03955 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -223,10 +223,14 @@
<dimen name="message_icon_inset">11dp</dimen>
<!-- Text Reading Settings -->
- <dimen name="text_reading_preview_padding_start">@*android:dimen/list_item_padding_end_material</dimen>
- <dimen name="text_reading_preview_padding_end">@*android:dimen/list_item_padding_end_material</dimen>
- <dimen name="text_reading_preview_background_padding_vertical">18dp</dimen>
- <dimen name="text_reading_preview_background_padding_horizontal">18dp</dimen>
+ <dimen name="text_reading_preview_layout_padding_horizontal_min">
+ @*android:dimen/list_item_padding_start_material</dimen>
+ <dimen name="text_reading_preview_background_padding_horizontal_min">18dp</dimen>
+
+ <dimen name="text_reading_preview_layout_padding_horizontal_min_suw">
+ @dimen/text_reading_preview_layout_padding_horizontal_min</dimen>
+ <dimen name="text_reading_preview_background_padding_horizontal_min_suw">
+ @dimen/text_reading_preview_background_padding_horizontal_min</dimen>
<!-- Accessibility Settings -->
<dimen name="accessibility_layout_margin_start_end">16dp</dimen>
diff --git a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
index 450aeca..a90af21 100644
--- a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java
@@ -62,7 +62,7 @@
static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
static final String HIGH_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
static final String RESET_KEY = "reset";
- private static final String PREVIEW_KEY = "preview";
+ static final String PREVIEW_KEY = "preview";
private static final String NEED_RESET_SETTINGS = "need_reset_settings";
private static final String LAST_PREVIEW_INDEX = "last_preview_index";
private static final int UNKNOWN_INDEX = -1;
diff --git a/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizard.java
index 783696d..11be73c 100644
--- a/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizard.java
+++ b/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizard.java
@@ -29,6 +29,7 @@
import androidx.recyclerview.widget.RecyclerView;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settingslib.Utils;
@@ -42,6 +43,24 @@
public class TextReadingPreferenceFragmentForSetupWizard extends TextReadingPreferenceFragment {
@Override
+ public void addPreferencesFromResource(int preferencesResId) {
+ super.addPreferencesFromResource(preferencesResId);
+
+ adjustPreviewPaddingsForSetupWizard();
+ }
+
+ @VisibleForTesting
+ void adjustPreviewPaddingsForSetupWizard() {
+ TextReadingPreviewPreference textReadingPreviewPreference = findPreference(PREVIEW_KEY);
+ textReadingPreviewPreference.setLayoutMinHorizontalPadding(
+ getContext().getResources().getDimensionPixelSize(
+ R.dimen.text_reading_preview_layout_padding_horizontal_min_suw));
+ textReadingPreviewPreference.setBackgroundMinHorizontalPadding(
+ getContext().getResources().getDimensionPixelSize(
+ R.dimen.text_reading_preview_background_padding_horizontal_min_suw));
+ }
+
+ @Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
diff --git a/src/com/android/settings/accessibility/TextReadingPreviewPreference.java b/src/com/android/settings/accessibility/TextReadingPreviewPreference.java
index c4a9489..a9e2dce 100644
--- a/src/com/android/settings/accessibility/TextReadingPreviewPreference.java
+++ b/src/com/android/settings/accessibility/TextReadingPreviewPreference.java
@@ -19,11 +19,14 @@
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import androidx.viewpager.widget.ViewPager;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
import com.android.settings.R;
import com.android.settings.display.PreviewPagerAdapter;
@@ -37,6 +40,9 @@
private int mLastLayerIndex;
private PreviewPagerAdapter mPreviewAdapter;
+ private int mLayoutMinHorizontalPadding = 0;
+ private int mBackgroundMinHorizontalPadding = 0;
+
private final ViewPager.OnPageChangeListener mPageChangeListener =
new ViewPager.OnPageChangeListener() {
@Override
@@ -80,6 +86,10 @@
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
+ FrameLayout previewLayout = (FrameLayout) holder.itemView;
+ LinearLayout backgroundView = previewLayout.findViewById(R.id.preview_background);
+ adjustPaddings(previewLayout, backgroundView);
+
final ViewPager viewPager = (ViewPager) holder.findViewById(R.id.preview_pager);
viewPager.addOnPageChangeListener(mPageChangeListener);
final DotsPageIndicator pageIndicator =
@@ -88,6 +98,36 @@
updatePagerAndIndicator(viewPager, pageIndicator);
}
+ /**
+ * Set the minimum preview layout horizontal inner padding.
+ */
+ void setLayoutMinHorizontalPadding(int layoutMinHorizontalPadding) {
+ mLayoutMinHorizontalPadding = layoutMinHorizontalPadding;
+ }
+
+ /**
+ * Set the minimum preview background view horizontal inner padding.
+ */
+ void setBackgroundMinHorizontalPadding(int backgroundMinHorizontalPadding) {
+ mBackgroundMinHorizontalPadding = backgroundMinHorizontalPadding;
+ }
+
+ @VisibleForTesting
+ void adjustPaddings(FrameLayout previewLayout, LinearLayout backgroundView) {
+ previewLayout.setPadding(
+ Math.max(previewLayout.getPaddingStart(), mLayoutMinHorizontalPadding),
+ previewLayout.getPaddingTop(),
+ Math.max(previewLayout.getPaddingEnd(), mLayoutMinHorizontalPadding),
+ previewLayout.getPaddingBottom()
+ );
+ backgroundView.setPadding(
+ Math.max(backgroundView.getPaddingStart(), mBackgroundMinHorizontalPadding),
+ backgroundView.getPaddingTop(),
+ Math.max(backgroundView.getPaddingEnd(), mBackgroundMinHorizontalPadding),
+ backgroundView.getPaddingBottom()
+ );
+ }
+
void setPreviewAdapter(PreviewPagerAdapter previewAdapter) {
if (previewAdapter != mPreviewAdapter) {
mPreviewAdapter = previewAdapter;
@@ -142,6 +182,12 @@
}
private void init() {
+ // set up the minimum horizontal paddings
+ setLayoutMinHorizontalPadding(getContext().getResources().getDimensionPixelSize(
+ R.dimen.text_reading_preview_layout_padding_horizontal_min));
+ setBackgroundMinHorizontalPadding(getContext().getResources().getDimensionPixelSize(
+ R.dimen.text_reading_preview_background_padding_horizontal_min));
+
setLayoutResource(R.layout.accessibility_text_reading_preview);
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizardTest.java b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizardTest.java
index 4ee2a2d..41502b3 100644
--- a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizardTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreferenceFragmentForSetupWizardTest.java
@@ -16,11 +16,13 @@
package com.android.settings.accessibility;
+import static com.android.settings.accessibility.TextReadingPreferenceFragment.PREVIEW_KEY;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.RESET_KEY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -65,6 +67,9 @@
@Mock
private FragmentActivity mActivity;
+ @Mock
+ private TextReadingPreviewPreference mPreviewPreference;
+
@Spy
private final Context mContext = ApplicationProvider.getApplicationContext();
private TextReadingPreferenceFragmentForSetupWizard mFragment;
@@ -77,6 +82,7 @@
doReturn(mContext).when(mFragment).getContext();
doReturn(mock(LifecycleOwner.class)).when(mFragment).getViewLifecycleOwner();
doReturn(resetPreference).when(mFragment).findPreference(RESET_KEY);
+ doReturn(mPreviewPreference).when(mFragment).findPreference(PREVIEW_KEY);
doReturn(mFooterBarMixin).when(mGlifLayoutView).getMixin(FooterBarMixin.class);
}
@@ -109,4 +115,12 @@
verify(mFooterBarMixin).setPrimaryButton(any());
verify(mFooterBarMixin).setSecondaryButton(any());
}
+
+ @Test
+ public void adjustPreviewPaddingsForSetupWizard_setPreviewLayoutPaddings() {
+ mFragment.adjustPreviewPaddingsForSetupWizard();
+
+ verify(mPreviewPreference).setLayoutMinHorizontalPadding(anyInt());
+ verify(mPreviewPreference).setBackgroundMinHorizontalPadding(anyInt());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java
index 0162d26..4ca1dca 100644
--- a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java
@@ -28,6 +28,7 @@
import android.content.res.Configuration;
import android.view.LayoutInflater;
import android.view.View;
+import android.widget.FrameLayout;
import android.widget.LinearLayout;
import androidx.preference.PreferenceViewHolder;
@@ -146,6 +147,44 @@
assertThat(mTextReadingPreviewPreference.getCurrentItem()).isEqualTo(currentItem);
}
+ @Test
+ public void adjustPaddings_setMinPaddingsLessThanXMLValue_paddingsNotIncreased() {
+ // get the default xml padding value
+ mTextReadingPreviewPreference.onBindViewHolder(mHolder);
+ final FrameLayout previewLayout = (FrameLayout) mHolder.itemView;
+ final LinearLayout backgroundView = previewLayout.findViewById(R.id.preview_background);
+
+ final int currentLayoutPaddingStart = previewLayout.getPaddingStart();
+ final int currentBackgroundPaddingStart = backgroundView.getPaddingStart();
+ mTextReadingPreviewPreference.setLayoutMinHorizontalPadding(
+ currentLayoutPaddingStart - 10);
+ mTextReadingPreviewPreference.setBackgroundMinHorizontalPadding(
+ currentBackgroundPaddingStart - 10);
+ mTextReadingPreviewPreference.adjustPaddings(previewLayout, backgroundView);
+
+ assertThat(previewLayout.getPaddingStart()).isEqualTo(currentLayoutPaddingStart);
+ assertThat(backgroundView.getPaddingStart()).isEqualTo(currentBackgroundPaddingStart);
+ }
+
+ @Test
+ public void adjustPaddings_setMinPaddingsLargerThanXMLValue_paddingsIncreased() {
+ // get the default xml padding value
+ mTextReadingPreviewPreference.onBindViewHolder(mHolder);
+ final FrameLayout previewLayout = (FrameLayout) mHolder.itemView;
+ final LinearLayout backgroundView = previewLayout.findViewById(R.id.preview_background);
+
+ final int currentLayoutPaddingStart = previewLayout.getPaddingStart();
+ final int currentBackgroundPaddingStart = backgroundView.getPaddingStart();
+ mTextReadingPreviewPreference.setLayoutMinHorizontalPadding(
+ currentLayoutPaddingStart + 10);
+ mTextReadingPreviewPreference.setBackgroundMinHorizontalPadding(
+ currentBackgroundPaddingStart + 10);
+ mTextReadingPreviewPreference.adjustPaddings(previewLayout, backgroundView);
+
+ assertThat(previewLayout.getPaddingStart()).isEqualTo(currentLayoutPaddingStart + 10);
+ assertThat(backgroundView.getPaddingStart()).isEqualTo(currentBackgroundPaddingStart + 10);
+ }
+
private static Configuration[] createConfigurations(int count) {
final Configuration[] configurations = new Configuration[count];
for (int i = 0; i < count; i++) {