summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2013-03-29 18:56:30 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-03-29 18:56:30 -0700
commit377002fa1a7a69de48d2f655a75b20f290c9fb6c (patch)
treea716f2a9a6475afc0de88130b4792b40ae104980 /src
parent419b49882a2f77096e60249fcec0837f7067774b (diff)
parent26aca80eb1813cfe69450383efd8442805b16da5 (diff)
downloadpackages_apps_Settings-377002fa1a7a69de48d2f655a75b20f290c9fb6c.zip
packages_apps_Settings-377002fa1a7a69de48d2f655a75b20f290c9fb6c.tar.gz
packages_apps_Settings-377002fa1a7a69de48d2f655a75b20f290c9fb6c.tar.bz2
am 26aca80e: am a7ff2a2d: Merge "Follow changes to RestrictionEntry API" into jb-mr2-dev
* commit '26aca80eb1813cfe69450383efd8442805b16da5': Follow changes to RestrictionEntry API
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/Settings.java4
-rw-r--r--src/com/android/settings/users/AppRestrictionsFragment.java144
-rw-r--r--src/com/android/settings/users/RestrictionsReceiver.java36
3 files changed, 131 insertions, 53 deletions
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 64a7d7f..f7bdf27 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -460,8 +460,8 @@ public class Settings extends PreferenceActivity
} else if (id == R.id.application_settings) {
if (mAppRestrictions != null) {
for (RestrictionEntry entry : mAppRestrictions) {
- if (entry.key.equals(RestrictionsReceiver.KEY_ENABLE_APPS)
- && !entry.getBooleanValue()) {
+ if (entry.getKey().equals(RestrictionsReceiver.KEY_ENABLE_APPS)
+ && !entry.getSelectedState()) {
target.remove(i);
}
}
diff --git a/src/com/android/settings/users/AppRestrictionsFragment.java b/src/com/android/settings/users/AppRestrictionsFragment.java
index b610025..7f80686 100644
--- a/src/com/android/settings/users/AppRestrictionsFragment.java
+++ b/src/com/android/settings/users/AppRestrictionsFragment.java
@@ -31,6 +31,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.os.Parcelable;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.CheckBoxPreference;
@@ -90,6 +91,10 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
private boolean mFirstTime = true;
private boolean mNewUser;
+ private int mCustomRequestCode;
+ private HashMap<Integer, AppRestrictionsPreference> mCustomRequestMap =
+ new HashMap<Integer,AppRestrictionsPreference>();
+
public static class Activity extends PreferenceActivity {
@Override
public Intent getIntent() {
@@ -133,7 +138,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
RestrictionEntry getRestriction(String key) {
if (restrictions == null) return null;
for (RestrictionEntry entry : restrictions) {
- if (entry.key.equals(key)) {
+ if (entry.getKey().equals(key)) {
return entry;
}
}
@@ -296,7 +301,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
if (v.getTag() instanceof AppRestrictionsPreference) {
AppRestrictionsPreference pref = (AppRestrictionsPreference) v.getTag();
if (v.getId() == R.id.app_restrictions_settings) {
- handleSettingsClick(pref);
+ toggleAppPanel(pref);
} else if (!pref.isRequired()) {
pref.setChecked(!pref.isChecked());
mSelectedPackages.put(pref.getKey().substring(PKG_PREFIX.length()),
@@ -317,21 +322,18 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
ArrayList<RestrictionEntry> restrictions = appPref.getRestrictions();
if (restrictions != null) {
for (RestrictionEntry entry : restrictions) {
- if (entry.key.equals(restrictionKey)) {
- switch (entry.type) {
+ if (entry.getKey().equals(restrictionKey)) {
+ switch (entry.getType()) {
case RestrictionEntry.TYPE_BOOLEAN:
- entry.setValue((Boolean) newValue);
+ entry.setSelectedState((Boolean) newValue);
break;
case RestrictionEntry.TYPE_CHOICE:
case RestrictionEntry.TYPE_CHOICE_LEVEL:
ListPreference listPref = (ListPreference) preference;
- entry.setValue((String) newValue);
- for (int i = 0; i < listPref.getEntryValues().length; i++) {
- if (entry.values[i].equals(newValue)) {
- listPref.setSummary(entry.choices[i]);
- break;
- }
- }
+ entry.setSelectedString((String) newValue);
+ String readable = findInArray(entry.getChoiceEntries(),
+ entry.getChoiceValues(), (String) newValue);
+ listPref.setSummary(readable);
break;
case RestrictionEntry.TYPE_MULTI_SELECT:
MultiSelectListPreference msListPref =
@@ -339,7 +341,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
Set<String> set = (Set<String>) newValue;
String [] selectedValues = new String[set.size()];
set.toArray(selectedValues);
- entry.setMultipleValues(selectedValues);
+ entry.setAllSelectedStrings(selectedValues);
break;
default:
continue;
@@ -360,7 +362,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
return true;
}
- private void handleSettingsClick(AppRestrictionsPreference preference) {
+ private void toggleAppPanel(AppRestrictionsPreference preference) {
if (preference.getKey().startsWith(PKG_PREFIX)) {
if (preference.panelOpen) {
for (Preference p : preference.childPreferences) {
@@ -372,6 +374,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
List<RestrictionEntry> oldEntries =
mUserManager.getApplicationRestrictions(packageName, mUser);
Intent intent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES);
+ intent.setPackage(packageName);
intent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS,
new ArrayList<RestrictionEntry>(oldEntries));
getActivity().sendOrderedBroadcast(intent, null,
@@ -384,6 +387,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
class RestrictionsResultReceiver extends BroadcastReceiver {
+ private static final String CUSTOM_RESTRICTIONS_INTENT = Intent.EXTRA_RESTRICTIONS_INTENT;
String packageName;
AppRestrictionsPreference preference;
@@ -395,39 +399,43 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
@Override
public void onReceive(Context context, Intent intent) {
- ArrayList<RestrictionEntry> restrictions = getResultExtras(true).getParcelableArrayList(
+ Bundle results = getResultExtras(true);
+ final ArrayList<RestrictionEntry> restrictions = results.getParcelableArrayList(
Intent.EXTRA_RESTRICTIONS);
- if (restrictions != null) {
+ Intent restrictionsIntent = (Intent) results.getParcelable(CUSTOM_RESTRICTIONS_INTENT);
+ if (restrictions != null && restrictionsIntent == null) {
+ // Non-custom-activity case - expand the restrictions in-place
int count = 1;
for (RestrictionEntry entry : restrictions) {
Preference p = null;
- switch (entry.type) {
+ switch (entry.getType()) {
case RestrictionEntry.TYPE_BOOLEAN:
p = new CheckBoxPreference(context);
- p.setTitle(entry.title);
- p.setSummary(entry.description);
- ((CheckBoxPreference)p).setChecked(entry.getBooleanValue());
+ p.setTitle(entry.getTitle());
+ p.setSummary(entry.getDescription());
+ ((CheckBoxPreference)p).setChecked(entry.getSelectedState());
break;
case RestrictionEntry.TYPE_CHOICE:
case RestrictionEntry.TYPE_CHOICE_LEVEL:
p = new ListPreference(context);
- p.setTitle(entry.title);
- String value = entry.getStringValue();
+ p.setTitle(entry.getTitle());
+ String value = entry.getSelectedString();
if (value == null) {
- value = entry.description;
+ value = entry.getDescription();
}
- p.setSummary(value);
- ((ListPreference)p).setEntryValues(entry.values);
- ((ListPreference)p).setEntries(entry.choices);
- ((ListPreference)p).setValue(entry.getStringValue());
+ p.setSummary(findInArray(entry.getChoiceEntries(), entry.getChoiceValues(),
+ value));
+ ((ListPreference)p).setEntryValues(entry.getChoiceValues());
+ ((ListPreference)p).setEntries(entry.getChoiceEntries());
+ ((ListPreference)p).setValue(value);
break;
case RestrictionEntry.TYPE_MULTI_SELECT:
p = new MultiSelectListPreference(context);
- p.setTitle(entry.title);
- ((MultiSelectListPreference)p).setEntryValues(entry.values);
- ((MultiSelectListPreference)p).setEntries(entry.choices);
+ p.setTitle(entry.getTitle());
+ ((MultiSelectListPreference)p).setEntryValues(entry.getChoiceValues());
+ ((MultiSelectListPreference)p).setEntries(entry.getChoiceEntries());
HashSet<String> set = new HashSet<String>();
- for (String s : entry.getMultipleValues()) {
+ for (String s : entry.getAllSelectedStrings()) {
set.add(s);
}
((MultiSelectListPreference)p).setValues(set);
@@ -440,7 +448,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
p.setOrder(preference.getOrder() + count);
// Store the restrictions key string as a key for the preference
p.setKey(preference.getKey().substring(PKG_PREFIX.length()) + DELIMITER
- + entry.key);
+ + entry.getKey());
mAppList.addPreference(p);
p.setOnPreferenceChangeListener(AppRestrictionsFragment.this);
preference.childPreferences.add(p);
@@ -448,9 +456,79 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
}
}
preference.setRestrictions(restrictions);
+ mUserManager.setApplicationRestrictions(packageName, restrictions, mUser);
+ } else if (restrictionsIntent != null) {
+ final Intent customIntent = restrictionsIntent;
+ customIntent.putParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS, restrictions);
+ Preference p = new Preference(context);
+ p.setTitle(R.string.app_restrictions_custom_label);
+ p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ int requestCode = generateCustomActivityRequestCode(
+ RestrictionsResultReceiver.this.preference);
+ AppRestrictionsFragment.this.startActivityForResult(
+ customIntent, requestCode);
+ return false;
+ }
+ });
+ p.setPersistent(false);
+ p.setOrder(preference.getOrder() + 1);
+ preference.childPreferences.add(p);
+ mAppList.addPreference(p);
+ preference.setRestrictions(restrictions);
+ }
+ }
+ }
+
+ /**
+ * Generates a request code that is stored in a map to retrieve the associated
+ * AppRestrictionsPreference.
+ * @param preference
+ * @return
+ */
+ private int generateCustomActivityRequestCode(AppRestrictionsPreference preference) {
+ mCustomRequestCode++;
+ mCustomRequestMap.put(mCustomRequestCode, preference);
+ return mCustomRequestCode;
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ Log.i(TAG, "Got activity resultCode=" + resultCode + ", requestCode="
+ + requestCode + ", data=" + data);
+
+ AppRestrictionsPreference pref = mCustomRequestMap.get(requestCode);
+ if (pref == null) {
+ Log.w(TAG, "Unknown requestCode " + requestCode);
+ return;
+ }
+
+ if (resultCode == Activity.RESULT_OK) {
+ ArrayList<RestrictionEntry> list =
+ data.getParcelableArrayListExtra(Intent.EXTRA_RESTRICTIONS);
+ if (list != null) {
+ // If there's a valid result, persist it to the user manager.
+ String packageName = pref.getKey().substring(PKG_PREFIX.length());
+ pref.setRestrictions(list);
+ mUserManager.setApplicationRestrictions(packageName, list, mUser);
+ }
+ toggleAppPanel(pref);
+ }
+ // Remove request from the map
+ mCustomRequestMap.remove(requestCode);
+ }
+
+ private String findInArray(String[] choiceEntries, String[] choiceValues,
+ String selectedString) {
+ for (int i = 0; i < choiceValues.length; i++) {
+ if (choiceValues[i].equals(selectedString)) {
+ return choiceEntries[i];
}
- mUserManager.setApplicationRestrictions(packageName, restrictions, mUser);
}
+ return selectedString;
}
@Override
diff --git a/src/com/android/settings/users/RestrictionsReceiver.java b/src/com/android/settings/users/RestrictionsReceiver.java
index 0eeb7cd..52436b4 100644
--- a/src/com/android/settings/users/RestrictionsReceiver.java
+++ b/src/com/android/settings/users/RestrictionsReceiver.java
@@ -77,12 +77,12 @@ public class RestrictionsReceiver extends BroadcastReceiver {
String[] oldEnabledSections = new String[0];
if (old != null) {
for (RestrictionEntry r : old) {
- if (r.key.equals(KEY_ENABLE_APPS)) {
- oldEnableApps = r.getBooleanValue();
- } else if (r.key.equals(KEY_CONTENT_RATING)) {
- oldContentRating = r.getStringValue();
- } else if (r.key.equals(KEY_SECTIONS_TO_SHOW)) {
- oldEnabledSections = r.getMultipleValues();
+ if (r.getKey().equals(KEY_ENABLE_APPS)) {
+ oldEnableApps = r.getSelectedState();
+ } else if (r.getKey().equals(KEY_CONTENT_RATING)) {
+ oldContentRating = r.getSelectedString();
+ } else if (r.getKey().equals(KEY_SECTIONS_TO_SHOW)) {
+ oldEnabledSections = r.getAllSelectedStrings();
}
}
}
@@ -92,17 +92,17 @@ public class RestrictionsReceiver extends BroadcastReceiver {
RestrictionEntry r1 = new RestrictionEntry(KEY_ENABLE_APPS,
Boolean.toString(oldEnableApps));
- r1.title = "Enable apps";
- r1.description = "Show the Apps section in Settings";
- r1.type = RestrictionEntry.TYPE_BOOLEAN;
+ r1.setTitle("Enable apps");
+ r1.setDescription("Show the Apps section in Settings");
+ r1.setType(RestrictionEntry.TYPE_BOOLEAN);
newRestrictions.add(r1);
RestrictionEntry r2 = new RestrictionEntry(KEY_CONTENT_RATING, oldContentRating);
- r2.title = "Test: Content rating";
- r2.description = "Limit content to chosen rating and lower";
- r2.type = RestrictionEntry.TYPE_CHOICE_LEVEL;
- r2.values = new String[] { "G", "PG", "PG13", "R", "NR" };
- r2.choices = new String[] { "G", "PG", "PG-13", "Restricted", "Not Rated" };
+ r2.setTitle("Test: Content rating");
+ r2.setDescription("Limit content to chosen rating and lower");
+ r2.setType(RestrictionEntry.TYPE_CHOICE_LEVEL);
+ r2.setChoiceValues(new String[] { "G", "PG", "PG13", "R", "NR"});
+ r2.setChoiceEntries(new String[] { "G", "PG", "PG-13", "Restricted", "Not Rated" });
newRestrictions.add(r2);
String [] values = new String[SECTION_IDS.length];
@@ -114,10 +114,10 @@ public class RestrictionsReceiver extends BroadcastReceiver {
i++;
}
RestrictionEntry r3 = new RestrictionEntry(KEY_SECTIONS_TO_SHOW, oldEnabledSections);
- r3.type = RestrictionEntry.TYPE_MULTI_SELECT;
- r3.choices = choices;
- r3.values = values;
- r3.title = "Test: Sections to show";
+ r3.setType(RestrictionEntry.TYPE_MULTI_SELECT);
+ r3.setChoiceEntries(choices);
+ r3.setChoiceValues(values);
+ r3.setTitle("Test: Sections to show");
newRestrictions.add(r3);
Bundle extras = new Bundle();