Cancel SubtypePreference dialog properly

Bug: 6384416
Bug: 6387408
Change-Id: Ia7b0653a09410b42a55915815c887bf0ad56c856
This commit is contained in:
Tadashi G. Takaoka 2012-04-23 22:18:27 +09:00
parent 9f0a137f82
commit cbaf6d85f1

View file

@ -141,7 +141,8 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
public KeyboardLayoutSetAdapter getKeyboardLayoutSetAdapter(); public KeyboardLayoutSetAdapter getKeyboardLayoutSetAdapter();
} }
static class SubtypePreference extends DialogPreference { static class SubtypePreference extends DialogPreference
implements DialogInterface.OnCancelListener {
private static final String KEY_PREFIX = "subtype_pref_"; private static final String KEY_PREFIX = "subtype_pref_";
private static final String KEY_NEW_SUBTYPE = KEY_PREFIX + "new"; private static final String KEY_NEW_SUBTYPE = KEY_PREFIX + "new";
@ -205,6 +206,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
@Override @Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
final Context context = builder.getContext(); final Context context = builder.getContext();
builder.setCancelable(true).setOnCancelListener(this);
if (isIncomplete()) { if (isIncomplete()) {
builder.setPositiveButton(R.string.add, this) builder.setPositiveButton(R.string.add, this)
.setNegativeButton(android.R.string.cancel, this); .setNegativeButton(android.R.string.cancel, this);
@ -232,6 +234,13 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
} }
} }
@Override
public void onCancel(DialogInterface dialog) {
if (isIncomplete()) {
mProxy.onRemovePressed(this);
}
}
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
super.onClick(dialog, which); super.onClick(dialog, which);