Merge "Announce scaled value for font scaling seekbar in Talkback" into udc-dev
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);
|
||||
|
Reference in New Issue
Block a user