Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f5153911 authored by Felipe Leme's avatar Felipe Leme Committed by android-build-merger
Browse files

Merge "Refactored ConfirmationDialogFragment to use default construcutor."...

Merge "Refactored ConfirmationDialogFragment to use default construcutor." into oc-dev am: 3cf690e9
am: 150fa397

Change-Id: Ibbc7d59b6db0f1b991266f5e41f8daf79f71e6ca
parents 2078bc23 150fa397
Loading
Loading
Loading
Loading
+18 −19
Original line number Diff line number Diff line
@@ -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.
         *
         * <p>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
+23 −4
Original line number Diff line number Diff line
@@ -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