Since creating the seekbar for changing font size in SystemUI requires the size of the value entry array and the values in the array. Therefore, we move the related resource to SettingsLib to share the usage. Bug: 242326166 Test: make RunSettingsRoboTests ROBOTEST_FILTER=FontSizeDataTest Test: Maually test the availability of changing font size through Settings page Change-Id: Ia2621e3b4c71f900e6591644d0e3f93bedbe4ee8 Merged-In: If630bd9c9c27823c210410b53342b921a11bbfb9
59 lines
2.2 KiB
Java
59 lines
2.2 KiB
Java
/*
|
|
* 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.settingslib.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));
|
|
}
|
|
}
|