Make preview pager and pager indicator screenreader-enabled

Bug: 27127738
Change-Id: I11a8589f4d8e1f15e895831dc3bd0cb7472e0591
This commit is contained in:
Noah Wang
2016-03-03 20:05:14 -08:00
parent e0255a7197
commit 36e89f644e
8 changed files with 66 additions and 13 deletions

View File

@@ -24,8 +24,7 @@
android:id="@+id/preview_pager" android:id="@+id/preview_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?android:attr/colorBackgroundFloating" android:background="?android:attr/colorBackgroundFloating" />
android:importantForAccessibility="noHideDescendants"/>
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -20,7 +20,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/conversation_background" android:background="@color/conversation_background"
android:padding="@dimen/conversation_message_list_padding" android:padding="@dimen/conversation_message_list_padding"
android:orientation="vertical" > android:orientation="vertical"
android:importantForAccessibility="noHideDescendants">
<com.android.settings.display.ConversationMessageView <com.android.settings.display.ConversationMessageView
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -16,4 +16,5 @@
<com.android.settings.display.AppGridView <com.android.settings.display.AppGridView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
android:importantForAccessibility="noHideDescendants" />

View File

@@ -16,7 +16,8 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:importantForAccessibility="noHideDescendants">
<LinearLayout <LinearLayout
android:layout_width="@dimen/screen_zoom_preview_app_icon_width" android:layout_width="@dimen/screen_zoom_preview_app_icon_width"

View File

@@ -18,7 +18,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="none" android:scrollbars="none"
android:background="?android:attr/colorBackgroundFloating"> android:background="?android:attr/colorBackgroundFloating"
android:importantForAccessibility="noHideDescendants">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -147,6 +147,9 @@
<!-- Used for diagnostic info screens, precise translation isn't needed. Formats the SD card in the phone, meaning it will be erased and reformatted --> <!-- Used for diagnostic info screens, precise translation isn't needed. Formats the SD card in the phone, meaning it will be erased and reformatted -->
<string name="sdcard_format" product="default">Erase SD card</string> <string name="sdcard_format" product="default">Erase SD card</string>
<!-- Content description for dot pager indicator for preview pager. [CHAR LIMIT=NONE] -->
<string name="preview_page_indicator_content_description">Preview screen <xliff:g id="current_page" example="3">%1$d</xliff:g> of <xliff:g id="num_pages" example="9">%2$d</xliff:g></string>
<!-- Summary of font size setting screen. [CHAR LIMIT=NONE] --> <!-- Summary of font size setting screen. [CHAR LIMIT=NONE] -->
<string name="font_size_summary">Make the text on screen smaller or larger.</string> <string name="font_size_summary">Make the text on screen smaller or larger.</string>

View File

@@ -50,6 +50,9 @@ public class PreviewPagerAdapter extends PagerAdapter {
for (int i = 0; i < previewSampleResIds.length; ++i) { for (int i = 0; i < previewSampleResIds.length; ++i) {
mPreviewFrames[i] = (TouchBlockingFrameLayout) LayoutInflater.from(context) mPreviewFrames[i] = (TouchBlockingFrameLayout) LayoutInflater.from(context)
.inflate(R.layout.preview_frame_container, null); .inflate(R.layout.preview_frame_container, null);
mPreviewFrames[i].setContentDescription(
context.getString(R.string.preview_page_indicator_content_description, i + 1,
previewSampleResIds.length));
for (Configuration configuration : configurations) { for (Configuration configuration : configurations) {
// Create a new configuration for the specified value. It won't // Create a new configuration for the specified value. It won't

View File

@@ -20,10 +20,12 @@ import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; import android.widget.TextView;
@@ -48,11 +50,12 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
/** Resource id of the layout for this preference fragment. */ /** Resource id of the layout for this preference fragment. */
protected int mActivityLayoutResId; protected int mActivityLayoutResId;
/** Resource id of the layout that defines the contents instide preview screen. */ /** Resource id of the layout that defines the contents inside preview screen. */
protected int[] mPreviewSampleResIds; protected int[] mPreviewSampleResIds;
private ViewPager mPreviewPager; private ViewPager mPreviewPager;
private PreviewPagerAdapter mPreviewPagerAdapter; private PreviewPagerAdapter mPreviewPagerAdapter;
private DotsPageIndicator mPageIndicator;
private TextView mLabel; private TextView mLabel;
private View mLarger; private View mLarger;
@@ -132,7 +135,7 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
seekBar.setEnabled(false); seekBar.setEnabled(false);
} }
final Context context = getContext(); final Context context = getPrefContext();
final Configuration origConfig = context.getResources().getConfiguration(); final Configuration origConfig = context.getResources().getConfiguration();
Configuration[] configurations = new Configuration[mEntries.length]; Configuration[] configurations = new Configuration[mEntries.length];
for (int i = 0; i < mEntries.length; ++i) { for (int i = 0; i < mEntries.length; ++i) {
@@ -143,14 +146,47 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
configurations); configurations);
mPreviewPager = (ViewPager) content.findViewById(R.id.preview_pager); mPreviewPager = (ViewPager) content.findViewById(R.id.preview_pager);
mPreviewPager.setAdapter(mPreviewPagerAdapter); mPreviewPager.setAdapter(mPreviewPagerAdapter);
mPreviewPager.addOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int state) {
// Do nothing.
}
final DotsPageIndicator pageIndicator = @Override
(DotsPageIndicator) content.findViewById(R.id.page_indicator); public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
// Do nothing.
}
@Override
public void onPageSelected(int position) {
mPreviewPager.sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
}
});
mPageIndicator = (DotsPageIndicator) content.findViewById(R.id.page_indicator);
if (mPreviewSampleResIds.length > 1) { if (mPreviewSampleResIds.length > 1) {
pageIndicator.setViewPager(mPreviewPager); mPageIndicator.setViewPager(mPreviewPager);
pageIndicator.setVisibility(View.VISIBLE); mPageIndicator.setVisibility(View.VISIBLE);
mPageIndicator.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int state) {
// Do nothing.
}
@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
// Do nothing.
}
@Override
public void onPageSelected(int position) {
setPagerIndicatorContentDescription(position);
}
});
} else { } else {
pageIndicator.setVisibility(View.GONE); mPageIndicator.setVisibility(View.GONE);
} }
setPreviewLayer(mInitialIndex, false); setPreviewLayer(mInitialIndex, false);
@@ -176,11 +212,19 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
mSmaller.setEnabled(index > 0); mSmaller.setEnabled(index > 0);
mLarger.setEnabled(index < mEntries.length - 1); mLarger.setEnabled(index < mEntries.length - 1);
setPagerIndicatorContentDescription(mPreviewPager.getCurrentItem());
mPreviewPagerAdapter.setPreviewLayer(index, mCurrentIndex, mPreviewPager.getCurrentItem(), mPreviewPagerAdapter.setPreviewLayer(index, mCurrentIndex, mPreviewPager.getCurrentItem(),
animate); animate);
mCurrentIndex = index; mCurrentIndex = index;
} }
private void setPagerIndicatorContentDescription(int position) {
mPageIndicator.setContentDescription(
getPrefContext().getString(R.string.preview_page_indicator_content_description,
position + 1, mPreviewSampleResIds.length));
}
/** /**
* Persists the selected value and sends a configuration change. * Persists the selected value and sends a configuration change.
*/ */