Fix CustomListPreference click handling
Bug: 26187611 Change-Id: I6293d5577b4f770e2dfe94bae53fa9da0822cefc
This commit is contained in:
@@ -44,6 +44,8 @@ public class CustomListPreference extends ListPreference{
|
|||||||
|
|
||||||
public static class CustomListPreferenceDialogFragment extends ListPreferenceDialogFragment {
|
public static class CustomListPreferenceDialogFragment extends ListPreferenceDialogFragment {
|
||||||
|
|
||||||
|
private int mClickedDialogEntryIndex;
|
||||||
|
|
||||||
public static ListPreferenceDialogFragment newInstance(String key) {
|
public static ListPreferenceDialogFragment newInstance(String key) {
|
||||||
final ListPreferenceDialogFragment fragment = new CustomListPreferenceDialogFragment();
|
final ListPreferenceDialogFragment fragment = new CustomListPreferenceDialogFragment();
|
||||||
final Bundle b = new Bundle(1);
|
final Bundle b = new Bundle(1);
|
||||||
@@ -59,12 +61,35 @@ public class CustomListPreference extends ListPreference{
|
|||||||
@Override
|
@Override
|
||||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||||
super.onPrepareDialogBuilder(builder);
|
super.onPrepareDialogBuilder(builder);
|
||||||
getCustomizablePreference().onPrepareDialogBuilder(builder, this);
|
mClickedDialogEntryIndex = getCustomizablePreference()
|
||||||
|
.findIndexOfValue(getCustomizablePreference().getValue());
|
||||||
|
getCustomizablePreference().onPrepareDialogBuilder(builder,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
mClickedDialogEntryIndex = which;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Clicking on an item simulates the positive button
|
||||||
|
* click, and dismisses the dialog.
|
||||||
|
*/
|
||||||
|
CustomListPreferenceDialogFragment.this.onClick(dialog,
|
||||||
|
DialogInterface.BUTTON_POSITIVE);
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDialogClosed(boolean positiveResult) {
|
public void onDialogClosed(boolean positiveResult) {
|
||||||
getCustomizablePreference().onDialogClosed(positiveResult);
|
getCustomizablePreference().onDialogClosed(positiveResult);
|
||||||
|
final ListPreference preference = getCustomizablePreference();
|
||||||
|
if (positiveResult && mClickedDialogEntryIndex >= 0 &&
|
||||||
|
preference.getEntryValues() != null) {
|
||||||
|
String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString();
|
||||||
|
if (preference.callChangeListener(value)) {
|
||||||
|
preference.setValue(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user