Move the content description for Display size and text preview to xml

Bug: 395882764
Test: atest TextReadingPreviewControllerTest
Test: atest TextReadingPreviewPreferenceTest
Flag: EXEMPT BUGFIX
Change-Id: I070ec2b9b39a205fd3a97636f0c45fb50b670049
This commit is contained in:
Candice
2025-03-14 16:13:24 +00:00
parent b4a1d57206
commit 526dacdc82
9 changed files with 44 additions and 104 deletions

View File

@@ -46,7 +46,6 @@
android:id="@+id/preview_pager"
android:layout_width="wrap_content"
android:layout_height="217dp"
android:contentDescription="@string/preview_pager_content_description"
android:nestedScrollingEnabled="true" />
<LinearLayout
android:layout_width="match_parent"

View File

@@ -14,14 +14,19 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<com.android.settings.display.AppGridView
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:gravity="center"
android:nestedScrollingEnabled="true"
android:importantForAccessibility="noHideDescendants"
app:appCount="6"/>
android:contentDescription="@string/preview_pager_home_content_description" >
<com.android.settings.display.AppGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:gravity="center"
android:nestedScrollingEnabled="true"
android:importantForAccessibility="noHideDescendants"
app:appCount="6"/>
</FrameLayout>

View File

@@ -14,18 +14,18 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:importantForAccessibility="noHideDescendants">
android:contentDescription="@string/preview_pager_email_content_description">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:importantForAccessibility="noHideDescendants">
<TextView
android:id="@+id/subject"

View File

@@ -19,12 +19,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:importantForAccessibility="noHideDescendants">
android:contentDescription="@string/preview_pager_message_content_description">
<view class="com.android.settings.TouchBlockingFrameLayout"
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:importantForAccessibility="noHideDescendants">
<LinearLayout
android:layout_width="match_parent"

View File

@@ -810,23 +810,13 @@
<!-- Allowed packages to show the confirmation dialog for a system locale suggestion -->
<string-array name="allowed_packages_for_locale_confirmation_diallog" translatable="false"/>
<!-- Array of text reading preview layouts. Must contain at least 1 layout.
Add content descriptions in the config_text_reading_preview_content_descriptions together
if adding more sample layouts here -->
<!-- Array of text reading preview layouts. Must contain at least 1 layout -->
<array name="config_text_reading_preview_samples">
<item>@layout/accessibility_text_reading_preview_app_grid</item>
<item>@layout/screen_zoom_preview_1</item>
<item>@layout/accessibility_text_reading_preview_mail_content</item>
</array>
<!-- Array of text reading preview layouts' content descriptions.
The order should be the same as the layouts in config_text_reading_preview_samples -->
<array name="config_text_reading_preview_content_descriptions">
<item>@string/preview_pager_home_content_description</item>
<item>@string/preview_pager_message_content_description</item>
<item>@string/preview_pager_email_content_description</item>
</array>
<!-- Package responsible for updating Mainline Modules -->
<string name="config_mainline_module_update_package" translatable="false">com.android.vending</string>

View File

@@ -104,13 +104,11 @@ class TextReadingPreviewController extends BasePreferenceController implements
final boolean isLayoutRtl =
origConfig.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
final int[] previewSamples = getPreviewSampleLayouts(mContext);
final int[] previewContentDescriptions = getPreviewSampleContentDescriptions(mContext);
final PreviewPagerAdapter pagerAdapter = new PreviewPagerAdapter(mContext, isLayoutRtl,
previewSamples, createConfig(origConfig));
mPreviewPreference.setPreviewAdapter(pagerAdapter);
mPreviewPreference.setCurrentItem(
isLayoutRtl ? previewSamples.length - 1 : FRAME_INITIAL_INDEX);
mPreviewPreference.setContentDescription(previewContentDescriptions);
final int initialPagerIndex =
mLastFontProgress * mDisplaySizeData.getValues().size() + mLastDisplayProgress;
@@ -190,20 +188,6 @@ class TextReadingPreviewController extends BasePreferenceController implements
return previewSamples;
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
static int[] getPreviewSampleContentDescriptions(Context context) {
TypedArray typedArray = context.getResources().obtainTypedArray(
R.array.config_text_reading_preview_content_descriptions);
int previewCount = typedArray.length();
int[] previewContentDescriptions = new int[previewCount];
for (int i = 0; i < previewCount; i++) {
previewContentDescriptions[i] =
typedArray.getResourceId(i, R.string.preview_pager_content_description);
}
typedArray.recycle();
return previewContentDescriptions;
}
private int getPagerIndex() {
final int displayDataSize = mDisplaySizeData.getValues().size();
final int fontSizeProgress = mFontSizePreference.getProgress();

View File

@@ -43,10 +43,26 @@ public class TextReadingPreviewPreference extends Preference {
private int mCurrentItem;
private int mLastLayerIndex;
private PreviewPagerAdapter mPreviewAdapter;
private int[] mContentDescriptions;
private int mLayoutMinHorizontalPadding = 0;
private int mBackgroundMinHorizontalPadding = 0;
private final ViewPager.OnPageChangeListener mPageChangeListener =
new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
// Do nothing
}
@Override
public void onPageSelected(int i) {
mCurrentItem = i;
}
@Override
public void onPageScrollStateChanged(int i) {
// Do nothing
}
};
TextReadingPreviewPreference(Context context) {
super(context);
@@ -78,23 +94,7 @@ public class TextReadingPreviewPreference extends Preference {
adjustPaddings(previewLayout, backgroundView);
final ViewPager viewPager = (ViewPager) holder.findViewById(R.id.preview_pager);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
// Do nothing
}
@Override
public void onPageSelected(int i) {
mCurrentItem = i;
viewPager.setContentDescription(getContext().getString(mContentDescriptions[i]));
}
@Override
public void onPageScrollStateChanged(int i) {
// Do nothing
}
});
viewPager.addOnPageChangeListener(mPageChangeListener);
final DotsPageIndicator pageIndicator =
(DotsPageIndicator) holder.findViewById(R.id.page_indicator);
updateAdapterIfNeeded(viewPager, pageIndicator, mPreviewAdapter);
@@ -121,10 +121,6 @@ public class TextReadingPreviewPreference extends Preference {
viewPager.setCurrentItem(getCurrentItem() + 1));
nextButton.setContentDescription(getContext().getString(
R.string.preview_pager_next_button));
// Initialize the content description since the OnPageChangeListener#onPageSelected won't
// be called during setup.
viewPager.setContentDescription(getContext().getString(mContentDescriptions[0]));
}
@Override
@@ -173,10 +169,6 @@ public class TextReadingPreviewPreference extends Preference {
);
}
void setContentDescription(int[] stringIds) {
mContentDescriptions = stringIds;
}
void setPreviewAdapter(PreviewPagerAdapter previewAdapter) {
if (previewAdapter != mPreviewAdapter) {
mPreviewAdapter = previewAdapter;

View File

@@ -16,8 +16,6 @@
package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -78,15 +76,6 @@ public class TextReadingPreviewControllerTest {
mDisplaySizePreference = new AccessibilitySeekBarPreference(mContext, /* attr= */ null);
}
@Test
public void numberOfPreviewSamples_numberOfPreviewContentDescription_isEqual() {
int[] previewSamples = TextReadingPreviewController.getPreviewSampleLayouts(mContext);
int[] previewContentDescriptions =
TextReadingPreviewController.getPreviewSampleContentDescriptions(mContext);
assertThat(previewSamples.length).isEqualTo(previewContentDescriptions.length);
}
@Test
public void initPreviewerAdapter_verifyAction() {
when(mPreferenceScreen.findPreference(PREVIEW_KEY)).thenReturn(mPreviewPreference);

View File

@@ -49,48 +49,28 @@ import org.robolectric.RobolectricTestRunner;
*/
@RunWith(RobolectricTestRunner.class)
public class TextReadingPreviewPreferenceTest {
private Context mContext;
private TextReadingPreviewPreference mTextReadingPreviewPreference;
private PreferenceViewHolder mHolder;
private ViewPager mViewPager;
private PreviewPagerAdapter mPreviewPagerAdapter;
private int mPreviewSampleCount;
private int[] mPreviewContentDescriptions;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mPreviewContentDescriptions =
TextReadingPreviewController.getPreviewSampleContentDescriptions(mContext);
final int[] previewSamples = TextReadingPreviewController.getPreviewSampleLayouts(mContext);
final Context context = ApplicationProvider.getApplicationContext();
final int[] previewSamples = TextReadingPreviewController.getPreviewSampleLayouts(context);
mPreviewSampleCount = previewSamples.length;
final Configuration[] configurations = createConfigurations(mPreviewSampleCount);
mTextReadingPreviewPreference = new TextReadingPreviewPreference(mContext);
mTextReadingPreviewPreference = new TextReadingPreviewPreference(context);
mPreviewPagerAdapter =
spy(new PreviewPagerAdapter(mContext, /* isLayoutRtl= */ false,
spy(new PreviewPagerAdapter(context, /* isLayoutRtl= */ false,
previewSamples, configurations));
final LayoutInflater inflater = LayoutInflater.from(mContext);
final LayoutInflater inflater = LayoutInflater.from(context);
final View view =
inflater.inflate(mTextReadingPreviewPreference.getLayoutResource(),
new LinearLayout(mContext), false);
new LinearLayout(context), false);
mHolder = PreferenceViewHolder.createInstanceForTests(view);
mViewPager = view.findViewById(R.id.preview_pager);
mTextReadingPreviewPreference.setContentDescription(mPreviewContentDescriptions);
}
@Test
public void changePreviewPage_getExpectedContentDescription() {
mTextReadingPreviewPreference.setPreviewAdapter(mPreviewPagerAdapter);
mTextReadingPreviewPreference.onBindViewHolder(mHolder);
// Verify the initial content description
assertThat(mViewPager.getContentDescription().toString())
.isEqualTo(mContext.getString(mPreviewContentDescriptions[0]));
// Change the preview page
mViewPager.setCurrentItem(1);
assertThat(mViewPager.getContentDescription().toString())
.isEqualTo(mContext.getString(mPreviewContentDescriptions[1]));
}
@Test