Merge "Improve RestrictionEntry API" into jb-mr2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9e8ba8f273
@@ -6178,6 +6178,7 @@ package android.content {
|
||||
field public static final java.lang.String EXTRA_REMOTE_INTENT_TOKEN = "android.intent.extra.remote_intent_token";
|
||||
field public static final java.lang.String EXTRA_REPLACING = "android.intent.extra.REPLACING";
|
||||
field public static final java.lang.String EXTRA_RESTRICTIONS = "android.intent.extra.restrictions";
|
||||
field public static final java.lang.String EXTRA_RESTRICTIONS_INTENT = "android.intent.extra.restrictions_intent";
|
||||
field public static final java.lang.String EXTRA_RETURN_RESULT = "android.intent.extra.RETURN_RESULT";
|
||||
field public static final java.lang.String EXTRA_SHORTCUT_ICON = "android.intent.extra.shortcut.ICON";
|
||||
field public static final java.lang.String EXTRA_SHORTCUT_ICON_RESOURCE = "android.intent.extra.shortcut.ICON_RESOURCE";
|
||||
@@ -6426,12 +6427,25 @@ package android.content {
|
||||
ctor public RestrictionEntry(java.lang.String, java.lang.String[]);
|
||||
ctor public RestrictionEntry(android.os.Parcel);
|
||||
method public int describeContents();
|
||||
method public boolean getBooleanValue();
|
||||
method public java.lang.String[] getMultipleValues();
|
||||
method public java.lang.String getStringValue();
|
||||
method public void setMultipleValues(java.lang.String[]);
|
||||
method public void setValue(java.lang.String);
|
||||
method public void setValue(boolean);
|
||||
method public java.lang.String[] getAllSelectedStrings();
|
||||
method public java.lang.String[] getChoiceEntries();
|
||||
method public java.lang.String[] getChoiceValues();
|
||||
method public java.lang.String getDescription();
|
||||
method public java.lang.String getKey();
|
||||
method public boolean getSelectedState();
|
||||
method public java.lang.String getSelectedString();
|
||||
method public java.lang.String getTitle();
|
||||
method public int getType();
|
||||
method public void setAllSelectedStrings(java.lang.String[]);
|
||||
method public void setChoiceEntries(java.lang.String[]);
|
||||
method public void setChoiceEntries(android.content.Context, int);
|
||||
method public void setChoiceValues(java.lang.String[]);
|
||||
method public void setChoiceValues(android.content.Context, int);
|
||||
method public void setDescription(java.lang.String);
|
||||
method public void setSelectedState(boolean);
|
||||
method public void setSelectedString(java.lang.String);
|
||||
method public void setTitle(java.lang.String);
|
||||
method public void setType(int);
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator CREATOR;
|
||||
field public static final int TYPE_BOOLEAN = 1; // 0x1
|
||||
@@ -6439,12 +6453,6 @@ package android.content {
|
||||
field public static final int TYPE_CHOICE_LEVEL = 3; // 0x3
|
||||
field public static final int TYPE_MULTI_SELECT = 4; // 0x4
|
||||
field public static final int TYPE_NULL = 0; // 0x0
|
||||
field public java.lang.String[] choices;
|
||||
field public java.lang.String description;
|
||||
field public java.lang.String key;
|
||||
field public java.lang.String title;
|
||||
field public int type;
|
||||
field public java.lang.String[] values;
|
||||
}
|
||||
|
||||
public class SearchRecentSuggestionsProvider extends android.content.ContentProvider {
|
||||
|
||||
@@ -2416,8 +2416,11 @@ public class Intent implements Parcelable, Cloneable {
|
||||
|
||||
/**
|
||||
* Broadcast to a specific application to query any supported restrictions to impose
|
||||
* on restricted users. The response should contain an extra {@link #EXTRA_RESTRICTIONS}
|
||||
* which is of type <code>ArrayList<RestrictionEntry></code>.
|
||||
* on restricted users. The response should contain an extra {@link #EXTRA_RESTRICTIONS},
|
||||
* which is of type <code>ArrayList<RestrictionEntry></code>. It can also
|
||||
* contain an extra {@link #EXTRA_RESTRICTIONS_INTENT}, which is of type <code>Intent</code>.
|
||||
* The activity specified by that intent will be launched for a result which must contain
|
||||
* the extra {@link #EXTRA_RESTRICTIONS}. The returned restrictions will be persisted.
|
||||
* @see RestrictionEntry
|
||||
*/
|
||||
public static final String ACTION_GET_RESTRICTION_ENTRIES =
|
||||
@@ -3161,6 +3164,13 @@ public class Intent implements Parcelable, Cloneable {
|
||||
*/
|
||||
public static final String EXTRA_RESTRICTIONS = "android.intent.extra.restrictions";
|
||||
|
||||
/**
|
||||
* Extra used in the response from a BroadcastReceiver that handles
|
||||
* {@link #ACTION_GET_RESTRICTION_ENTRIES}.
|
||||
*/
|
||||
public static final String EXTRA_RESTRICTIONS_INTENT =
|
||||
"android.intent.extra.restrictions_intent";
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// Intent flags (see mFlags variable).
|
||||
|
||||
@@ -34,141 +34,278 @@ import java.lang.annotation.Inherited;
|
||||
public class RestrictionEntry implements Parcelable {
|
||||
|
||||
/**
|
||||
* A type of restriction. Use this one for information that needs to be transferred across
|
||||
* but shouldn't be presented to the user in the UI.
|
||||
* A type of restriction. Use this type for information that needs to be transferred across
|
||||
* but shouldn't be presented to the user in the UI. Stores a single String value.
|
||||
*/
|
||||
public static final int TYPE_NULL = 0;
|
||||
|
||||
/**
|
||||
* A type of restriction. Use this for storing true/false values, typically presented as
|
||||
* A type of restriction. Use this for storing a boolean value, typically presented as
|
||||
* a checkbox in the UI.
|
||||
*/
|
||||
public static final int TYPE_BOOLEAN = 1;
|
||||
|
||||
/**
|
||||
* A type of restriction. Use this for storing a string value, typically presented as
|
||||
* a single-select list. The {@link #values} and {@link #choices} need to have the list of
|
||||
* possible values and the corresponding localized strings, respectively, to present in the UI.
|
||||
* a single-select list. Call {@link #setChoiceEntries(String[])} and
|
||||
* {@link #setChoiceValues(String[])} to set the localized list entries to present to the user
|
||||
* and the corresponding values, respectively.
|
||||
*/
|
||||
public static final int TYPE_CHOICE = 2;
|
||||
|
||||
/**
|
||||
* A type of restriction. Use this for storing a string value, typically presented as
|
||||
* a single-select list. The {@link #values} and {@link #choices} need to have the list of
|
||||
* possible values and the corresponding localized strings, respectively, to present in the UI.
|
||||
* a single-select list. Call {@link #setChoiceEntries(String[])} and
|
||||
* {@link #setChoiceValues(String[])} to set the localized list entries to present to the user
|
||||
* and the corresponding values, respectively.
|
||||
* The presentation could imply that values in lower array indices are included when a
|
||||
* particular value is chosen.
|
||||
*/
|
||||
public static final int TYPE_CHOICE_LEVEL = 3;
|
||||
|
||||
/**
|
||||
* A type of restriction. Use this for presenting a multi-select list where more than one
|
||||
* entry can be selected, such as for choosing specific titles to white-list.
|
||||
* The {@link #values} and {@link #choices} need to have the list of
|
||||
* possible values and the corresponding localized strings, respectively, to present in the UI.
|
||||
* Use {@link #getMultipleValues()} and {@link #setMultipleValues(String[])} to manipulate
|
||||
* the selections.
|
||||
* Call {@link #setChoiceEntries(String[])} and
|
||||
* {@link #setChoiceValues(String[])} to set the localized list entries to present to the user
|
||||
* and the corresponding values, respectively.
|
||||
* Use {@link #getAllSelectedStrings()} and {@link #setAllSelectedStrings(String[])} to
|
||||
* manipulate the selections.
|
||||
*/
|
||||
public static final int TYPE_MULTI_SELECT = 4;
|
||||
|
||||
/** The type of restriction. */
|
||||
public int type;
|
||||
private int type;
|
||||
|
||||
/** The unique key that identifies the restriction. */
|
||||
public String key;
|
||||
private String key;
|
||||
|
||||
/** The user-visible title of the restriction. */
|
||||
public String title;
|
||||
private String title;
|
||||
|
||||
/** The user-visible secondary description of the restriction. */
|
||||
public String description;
|
||||
private String description;
|
||||
|
||||
/** The user-visible set of choices used for single-select and multi-select lists. */
|
||||
public String [] choices;
|
||||
private String [] choices;
|
||||
|
||||
/** The values corresponding to the user-visible choices. The value(s) of this entry will
|
||||
* one or more of these, returned by {@link #getMultipleValues()} and
|
||||
* {@link #getStringValue()}.
|
||||
* one or more of these, returned by {@link #getAllSelectedStrings()} and
|
||||
* {@link #getSelectedString()}.
|
||||
*/
|
||||
public String [] values;
|
||||
private String [] values;
|
||||
|
||||
/* The chosen value, whose content depends on the type of the restriction. */
|
||||
private String currentValue;
|
||||
|
||||
/* List of selected choices in the multi-select case. */
|
||||
private String[] currentValues;
|
||||
|
||||
/**
|
||||
* Constructor for {@link #TYPE_CHOICE} and {@link #TYPE_CHOICE_LEVEL} types.
|
||||
* @param key the unique key for this restriction
|
||||
* @param value the current value
|
||||
* @param selectedString the current value
|
||||
*/
|
||||
public RestrictionEntry(String key, String value) {
|
||||
public RestrictionEntry(String key, String selectedString) {
|
||||
this.key = key;
|
||||
this.currentValue = value;
|
||||
this.currentValue = selectedString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link #TYPE_BOOLEAN} type.
|
||||
* @param key the unique key for this restriction
|
||||
* @param value the current value
|
||||
* @param selectedState whether this restriction is selected or not
|
||||
*/
|
||||
public RestrictionEntry(String key, boolean value) {
|
||||
public RestrictionEntry(String key, boolean selectedState) {
|
||||
this.key = key;
|
||||
setValue(value);
|
||||
setSelectedState(selectedState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for {@link #TYPE_MULTI_SELECT} type.
|
||||
* @param key the unique key for this restriction
|
||||
* @param multipleValues the list of values that are currently selected
|
||||
* @param selectedStrings the list of values that are currently selected
|
||||
*/
|
||||
public RestrictionEntry(String key, String[] multipleValues) {
|
||||
public RestrictionEntry(String key, String[] selectedStrings) {
|
||||
this.key = key;
|
||||
this.currentValues = multipleValues;
|
||||
this.currentValues = selectedStrings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current value. Null for {@link #TYPE_MULTI_SELECT} type.
|
||||
* @return the current value
|
||||
* Sets the type for this restriction.
|
||||
* @param type the type for this restriction.
|
||||
*/
|
||||
public String getStringValue() {
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type for this restriction.
|
||||
* @return the type for this restriction
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently selected string value.
|
||||
* @return the currently selected value, which can be null for types that aren't for holding
|
||||
* single string values.
|
||||
*/
|
||||
public String getSelectedString() {
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of current selections. Null if the type is not {@link #TYPE_MULTI_SELECT}.
|
||||
* @return the list of current selections.
|
||||
* Returns the list of currently selected values.
|
||||
* @return the list of current selections, if type is {@link #TYPE_MULTI_SELECT},
|
||||
* null otherwise.
|
||||
*/
|
||||
public String[] getMultipleValues() {
|
||||
public String[] getAllSelectedStrings() {
|
||||
return currentValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current boolean value for entries of type {@link #TYPE_BOOLEAN}.
|
||||
* @return the current value
|
||||
* Returns the current selected state for an entry of type {@link #TYPE_BOOLEAN}.
|
||||
* @return the current selected state of the entry.
|
||||
*/
|
||||
public boolean getBooleanValue() {
|
||||
public boolean getSelectedState() {
|
||||
return Boolean.parseBoolean(currentValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current string value.
|
||||
* @param s the current value
|
||||
* Sets the string value to use as the selected value for this restriction. This value will
|
||||
* be persisted by the system for later use by the application.
|
||||
* @param selectedString the string value to select.
|
||||
*/
|
||||
public void setValue(String s) {
|
||||
currentValue = s;
|
||||
public void setSelectedString(String selectedString) {
|
||||
currentValue = selectedString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current boolean value.
|
||||
* @param b the current value
|
||||
* Sets the current selected state for an entry of type {@link #TYPE_BOOLEAN}. This value will
|
||||
* be persisted by the system for later use by the application.
|
||||
* @param state the current selected state
|
||||
*/
|
||||
public void setValue(boolean b) {
|
||||
currentValue = Boolean.toString(b);
|
||||
public void setSelectedState(boolean state) {
|
||||
currentValue = Boolean.toString(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current list of selected values.
|
||||
* @param values the current list of selected values
|
||||
* Sets the current list of selected values for an entry of type {@link #TYPE_MULTI_SELECT}.
|
||||
* These values will be persisted by the system for later use by the application.
|
||||
* @param allSelectedStrings the current list of selected values.
|
||||
*/
|
||||
public void setMultipleValues(String[] values) {
|
||||
currentValues = values;
|
||||
public void setAllSelectedStrings(String[] allSelectedStrings) {
|
||||
currentValues = allSelectedStrings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of string values that can be selected by the user. If no user-visible entries
|
||||
* are set by a call to {@link #setChoiceEntries(String[])}, these values will be the ones
|
||||
* shown to the user. Values will be chosen from this list as the user's selection and the
|
||||
* selected values can be retrieved by a call to {@link #getAllSelectedStrings()}, or
|
||||
* {@link #getSelectedString()}, depending on whether it is a multi-select type or choice type.
|
||||
* This method is not relevant for types other than {@link #TYPE_CHOICE_LEVEL},
|
||||
* {@link #TYPE_CHOICE}, and {@link #TYPE_MULTI_SELECT}.
|
||||
* @param choiceValues an array of Strings which will be the selected values for the user's
|
||||
* selections.
|
||||
* @see #getChoiceValues()
|
||||
* @see #getAllSelectedStrings()
|
||||
*/
|
||||
public void setChoiceValues(String[] choiceValues) {
|
||||
values = choiceValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of string values that can be selected by the user, similar to
|
||||
* {@link #setChoiceValues(String[])}.
|
||||
* @param context the application context for retrieving the resources.
|
||||
* @param stringArrayResId the resource id for a string array containing the possible values.
|
||||
* @see #setChoiceValues(String[])
|
||||
*/
|
||||
public void setChoiceValues(Context context, int stringArrayResId) {
|
||||
values = context.getResources().getStringArray(stringArrayResId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of possible string values set earlier.
|
||||
* @return the list of possible values.
|
||||
*/
|
||||
public String[] getChoiceValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of strings that will be presented as choices to the user. When the
|
||||
* user selects one or more of these choices, the corresponding value from the possible values
|
||||
* are stored as the selected strings. The size of this array must match the size of the array
|
||||
* set in {@link #setChoiceValues(String[])}. This method is not relevant for types other
|
||||
* than {@link #TYPE_CHOICE_LEVEL}, {@link #TYPE_CHOICE}, and {@link #TYPE_MULTI_SELECT}.
|
||||
* @param choiceEntries the list of user-visible choices.
|
||||
* @see #setChoiceValues(String[])
|
||||
*/
|
||||
public void setChoiceEntries(String[] choiceEntries) {
|
||||
choices = choiceEntries;
|
||||
}
|
||||
|
||||
/** Sets a list of strings that will be presented as choices to the user. This is similar to
|
||||
* {@link #setChoiceEntries(String[])}.
|
||||
* @param context the application context, used for retrieving the resources.
|
||||
* @param stringArrayResId the resource id of a string array containing the possible entries.
|
||||
*/
|
||||
public void setChoiceEntries(Context context, int stringArrayResId) {
|
||||
choices = context.getResources().getStringArray(stringArrayResId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of strings, set earlier, that will be presented as choices to the user.
|
||||
* @return the list of choices presented to the user.
|
||||
*/
|
||||
public String[] getChoiceEntries() {
|
||||
return choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provided user-visible description of the entry, if any.
|
||||
* @return the user-visible description, null if none was set earlier.
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user-visible description of the entry, as a possible sub-text for the title.
|
||||
* You can use this to describe the entry in more detail or to display the current state of
|
||||
* the restriction.
|
||||
* @param description the user-visible description string.
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the unique key for the restriction entry.
|
||||
* @return the key for the restriction.
|
||||
*/
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user-visible title for the entry, if any.
|
||||
* @return the user-visible title for the entry, null if none was set earlier.
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user-visible title for the entry.
|
||||
* @param title the user-visible title for the entry.
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
private boolean equalArrays(String[] one, String[] other) {
|
||||
|
||||
@@ -1079,12 +1079,12 @@ public class UserManagerService extends IUserManager.Stub {
|
||||
|
||||
for (RestrictionEntry entry : entries) {
|
||||
serializer.startTag(null, TAG_ENTRY);
|
||||
serializer.attribute(null, ATTR_KEY, entry.key);
|
||||
if (entry.getStringValue() != null || entry.getMultipleValues() == null) {
|
||||
String value = entry.getStringValue();
|
||||
serializer.attribute(null, ATTR_KEY, entry.getKey());
|
||||
if (entry.getSelectedString() != null || entry.getAllSelectedStrings() == null) {
|
||||
String value = entry.getSelectedString();
|
||||
serializer.text(value != null ? value : "");
|
||||
} else {
|
||||
String[] values = entry.getMultipleValues();
|
||||
String[] values = entry.getAllSelectedStrings();
|
||||
serializer.attribute(null, ATTR_MULTIPLE, Integer.toString(values.length));
|
||||
for (String value : values) {
|
||||
serializer.startTag(null, TAG_VALUE);
|
||||
|
||||
Reference in New Issue
Block a user