Merge "Fix some crashes in the sample" into jb-mr2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fb6dc4fedf
@@ -21,7 +21,6 @@
|
|||||||
<string name="choice_entry_title">Test choice type</string>
|
<string name="choice_entry_title">Test choice type</string>
|
||||||
<string name="multi_entry_title">Test multi-select type</string>
|
<string name="multi_entry_title">Test multi-select type</string>
|
||||||
|
|
||||||
|
|
||||||
<string-array name="multi_entry_entries">
|
<string-array name="multi_entry_entries">
|
||||||
<item>Ice Cream</item>
|
<item>Ice Cream</item>
|
||||||
<item>Jelly Bean</item>
|
<item>Jelly Bean</item>
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import android.preference.PreferenceActivity;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class CustomRestrictionsActivity extends PreferenceActivity
|
public class CustomRestrictionsActivity extends PreferenceActivity
|
||||||
@@ -37,7 +38,7 @@ public class CustomRestrictionsActivity extends PreferenceActivity
|
|||||||
private static final String KEY_CHOICE_PREF = "choice";
|
private static final String KEY_CHOICE_PREF = "choice";
|
||||||
private static final String KEY_MULTI_PREF = "multi";
|
private static final String KEY_MULTI_PREF = "multi";
|
||||||
|
|
||||||
ArrayList<RestrictionEntry> mRestrictions;
|
List<RestrictionEntry> mRestrictions;
|
||||||
|
|
||||||
CheckBoxPreference mCustomPref;
|
CheckBoxPreference mCustomPref;
|
||||||
ListPreference mChoicePref;
|
ListPreference mChoicePref;
|
||||||
@@ -59,40 +60,56 @@ public class CustomRestrictionsActivity extends PreferenceActivity
|
|||||||
mRestrictions = savedInstanceState.getParcelableArrayList(Intent.EXTRA_RESTRICTIONS);
|
mRestrictions = savedInstanceState.getParcelableArrayList(Intent.EXTRA_RESTRICTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mRestrictions == null) {
|
||||||
|
mRestrictions = new ArrayList<RestrictionEntry>(getApplicationRestrictions());
|
||||||
|
}
|
||||||
|
|
||||||
this.addPreferencesFromResource(R.xml.custom_prefs);
|
this.addPreferencesFromResource(R.xml.custom_prefs);
|
||||||
mCustomPref = (CheckBoxPreference) findPreference(KEY_CUSTOM_PREF);
|
mCustomPref = (CheckBoxPreference) findPreference(KEY_CUSTOM_PREF);
|
||||||
mChoicePref = (ListPreference) findPreference(KEY_CHOICE_PREF);
|
mChoicePref = (ListPreference) findPreference(KEY_CHOICE_PREF);
|
||||||
mMultiPref = (MultiSelectListPreference) findPreference(KEY_MULTI_PREF);
|
mMultiPref = (MultiSelectListPreference) findPreference(KEY_MULTI_PREF);
|
||||||
|
|
||||||
// Transfer the saved values into the preference hierarchy
|
// Transfer the saved values into the preference hierarchy
|
||||||
for (RestrictionEntry entry : mRestrictions) {
|
if (mRestrictions != null) {
|
||||||
if (entry.getKey().equals(GetRestrictionsReceiver.KEY_CUSTOM)) {
|
for (RestrictionEntry entry : mRestrictions) {
|
||||||
mCustomPref.setChecked(entry.getSelectedState());
|
if (entry.getKey().equals(GetRestrictionsReceiver.KEY_CUSTOM)) {
|
||||||
mCustomEntry = entry;
|
mCustomPref.setChecked(entry.getSelectedState());
|
||||||
} else if (entry.getKey().equals(GetRestrictionsReceiver.KEY_CHOICE)) {
|
mCustomEntry = entry;
|
||||||
mChoicePref.setValue(entry.getSelectedString());
|
} else if (entry.getKey().equals(GetRestrictionsReceiver.KEY_CHOICE)) {
|
||||||
mChoiceEntry = entry;
|
mChoicePref.setValue(entry.getSelectedString());
|
||||||
} else if (entry.getKey().equals(GetRestrictionsReceiver.KEY_MULTI_SELECT)) {
|
mChoiceEntry = entry;
|
||||||
HashSet<String> set = new HashSet<String>();
|
} else if (entry.getKey().equals(GetRestrictionsReceiver.KEY_MULTI_SELECT)) {
|
||||||
for (String value : entry.getAllSelectedStrings()) {
|
HashSet<String> set = new HashSet<String>();
|
||||||
set.add(value);
|
for (String value : entry.getAllSelectedStrings()) {
|
||||||
|
set.add(value);
|
||||||
|
}
|
||||||
|
mMultiPref.setValues(set);
|
||||||
|
mMultiEntry = entry;
|
||||||
}
|
}
|
||||||
mMultiPref.setValues(set);
|
|
||||||
mMultiEntry = entry;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
mRestrictions = new ArrayList<RestrictionEntry>();
|
||||||
|
mCustomEntry = new RestrictionEntry(GetRestrictionsReceiver.KEY_CUSTOM, false);
|
||||||
|
mChoiceEntry = new RestrictionEntry(GetRestrictionsReceiver.KEY_CHOICE, (String) null);
|
||||||
|
mMultiEntry = new RestrictionEntry(GetRestrictionsReceiver.KEY_MULTI_SELECT,
|
||||||
|
new String[0]);
|
||||||
|
mRestrictions.add(mCustomEntry);
|
||||||
|
mRestrictions.add(mChoiceEntry);
|
||||||
|
mRestrictions.add(mMultiEntry);
|
||||||
}
|
}
|
||||||
mCustomPref.setOnPreferenceChangeListener(this);
|
mCustomPref.setOnPreferenceChangeListener(this);
|
||||||
mChoicePref.setOnPreferenceChangeListener(this);
|
mChoicePref.setOnPreferenceChangeListener(this);
|
||||||
mMultiPref.setOnPreferenceChangeListener(this);
|
mMultiPref.setOnPreferenceChangeListener(this);
|
||||||
Intent intent = new Intent(getIntent());
|
Intent intent = new Intent(getIntent());
|
||||||
intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS,
|
intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS,
|
||||||
mRestrictions);
|
new ArrayList<RestrictionEntry>(mRestrictions));
|
||||||
setResult(RESULT_OK, intent);
|
setResult(RESULT_OK, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putParcelableArrayList(Intent.EXTRA_RESTRICTIONS, mRestrictions);
|
outState.putParcelableArrayList(Intent.EXTRA_RESTRICTIONS,
|
||||||
|
new ArrayList<RestrictionEntry>(mRestrictions));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -111,7 +128,7 @@ public class CustomRestrictionsActivity extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
Intent intent = new Intent(getIntent());
|
Intent intent = new Intent(getIntent());
|
||||||
intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS,
|
intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS,
|
||||||
mRestrictions);
|
new ArrayList<RestrictionEntry>(mRestrictions));
|
||||||
setResult(RESULT_OK, intent);
|
setResult(RESULT_OK, intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user