New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (10/n).

- Create the font size LabeledSeekBarPreference and add the entry
1) It's integrated with the system font scale configurations.
2) Create the new PreviewSizeSeekBarController component for controlling the LabeledSeekBarPreference of the display/font size.
3) Create the new PreviewSizeData component to store the configurations related to the display/font size features.

Bug: 211503117
Test: make RunSettingsRoboTests ROBOTEST_FILTER=FontSizeDataTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=PreviewSizeSeekBarControllerTest

Change-Id: I0c1cf6d0425c5c8b61cc8ed0c9fedadf7a65bd27
This commit is contained in:
Peter_Liang
2022-01-21 00:53:32 +08:00
parent 0ee078d37a
commit 4681ef2b47
7 changed files with 408 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.accessibility;
import android.content.Context;
import android.widget.SeekBar;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.widget.LabeledSeekBarPreference;
/**
* The controller of {@link LabeledSeekBarPreference} that listens to display size and font size
* settings changes and updates preview size threshold smoothly.
*/
class PreviewSizeSeekBarController extends BasePreferenceController {
private final PreviewSizeData<? extends Number> mSizeData;
private boolean mSeekByTouch;
private ProgressInteractionListener mInteractionListener;
private final SeekBar.OnSeekBarChangeListener mSeekBarChangeListener =
new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mInteractionListener.notifyPreferenceChanged();
if (!mSeekByTouch && mInteractionListener != null) {
mInteractionListener.onProgressChanged();
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
mSeekByTouch = true;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mSeekByTouch = false;
if (mInteractionListener != null) {
mInteractionListener.onEndTrackingTouch();
}
}
};
PreviewSizeSeekBarController(Context context, String preferenceKey,
@NonNull PreviewSizeData<? extends Number> sizeData) {
super(context, preferenceKey);
mSizeData = sizeData;
}
void setInteractionListener(ProgressInteractionListener interactionListener) {
mInteractionListener = interactionListener;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
final int dataSize = mSizeData.getValues().size();
final int initialIndex = mSizeData.getInitialIndex();
final LabeledSeekBarPreference seekBarPreference =
screen.findPreference(getPreferenceKey());
seekBarPreference.setMax(dataSize - 1);
seekBarPreference.setProgress(initialIndex);
seekBarPreference.setContinuousUpdates(true);
seekBarPreference.setOnSeekBarChangeListener(mSeekBarChangeListener);
}
/**
* Interface for callbacks when users interact with the seek bar.
*/
interface ProgressInteractionListener {
/**
* Called when the progress is changed.
*/
void notifyPreferenceChanged();
/**
* Called when the progress is changed without tracking touch.
*/
void onProgressChanged();
/**
* Called when the seek bar is end tracking.
*/
void onEndTrackingTouch();
}
}