Misc tweaks to Indexable usage and tests.
- Make SettingsPreferenceFragment implement Indexable directly - Add existing fragments that are SettingsPrefFragment but not Indexable to grandfather list. - Fix "font size" fragment so it shows up in search properly. - Remove duplicates for "lock screen display", "Screen saver". Bug: 70720645 Test: robotests Change-Id: I44ce0cac0fdf5e882b315861bb4bebc45dbe01e6
This commit is contained in:
@@ -48,7 +48,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
@@ -75,7 +74,7 @@ import androidx.preference.SwitchPreference;
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener, Indexable {
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
// Index of the first preference in a preference category.
|
||||
private static final int FIRST_PREFERENCE_IN_CATEGORY_INDEX = -1;
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings.accessibility;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
@@ -26,10 +27,18 @@ import android.provider.Settings;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.PreviewSeekBarPreferenceFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Preference fragment used to control font size.
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class ToggleFontSizePreferenceFragment extends PreviewSeekBarPreferenceFragment {
|
||||
|
||||
private float[] mValues;
|
||||
@@ -39,7 +48,7 @@ public class ToggleFontSizePreferenceFragment extends PreviewSeekBarPreferenceFr
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mActivityLayoutResId = R.layout.font_size_activity;
|
||||
mPreviewSampleResIds = new int[]{R.layout.font_size_preview};
|
||||
mPreviewSampleResIds = new int[] {R.layout.font_size_preview};
|
||||
|
||||
Resources res = getContext().getResources();
|
||||
final ContentResolver resolver = getContext().getContentResolver();
|
||||
@@ -85,19 +94,35 @@ public class ToggleFontSizePreferenceFragment extends PreviewSeekBarPreferenceFr
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function that returns the index in a string array with which the represented value is
|
||||
* the closest to a given float value.
|
||||
* Utility function that returns the index in a string array with which the represented value is
|
||||
* the closest to a given float value.
|
||||
*/
|
||||
public static int fontSizeValueToIndex(float val, String[] indices) {
|
||||
float lastVal = Float.parseFloat(indices[0]);
|
||||
for (int i=1; i<indices.length; i++) {
|
||||
for (int i = 1; i < indices.length; i++) {
|
||||
float thisVal = Float.parseFloat(indices[i]);
|
||||
if (val < (lastVal + (thisVal-lastVal)*.5f)) {
|
||||
return i-1;
|
||||
if (val < (lastVal + (thisVal - lastVal) * .5f)) {
|
||||
return i - 1;
|
||||
}
|
||||
lastVal = thisVal;
|
||||
}
|
||||
return indices.length-1;
|
||||
return indices.length - 1;
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
|
||||
boolean enabled) {
|
||||
final ArrayList<SearchIndexableRaw> result = new ArrayList<>();
|
||||
final SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.title = context.getString(R.string.title_font_size);
|
||||
data.screenTitle = context.getString(R.string.title_font_size);
|
||||
data.key = "font_size_setting_screen";
|
||||
data.keywords = context.getString(R.string.keywords_display_font_size);
|
||||
result.add(data);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user