Merge "Announce scaled value for font scaling seekbar in Talkback" into udc-dev am: 470dbd6884
am: c96e19f819
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/22347809 Change-Id: I66795c6f016a705acdd20526b443e50f8f89cac0 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||
import com.android.settings.widget.SeekBarPreference;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
||||
import com.android.settingslib.core.lifecycle.events.OnDestroy;
|
||||
@@ -52,11 +53,14 @@ abstract class PreviewSizeSeekBarController extends BasePreferenceController imp
|
||||
private AccessibilityQuickSettingsTooltipWindow mTooltipWindow;
|
||||
private final Handler mHandler;
|
||||
|
||||
private String[] mStateLabels = null;
|
||||
|
||||
private final SeekBar.OnSeekBarChangeListener mSeekBarChangeListener =
|
||||
new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
setSeekbarStateDescription(progress);
|
||||
|
||||
if (mInteractionListener.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -141,6 +145,7 @@ abstract class PreviewSizeSeekBarController extends BasePreferenceController imp
|
||||
if (mNeedsQSTooltipReshow) {
|
||||
mHandler.post(this::showQuickSettingsTooltipIfNeeded);
|
||||
}
|
||||
setSeekbarStateDescription(mSeekBarPreference.getProgress());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,6 +158,34 @@ abstract class PreviewSizeSeekBarController extends BasePreferenceController imp
|
||||
mInteractionListener.ifPresent(ProgressInteractionListener::onProgressChanged);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the String array we would like to use for describing the state of seekbar progress
|
||||
* and updates the state description with current progress.
|
||||
*
|
||||
* @param labels The state descriptions to be announced for each progress.
|
||||
*/
|
||||
public void setProgressStateLabels(String[] labels) {
|
||||
mStateLabels = labels;
|
||||
if (mStateLabels == null) {
|
||||
return;
|
||||
}
|
||||
updateState(mSeekBarPreference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the state of seekbar based on current progress. The progress of seekbar is
|
||||
* corresponding to the index of the string array. If the progress is larger than or equals
|
||||
* to the length of the array, the state description is set to an empty string.
|
||||
*/
|
||||
private void setSeekbarStateDescription(int index) {
|
||||
if (mStateLabels == null) {
|
||||
return;
|
||||
}
|
||||
mSeekBarPreference.setSeekBarStateDescription(
|
||||
(index < mStateLabels.length)
|
||||
? mStateLabels[index] : "");
|
||||
}
|
||||
|
||||
private void onProgressFinalized() {
|
||||
// Using progress in SeekBarPreference since the progresses in
|
||||
// SeekBarPreference and seekbar are not always the same.
|
||||
|
@@ -170,6 +170,15 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
R.string.accessibility_font_scaling_auto_added_qs_tooltip_content);
|
||||
}
|
||||
};
|
||||
final String[] labelArray = new String[fontSizeData.getValues().size()];
|
||||
for (int i = 0; i < labelArray.length; i++) {
|
||||
labelArray[i] =
|
||||
context.getResources().getString(
|
||||
com.android.settingslib.R.string.font_scale_percentage,
|
||||
(int) (fontSizeData.getValues().get(i) * 100)
|
||||
);
|
||||
}
|
||||
fontSizeController.setProgressStateLabels(labelArray);
|
||||
fontSizeController.setInteractionListener(mPreviewController);
|
||||
getSettingsLifecycle().addObserver(fontSizeController);
|
||||
controllers.add(fontSizeController);
|
||||
|
@@ -43,6 +43,7 @@ import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
|
||||
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||
import com.android.settings.widget.SeekBarPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -75,6 +76,7 @@ public class PreviewSizeSeekBarControllerTest {
|
||||
private PreferenceViewHolder mHolder;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceManager mPreferenceManager;
|
||||
private SeekBar mSeekBar;
|
||||
|
||||
@Mock
|
||||
private PreviewSizeSeekBarController.ProgressInteractionListener mInteractionListener;
|
||||
@@ -101,8 +103,10 @@ public class PreviewSizeSeekBarControllerTest {
|
||||
mSeekBarPreference.setKey(FONT_SIZE_KEY);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(
|
||||
R.layout.preference_labeled_slider, null));
|
||||
mHolder = spy(PreferenceViewHolder.createInstanceForTests(inflater.inflate(
|
||||
R.layout.preference_labeled_slider, null)));
|
||||
mSeekBar = spy(new SeekBar(mContext));
|
||||
doReturn(mSeekBar).when(mHolder).findViewById(com.android.internal.R.id.seekbar);
|
||||
mSeekBarPreference.onBindViewHolder(mHolder);
|
||||
|
||||
when(mPreferenceScreen.findPreference(anyString())).thenReturn(mSeekBarPreference);
|
||||
@@ -224,6 +228,22 @@ public class PreviewSizeSeekBarControllerTest {
|
||||
assertThat(getLatestPopupWindow().isShowing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProgressChanged_setCorrespondingCustomizedStateDescription() {
|
||||
String[] stateLabels = new String[]{"1", "2", "3", "4", "5"};
|
||||
mSeekBarController.setProgressStateLabels(stateLabels);
|
||||
mSeekBarController.displayPreference(mPreferenceScreen);
|
||||
|
||||
int progress = 3;
|
||||
mSeekBarPreference.setProgress(progress);
|
||||
mSeekBarPreference.onProgressChanged(mSeekBar,
|
||||
progress,
|
||||
/* fromUser= */ false);
|
||||
|
||||
verify(mSeekBarPreference).setSeekBarStateDescription(stateLabels[progress]);
|
||||
assertThat(mSeekBar.getStateDescription().toString()).isEqualTo(stateLabels[progress]);
|
||||
}
|
||||
|
||||
private static class TestFragment extends SettingsPreferenceFragment {
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user