Properly handle rotation in NotificationLockscreenPreference

There were some issues because we didn't explicitly
track and restore the selected position upon rotating,
so the fragment's oppinion of which item was selected
didn't match the ListView's.

Change-Id: Ia86e25dab36b44931297f8bcc7bcb7d6974f4b76
Fixes: 27921546
This commit is contained in:
Adrian Roos
2016-04-29 14:37:02 -07:00
parent e69d754865
commit 4bd42073d4
2 changed files with 34 additions and 6 deletions

View File

@@ -24,7 +24,6 @@ import android.os.Bundle;
import android.support.v14.preference.ListPreferenceDialogFragment;
import android.support.v7.preference.ListPreference;
import android.util.AttributeSet;
import android.view.View;
public class CustomListPreference extends ListPreference {
@@ -51,8 +50,14 @@ public class CustomListPreference extends ListPreference {
return true;
}
protected void onDialogStateRestored(Dialog dialog, Bundle savedInstanceState) {
}
public static class CustomListPreferenceDialogFragment extends ListPreferenceDialogFragment {
private static final java.lang.String KEY_CLICKED_ENTRY_INDEX
= "settings.CustomListPrefDialog.KEY_CLICKED_ENTRY_INDEX";
private int mClickedDialogEntryIndex;
public static ListPreferenceDialogFragment newInstance(String key) {
@@ -88,10 +93,26 @@ public class CustomListPreference extends ListPreference {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
if (savedInstanceState != null) {
mClickedDialogEntryIndex = savedInstanceState.getInt(KEY_CLICKED_ENTRY_INDEX,
mClickedDialogEntryIndex);
}
getCustomizablePreference().onDialogCreated(dialog);
return dialog;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(KEY_CLICKED_ENTRY_INDEX, mClickedDialogEntryIndex);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getCustomizablePreference().onDialogStateRestored(getDialog(), savedInstanceState);
}
protected DialogInterface.OnClickListener getOnItemClickListener() {
return new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {