Refactored ConfirmationDialogFragment to use default construcutor.
Test: manual verification Test: make RunSettingsRoboTests -j90 Fixes: 38397850 Change-Id: Ie724e7e92a6a34d4db16e4406bf821f00d98d180
This commit is contained in:
@@ -23,6 +23,7 @@ import android.app.DialogFragment;
|
|||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@@ -76,7 +77,9 @@ public abstract class DefaultAppPickerFragment extends RadioButtonPickerFragment
|
|||||||
|
|
||||||
protected ConfirmationDialogFragment newConfirmationDialogFragment(String selectedKey,
|
protected ConfirmationDialogFragment newConfirmationDialogFragment(String selectedKey,
|
||||||
CharSequence confirmationMessage) {
|
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) {
|
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_KEY = "extra_key";
|
||||||
public static final String EXTRA_MESSAGE = "extra_message";
|
public static final String EXTRA_MESSAGE = "extra_message";
|
||||||
|
|
||||||
private final DialogInterface.OnClickListener mCancelListener;
|
private DialogInterface.OnClickListener mCancelListener;
|
||||||
|
|
||||||
private ConfirmationDialogFragment(DialogInterface.OnClickListener cancelListener) {
|
|
||||||
mCancelListener = cancelListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return MetricsProto.MetricsEvent.DEFAULT_APP_PICKER_CONFIRMATION_DIALOG;
|
return MetricsProto.MetricsEvent.DEFAULT_APP_PICKER_CONFIRMATION_DIALOG;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfirmationDialogFragment newInstance(DefaultAppPickerFragment parent,
|
/**
|
||||||
String key, CharSequence message) {
|
* Initializes the fragment.
|
||||||
return newInstance(parent, key, message, null);
|
*
|
||||||
}
|
* <p>Should be called after it's constructed.
|
||||||
|
*/
|
||||||
// TODO: add test case for cancelListener
|
public void init(DefaultAppPickerFragment parent, String key, CharSequence message) {
|
||||||
public static ConfirmationDialogFragment newInstance(DefaultAppPickerFragment parent,
|
|
||||||
String key, CharSequence message, DialogInterface.OnClickListener cancelListener) {
|
|
||||||
final ConfirmationDialogFragment fragment = new ConfirmationDialogFragment(
|
|
||||||
cancelListener);
|
|
||||||
final Bundle argument = new Bundle();
|
final Bundle argument = new Bundle();
|
||||||
argument.putString(EXTRA_KEY, key);
|
argument.putString(EXTRA_KEY, key);
|
||||||
argument.putCharSequence(EXTRA_MESSAGE, message);
|
argument.putCharSequence(EXTRA_MESSAGE, message);
|
||||||
fragment.setArguments(argument);
|
setArguments(argument);
|
||||||
fragment.setTargetFragment(parent, 0);
|
setTargetFragment(parent, 0);
|
||||||
return fragment;
|
}
|
||||||
|
|
||||||
|
// TODO: add test case for cancelListener
|
||||||
|
public void setCancelListener(DialogInterface.OnClickListener cancelListener) {
|
||||||
|
this.mCancelListener = cancelListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.applications.defaultapps;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -60,7 +61,7 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment {
|
|||||||
/**
|
/**
|
||||||
* Set when the fragment is implementing ACTION_REQUEST_SET_AUTOFILL_SERVICE.
|
* 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();
|
private final Handler mHandler = new Handler();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -75,15 +76,33 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
mSettingsPackageMonitor.register(getActivity(), getActivity().getMainLooper(), false);
|
mSettingsPackageMonitor.register(activity, activity.getMainLooper(), false);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConfirmationDialogFragment newConfirmationDialogFragment(String selectedKey,
|
protected ConfirmationDialogFragment newConfirmationDialogFragment(String selectedKey,
|
||||||
CharSequence confirmationMessage) {
|
CharSequence confirmationMessage) {
|
||||||
return ConfirmationDialogFragment.newInstance(this, selectedKey, confirmationMessage,
|
final AutofillPickerConfirmationDialogFragment fragment =
|
||||||
mCancelListener);
|
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
|
@Override
|
||||||
|
Reference in New Issue
Block a user