fix(text preference): fix preview block ui broken in SUW

As previous cl ag/25185014 we increased the preview block horizontal padding when landscape mode. However, in setup wizard it uses GlifPreferenceLayout so the settings page only has half screen width when landscape mode, so the preview block ui is squished due to limited width. Also, setup wizard package has overlay the paddings to larger than our prevoius adjust. Therefore, we rollback the changes in accessibility_text_reading_preview.xml to get the default padding, then add checker to increase the paddings if needed at runtime.

Bug: 309590083
Test: manually
Test: atest TextReadingPreviewPreferenceTest
Test: atest TextReadingPreferenceFragmentForSetupWizardTest
Change-Id: Ib907f4182eed272b84a4ab6208ea2d8a89ba96c4
This commit is contained in:
Roy Chou
2023-11-15 07:36:35 +00:00
parent 07f2b54496
commit 004238d7f8
8 changed files with 136 additions and 12 deletions

View File

@@ -28,6 +28,7 @@ import android.content.Context;
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 @@ public class TextReadingPreviewPreferenceTest {
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++) {