Polish humanize strings for Caption preferences page
- Add intro for usage - Update footer description on limitations - Update the default caption size to medium - Update the caption size and style dynamically Bug: 218409087 Test: make RunSettingsRoboTests ROBOTEST_FILTER=CaptionAppearancePreferenceControllerTest Change-Id: I6526250894cc6a3fd02e3d8c675280855b307a68
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.view.accessibility.CaptioningManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import com.google.common.primitives.Floats;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
/** Controller that shows the caption scale and style summary. */
|
||||
public class CaptionAppearancePreferenceController extends BasePreferenceController {
|
||||
|
||||
private final CaptioningManager mCaptioningManager;
|
||||
|
||||
public CaptionAppearancePreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mCaptioningManager = context.getSystemService(CaptioningManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mContext.getString(R.string.preference_summary_default_combination,
|
||||
geFontScaleSummary(), getPresetSummary());
|
||||
}
|
||||
|
||||
private float[] getFontScaleValuesArray() {
|
||||
final String[] fontScaleValuesStrArray = mContext.getResources().getStringArray(
|
||||
R.array.captioning_font_size_selector_values);
|
||||
final int length = fontScaleValuesStrArray.length;
|
||||
final float[] fontScaleValuesArray = new float[length];
|
||||
for (int i = 0; i < length; ++i) {
|
||||
fontScaleValuesArray[i] = Float.parseFloat(fontScaleValuesStrArray[i]);
|
||||
}
|
||||
return fontScaleValuesArray;
|
||||
}
|
||||
|
||||
private CharSequence geFontScaleSummary() {
|
||||
final float[] fontScaleValuesArray = getFontScaleValuesArray();
|
||||
final String[] fontScaleSummaries = mContext.getResources().getStringArray(
|
||||
R.array.captioning_font_size_selector_titles);
|
||||
final float fontScale = mCaptioningManager.getFontScale();
|
||||
final int idx = Floats.indexOf(fontScaleValuesArray, fontScale);
|
||||
return fontScaleSummaries[idx == /* not exist */ -1 ? 0 : idx];
|
||||
}
|
||||
|
||||
private CharSequence getPresetSummary() {
|
||||
final int[] presetValuesArray = mContext.getResources().getIntArray(
|
||||
R.array.captioning_preset_selector_values);
|
||||
final String[] presetSummaries = mContext.getResources().getStringArray(
|
||||
R.array.captioning_preset_selector_titles);
|
||||
final int preset = mCaptioningManager.getRawUserStyle();
|
||||
final int idx = Ints.indexOf(presetValuesArray, preset);
|
||||
return presetSummaries[idx];
|
||||
}
|
||||
}
|
@@ -34,8 +34,6 @@ import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||
|
||||
import com.google.common.primitives.Floats;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -56,7 +54,6 @@ public class CaptionPropertiesFragment extends DashboardFragment
|
||||
private Preference mMoreOptions;
|
||||
|
||||
private final List<Preference> mPreferenceList = new ArrayList<>();
|
||||
private float[] mFontSizeValuesArray;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
@@ -71,13 +68,12 @@ public class CaptionPropertiesFragment extends DashboardFragment
|
||||
|
||||
initializeAllPreferences();
|
||||
installUpdateListeners();
|
||||
initFontSizeValuesArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateAllPreferences();
|
||||
mSwitch.setChecked(mCaptioningManager.isEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,21 +101,6 @@ public class CaptionPropertiesFragment extends DashboardFragment
|
||||
|
||||
}
|
||||
|
||||
private void initFontSizeValuesArray() {
|
||||
final String[] fontSizeValuesStrArray = getPrefContext().getResources().getStringArray(
|
||||
R.array.captioning_font_size_selector_values);
|
||||
final int length = fontSizeValuesStrArray.length;
|
||||
mFontSizeValuesArray = new float[length];
|
||||
for (int i = 0; i < length; ++i) {
|
||||
mFontSizeValuesArray[i] = Float.parseFloat(fontSizeValuesStrArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAllPreferences() {
|
||||
mSwitch.setChecked(mCaptioningManager.isEnabled());
|
||||
mTextAppearance.setSummary(geTextAppearanceSummary(getPrefContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
final ContentResolver cr = getActivity().getContentResolver();
|
||||
@@ -136,16 +117,6 @@ public class CaptionPropertiesFragment extends DashboardFragment
|
||||
return R.string.help_url_caption;
|
||||
}
|
||||
|
||||
private CharSequence geTextAppearanceSummary(Context context) {
|
||||
final String[] fontSizeSummaries = context.getResources().getStringArray(
|
||||
R.array.captioning_font_size_selector_summaries);
|
||||
|
||||
final float fontSize = mCaptioningManager.getFontScale();
|
||||
final int idx = Floats.indexOf(mFontSizeValuesArray, fontSize);
|
||||
|
||||
return fontSizeSummaries[idx == /* not exist */ -1 ? 0 : idx];
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.captioning_settings);
|
||||
|
||||
|
Reference in New Issue
Block a user