Merge "Avoid checking the restricted items in the list." into nyc-dev
diff --git a/src/com/android/settings/RestrictedListPreference.java b/src/com/android/settings/RestrictedListPreference.java
index fca0071..521b698 100644
--- a/src/com/android/settings/RestrictedListPreference.java
+++ b/src/com/android/settings/RestrictedListPreference.java
@@ -25,10 +25,12 @@
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.ImageView;
import android.widget.ListAdapter;
+import android.widget.ListView;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreferenceHelper;
@@ -118,10 +120,15 @@
}
protected ListAdapter createListAdapter() {
+ return new RestrictedArrayAdapter(getContext(), getEntries(),
+ getSelectedValuePos());
+ }
+
+ public int getSelectedValuePos() {
final String selectedValue = getValue();
final int selectedIndex =
(selectedValue == null) ? -1 : findIndexOfValue(selectedValue);
- return new RestrictedArrayAdapter(getContext(), getEntries(), selectedIndex);
+ return selectedIndex;
}
@Override
@@ -173,6 +180,8 @@
public static class RestrictedListPreferenceDialogFragment extends
CustomListPreference.CustomListPreferenceDialogFragment {
+ private int mLastCheckedPosition = AdapterView.INVALID_POSITION;
+
public static ListPreferenceDialogFragment newInstance(String key) {
final ListPreferenceDialogFragment fragment
= new RestrictedListPreferenceDialogFragment();
@@ -197,6 +206,8 @@
String entryValue = preference.getEntryValues()[which].toString();
RestrictedItem item = preference.getRestrictedItemForEntryValue(entryValue);
if (item != null) {
+ ListView listView = ((AlertDialog) dialog).getListView();
+ listView.setItemChecked(getLastCheckedPosition(), true);
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(),
item.enforcedAdmin);
} else {
@@ -215,6 +226,24 @@
}
};
}
+
+ private int getLastCheckedPosition() {
+ if (mLastCheckedPosition == AdapterView.INVALID_POSITION) {
+ mLastCheckedPosition = ((RestrictedListPreference) getCustomizablePreference())
+ .getSelectedValuePos();
+ }
+ return mLastCheckedPosition;
+ }
+
+ private void setCheckedPosition(int checkedPosition) {
+ mLastCheckedPosition = checkedPosition;
+ }
+
+ @Override
+ protected void setClickedDialogEntryIndex(int which) {
+ super.setClickedDialogEntryIndex(which);
+ mLastCheckedPosition = which;
+ }
}
public static class RestrictedItem {
diff --git a/src/com/android/settings/notification/NotificationLockscreenPreference.java b/src/com/android/settings/notification/NotificationLockscreenPreference.java
index 969aed1..34770da 100644
--- a/src/com/android/settings/notification/NotificationLockscreenPreference.java
+++ b/src/com/android/settings/notification/NotificationLockscreenPreference.java
@@ -29,6 +29,7 @@
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ListAdapter;
+import android.widget.ListView;
public class NotificationLockscreenPreference extends RestrictedListPreference {
@@ -101,8 +102,11 @@
@Override
public void onClick(DialogInterface dialog, int which) {
mInner.onClick(dialog, which);
+ ListView listView = ((AlertDialog) dialog).getListView();
+ int selectedPosition = listView.getCheckedItemPosition();
if (mView != null) {
- mView.setVisibility(checkboxVisibilityForSelectedIndex(which, mShowRemoteInput));
+ mView.setVisibility(
+ checkboxVisibilityForSelectedIndex(selectedPosition, mShowRemoteInput));
}
}