Fix ClassCastException when users starts A11y vision settings from out of setup flow

Root cause: Launch A11y vision settings from out of setup flow would not apply setup wizard theme (SettingsPreferenceTheme_SetupWizard). This throws ClassCastException when converting the layout to support auto-switching two-panel pattern.
Solution: Only converting the layout if launched in setup flow.

Bug: 269267419
Test: Manual testing by `adb shell am start -n com.android.settings/com.android.settings.accessibility.AccessibilitySettingsForSetupWizardActivity` for out of setup flow cases & 'adb shell am start -a android.intent.action.MAIN -n com.google.android.setupwizard/.SetupWizardTestActivity' for setup flow.

Change-Id: I16871b2fa800dd1de539b7b4b96c32ce7b2cd5c9
This commit is contained in:
menghanli
2023-03-01 16:20:58 +08:00
parent 408a4045f1
commit fdc9a1b896
6 changed files with 110 additions and 81 deletions

View File

@@ -45,30 +45,36 @@ public class TextReadingPreferenceFragmentForSetupWizard extends TextReadingPref
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
final String title = getContext().getString(
R.string.accessibility_text_reading_options_title);
final Drawable icon = getContext().getDrawable(R.drawable.ic_accessibility_visibility);
icon.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorPrimary));
AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title,
/* description= */ null, icon);
if (view instanceof GlifPreferenceLayout) {
final GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
final String title = getContext().getString(
R.string.accessibility_text_reading_options_title);
final Drawable icon = getContext().getDrawable(R.drawable.ic_accessibility_visibility);
icon.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorPrimary));
AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title,
/* description= */ null, icon);
final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
AccessibilitySetupWizardUtils.setPrimaryButton(getContext(), mixin, R.string.done, () -> {
setResult(RESULT_CANCELED);
finish();
});
AccessibilitySetupWizardUtils.setSecondaryButton(getContext(), mixin,
R.string.accessibility_text_reading_reset_button_title,
() -> showDialog(DIALOG_RESET_SETTINGS)
);
final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
AccessibilitySetupWizardUtils.setPrimaryButton(getContext(), mixin, R.string.done,
() -> {
setResult(RESULT_CANCELED);
finish();
});
AccessibilitySetupWizardUtils.setSecondaryButton(getContext(), mixin,
R.string.accessibility_text_reading_reset_button_title,
() -> showDialog(DIALOG_RESET_SETTINGS)
);
}
}
@Override
public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
final GlifPreferenceLayout layout = (GlifPreferenceLayout) parent;
return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
if (parent instanceof GlifPreferenceLayout) {
final GlifPreferenceLayout layout = (GlifPreferenceLayout) parent;
return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
}
return super.onCreateRecyclerView(inflater, parent, savedInstanceState);
}
@Override