Merge changes Iad13fbe1,I6eed7598 into main

* changes:
  Makes Use Color inversion searchable.
  Create a method to allow child classes to define it's main switch toggle's pref key
This commit is contained in:
Jean Chen
2024-10-09 03:25:55 +00:00
committed by Android (Google) Code Review
7 changed files with 87 additions and 32 deletions

View File

@@ -67,7 +67,7 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
initLaunchPreference();
final View view = super.onCreateView(inflater, container, savedInstanceState);
removePreference(KEY_USE_SERVICE_PREFERENCE);
removePreference(getUseServicePreferenceKey());
return view;
}

View File

@@ -33,6 +33,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -52,7 +54,10 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
private static final String TAG = "ToggleColorInversionPreferenceFragment";
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;
private static final String KEY_SHORTCUT_PREFERENCE = "color_inversion_shortcut_key";
@VisibleForTesting
static final String KEY_SHORTCUT_PREFERENCE = "color_inversion_shortcut_key";
@VisibleForTesting
static final String KEY_SWITCH_PREFERENCE = "color_inversion_switch_preference_key";
@Override
protected void registerKeysToObserverCallback(
@@ -73,9 +78,9 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
mHtmlDescription = getText(R.string.accessibility_display_inversion_preference_subtitle);
mTopIntroTitle = getText(R.string.accessibility_display_inversion_preference_intro_text);
mImageUri = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
.authority(getPrefContext().getPackageName())
.appendPath(String.valueOf(R.raw.a11y_color_inversion_banner))
.build();
.authority(getPrefContext().getPackageName())
.appendPath(String.valueOf(R.raw.a11y_color_inversion_banner))
.build();
final View view = super.onCreateView(inflater, container, savedInstanceState);
updateFooterPreference();
return view;
@@ -131,6 +136,11 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
switchPreference.setTitle(R.string.accessibility_display_inversion_switch_title);
}
@Override
protected String getUseServicePreferenceKey() {
return KEY_SWITCH_PREFERENCE;
}
@Override
protected CharSequence getShortcutTitle() {
return getText(R.string.accessibility_display_inversion_shortcut_title);
@@ -165,7 +175,7 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
@Override
int getUserShortcutTypes() {
return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
mComponentName);
mComponentName);
}
@Override
@@ -176,8 +186,8 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
@Override
CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT
? R.string.accessibility_color_inversion_qs_tooltip_content
: R.string.accessibility_color_inversion_auto_added_qs_tooltip_content);
? R.string.accessibility_color_inversion_qs_tooltip_content
: R.string.accessibility_color_inversion_auto_added_qs_tooltip_content);
}
@Override
@@ -194,12 +204,22 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
@Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
boolean enabled) {
final List<SearchIndexableRaw> rawData = new ArrayList<>();
final List<SearchIndexableRaw> rawData =
super.getRawDataToIndex(context, enabled);
SearchIndexableRaw raw = new SearchIndexableRaw(context);
raw.key = KEY_SHORTCUT_PREFERENCE;
raw.title = context.getString(
R.string.accessibility_display_inversion_shortcut_title);
R.string.accessibility_display_inversion_shortcut_title);
rawData.add(raw);
if (Flags.fixA11ySettingsSearch()) {
SearchIndexableRaw mainPreferenceRaw = new SearchIndexableRaw(context);
mainPreferenceRaw.key = KEY_SWITCH_PREFERENCE;
mainPreferenceRaw.title = context.getString(
R.string.accessibility_display_inversion_switch_title);
rawData.add(mainPreferenceRaw);
}
return rawData;
}
};

View File

@@ -106,7 +106,7 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
final List<String> lists = new ArrayList<>();
lists.add(KEY_TOP_INTRO_PREFERENCE);
lists.add(KEY_PREVIEW);
lists.add(KEY_USE_SERVICE_PREFERENCE);
lists.add(getUseServicePreferenceKey());
// Putting saturation level close to the preview so users can see what is changing.
lists.add(KEY_SATURATION);
lists.add(KEY_DEUTERANOMALY);

View File

@@ -83,7 +83,6 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
public static final String KEY_GENERAL_CATEGORY = "general_categories";
public static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
protected static final String KEY_TOP_INTRO_PREFERENCE = "top_intro";
protected static final String KEY_USE_SERVICE_PREFERENCE = "use_service";
protected static final String KEY_HTML_DESCRIPTION_PREFERENCE = "html_description";
protected static final String KEY_SAVED_QS_TOOLTIP_RESHOW = "qs_tooltip_reshow";
protected static final String KEY_SAVED_QS_TOOLTIP_TYPE = "qs_tooltip_type";
@@ -325,6 +324,10 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
switchPreference.setTitle(title);
}
protected String getUseServicePreferenceKey() {
return "use_service";
}
protected CharSequence getShortcutTitle() {
return getString(R.string.accessibility_shortcut_title, mPackageName);
}
@@ -411,7 +414,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
final List<String> lists = new ArrayList<>();
lists.add(KEY_TOP_INTRO_PREFERENCE);
lists.add(KEY_ANIMATED_IMAGE);
lists.add(KEY_USE_SERVICE_PREFERENCE);
lists.add(getUseServicePreferenceKey());
lists.add(KEY_GENERAL_CATEGORY);
lists.add(KEY_HTML_DESCRIPTION_PREFERENCE);
return lists;
@@ -476,7 +479,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
private void initToggleServiceSwitchPreference() {
mToggleServiceSwitchPreference = new SettingsMainSwitchPreference(getPrefContext());
mToggleServiceSwitchPreference.setKey(KEY_USE_SERVICE_PREFERENCE);
mToggleServiceSwitchPreference.setKey(getUseServicePreferenceKey());
if (getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
final boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED);
mToggleServiceSwitchPreference.setChecked(enabled);