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,58 @@
/*
* 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 static com.android.settings.display.ToggleFontSizePreferenceFragment.fontSizeValueToIndex;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import com.android.settings.R;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Data class for storing the configurations related to the font size.
*/
final class FontSizeData extends PreviewSizeData<Float> {
private static final float FONT_SCALE_DEF_VALUE = 1.0f;
FontSizeData(Context context) {
super(context);
final Resources resources = getContext().getResources();
final ContentResolver resolver = getContext().getContentResolver();
final List<String> strEntryValues =
Arrays.asList(resources.getStringArray(R.array.entryvalues_font_size));
setDefaultValue(FONT_SCALE_DEF_VALUE);
final float currentScale =
Settings.System.getFloat(resolver, Settings.System.FONT_SCALE, getDefaultValue());
setInitialIndex(fontSizeValueToIndex(currentScale, strEntryValues.toArray(new String[0])));
setValues(strEntryValues.stream().map(Float::valueOf).collect(Collectors.toList()));
}
@Override
void commit(int currentProgress) {
final ContentResolver resolver = getContext().getContentResolver();
Settings.System.putFloat(resolver, Settings.System.FONT_SCALE,
getValues().get(currentProgress));
}
}