diff --git a/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java b/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java index 73f4bbe9720..a08711c160c 100644 --- a/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java +++ b/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragment.java @@ -23,6 +23,7 @@ import android.app.DialogFragment; import android.app.Fragment; import android.content.Context; import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.text.TextUtils; @@ -76,7 +77,9 @@ public abstract class DefaultAppPickerFragment extends RadioButtonPickerFragment protected ConfirmationDialogFragment newConfirmationDialogFragment(String selectedKey, CharSequence confirmationMessage) { - return ConfirmationDialogFragment.newInstance(this, selectedKey, confirmationMessage); + final ConfirmationDialogFragment fragment = new ConfirmationDialogFragment(); + fragment.init(this, selectedKey, confirmationMessage); + return fragment; } protected CharSequence getConfirmationMessage(CandidateInfo info) { @@ -90,33 +93,29 @@ public abstract class DefaultAppPickerFragment extends RadioButtonPickerFragment public static final String EXTRA_KEY = "extra_key"; public static final String EXTRA_MESSAGE = "extra_message"; - private final DialogInterface.OnClickListener mCancelListener; - - private ConfirmationDialogFragment(DialogInterface.OnClickListener cancelListener) { - mCancelListener = cancelListener; - } + private DialogInterface.OnClickListener mCancelListener; @Override public int getMetricsCategory() { return MetricsProto.MetricsEvent.DEFAULT_APP_PICKER_CONFIRMATION_DIALOG; } - public static ConfirmationDialogFragment newInstance(DefaultAppPickerFragment parent, - String key, CharSequence message) { - return newInstance(parent, key, message, null); - } - - // TODO: add test case for cancelListener - public static ConfirmationDialogFragment newInstance(DefaultAppPickerFragment parent, - String key, CharSequence message, DialogInterface.OnClickListener cancelListener) { - final ConfirmationDialogFragment fragment = new ConfirmationDialogFragment( - cancelListener); + /** + * Initializes the fragment. + * + *
Should be called after it's constructed. + */ + public void init(DefaultAppPickerFragment parent, String key, CharSequence message) { final Bundle argument = new Bundle(); argument.putString(EXTRA_KEY, key); argument.putCharSequence(EXTRA_MESSAGE, message); - fragment.setArguments(argument); - fragment.setTargetFragment(parent, 0); - return fragment; + setArguments(argument); + setTargetFragment(parent, 0); + } + + // TODO: add test case for cancelListener + public void setCancelListener(DialogInterface.OnClickListener cancelListener) { + this.mCancelListener = cancelListener; } @Override diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java index 6dcf7b8b39a..d674522873b 100644 --- a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java +++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java @@ -18,6 +18,7 @@ package com.android.settings.applications.defaultapps; import android.Manifest; import android.app.Activity; +import android.app.Dialog; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; @@ -60,7 +61,7 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment { /** * Set when the fragment is implementing ACTION_REQUEST_SET_AUTOFILL_SERVICE. */ - public DialogInterface.OnClickListener mCancelListener; + private DialogInterface.OnClickListener mCancelListener; private final Handler mHandler = new Handler(); @Override @@ -75,15 +76,33 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment { }; } - mSettingsPackageMonitor.register(getActivity(), getActivity().getMainLooper(), false); + mSettingsPackageMonitor.register(activity, activity.getMainLooper(), false); update(); } @Override protected ConfirmationDialogFragment newConfirmationDialogFragment(String selectedKey, CharSequence confirmationMessage) { - return ConfirmationDialogFragment.newInstance(this, selectedKey, confirmationMessage, - mCancelListener); + final AutofillPickerConfirmationDialogFragment fragment = + new AutofillPickerConfirmationDialogFragment(); + fragment.init(this, selectedKey, confirmationMessage); + return fragment; + } + + /** + * Custom dialog fragment that has a cancel listener used to propagate the result back to + * caller (for the cases where the picker is launched by + * {@code android.settings.REQUEST_SET_AUTOFILL_SERVICE}. + */ + public static class AutofillPickerConfirmationDialogFragment + extends ConfirmationDialogFragment { + + @Override + public void onCreate(Bundle savedInstanceState) { + final DefaultAutofillPicker target = (DefaultAutofillPicker) getTargetFragment(); + setCancelListener(target.mCancelListener); + super.onCreate(savedInstanceState); + } } @Override