1df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani/*
2df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * Copyright (C) 2013 The Android Open Source Project
3df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani *
4df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * Licensed under the Apache License, Version 2.0 (the "License");
5df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * you may not use this file except in compliance with the License.
6df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * You may obtain a copy of the License at
7df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani *
8df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani *      http://www.apache.org/licenses/LICENSE-2.0
9df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani *
10df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * Unless required by applicable law or agreed to in writing, software
11df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * distributed under the License is distributed on an "AS IS" BASIS,
12df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * See the License for the specific language governing permissions and
14df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * limitations under the License.
15df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */
16df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
17df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasanipackage android.content;
18df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
197b9c912f536925ac6ec43935d6e97506851b33d6Tor Norbyeimport android.annotation.ArrayRes;
20df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasaniimport android.os.Parcel;
21df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasaniimport android.os.Parcelable;
22df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
23262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolovimport java.util.Arrays;
24262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolovimport java.util.Objects;
25262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov
26df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani/**
27df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * Applications can expose restrictions for a restricted user on a
28df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * multiuser device. The administrator can configure these restrictions that will then be
29df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * applied to the restricted user. Each RestrictionsEntry is one configurable restriction.
30df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * <p/>
31df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * Any application that chooses to expose such restrictions does so by implementing a
321eab5f26939748dea5e94bf019804a68d2a2b161Amith Yamasani * receiver that handles the {@link Intent#ACTION_GET_RESTRICTION_ENTRIES} action.
33df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * The receiver then returns a result bundle that contains an entry called "restrictions", whose
34df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani * value is an ArrayList<RestrictionsEntry>.
35df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani */
36df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasanipublic class RestrictionEntry implements Parcelable {
37df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
38df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
39262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Hidden restriction type. Use this type for information that needs to be transferred
40262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * across but shouldn't be presented to the user in the UI. Stores a single String value.
41df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
42df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public static final int TYPE_NULL         = 0;
4386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
44df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
45262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Restriction of type "bool". Use this for storing a boolean value, typically presented as
46df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * a checkbox in the UI.
47df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
48df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public static final int TYPE_BOOLEAN      = 1;
4986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
50df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
51262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Restriction of type "choice". Use this for storing a string value, typically presented as
5286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * a single-select list. Call {@link #setChoiceEntries(String[])} and
5386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * {@link #setChoiceValues(String[])} to set the localized list entries to present to the user
5486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * and the corresponding values, respectively.
55df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
56df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public static final int TYPE_CHOICE       = 2;
5786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
58df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
59262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Internal restriction type. Use this for storing a string value, typically presented as
6086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * a single-select list. Call {@link #setChoiceEntries(String[])} and
6186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * {@link #setChoiceValues(String[])} to set the localized list entries to present to the user
6286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * and the corresponding values, respectively.
63df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * The presentation could imply that values in lower array indices are included when a
64df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * particular value is chosen.
65d5e946a52c5095c05a4621073f428649ad626430Amith Yamasani     * @hide
66df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
67df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public static final int TYPE_CHOICE_LEVEL = 3;
6886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
69df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
70262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Restriction of type "multi-select". Use this for presenting a multi-select list where more
71262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * than one entry can be selected, such as for choosing specific titles to white-list.
7286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Call {@link #setChoiceEntries(String[])} and
7386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * {@link #setChoiceValues(String[])} to set the localized list entries to present to the user
7486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * and the corresponding values, respectively.
7586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Use {@link #getAllSelectedStrings()} and {@link #setAllSelectedStrings(String[])} to
7686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * manipulate the selections.
77df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
78df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public static final int TYPE_MULTI_SELECT = 4;
79df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
80f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    /**
81262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Restriction of type "integer". Use this for storing an integer value. The range of values
82f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     * is from {@link Integer#MIN_VALUE} to {@link Integer#MAX_VALUE}.
83f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     */
84f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    public static final int TYPE_INTEGER = 5;
85f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani
86c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani    /**
87262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Restriction of type "string". Use this for storing a string value.
88c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani     * @see #setSelectedString
89c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani     * @see #getSelectedString
90c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani     */
91c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani    public static final int TYPE_STRING = 6;
92c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani
93262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    /**
94262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Restriction of type "bundle". Use this for storing {@link android.os.Bundle bundles} of
95262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * restrictions
96262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     */
97262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    public static final int TYPE_BUNDLE = 7;
98262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov
99262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    /**
100262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Restriction of type "bundle_array". Use this for storing arrays of
101262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * {@link android.os.Bundle bundles} of restrictions
102262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     */
103262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    public static final int TYPE_BUNDLE_ARRAY = 8;
104262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov
105df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /** The type of restriction. */
106f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    private int mType;
107df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
108df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /** The unique key that identifies the restriction. */
109f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    private String mKey;
110df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
111df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /** The user-visible title of the restriction. */
112f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    private String mTitle;
113df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
114df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /** The user-visible secondary description of the restriction. */
115f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    private String mDescription;
116df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
117df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /** The user-visible set of choices used for single-select and multi-select lists. */
118262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    private String[] mChoiceEntries;
119df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
120df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /** The values corresponding to the user-visible choices. The value(s) of this entry will
12186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * one or more of these, returned by {@link #getAllSelectedStrings()} and
12286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * {@link #getSelectedString()}.
123df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
124262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    private String[] mChoiceValues;
125df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
126df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /* The chosen value, whose content depends on the type of the restriction. */
127f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    private String mCurrentValue;
12886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
129df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /* List of selected choices in the multi-select case. */
130f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    private String[] mCurrentValues;
131df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
132df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
133262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * List of nested restrictions. Used by {@link #TYPE_BUNDLE bundle} and
134262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * {@link #TYPE_BUNDLE_ARRAY bundle_array} restrictions.
135262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     */
136262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    private RestrictionEntry[] mRestrictions;
137262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov
138262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    /**
139c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani     * Constructor for specifying the type and key, with no initial value;
140c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani     *
141c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani     * @param type the restriction type.
142c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani     * @param key the unique key for this restriction
143c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani     */
144c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani    public RestrictionEntry(int type, String key) {
145c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani        mType = type;
146c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani        mKey = key;
147c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani    }
148c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani
149c8c8425b51a4f68fae993e68b357679ca27d155dAmith Yamasani    /**
150d5e946a52c5095c05a4621073f428649ad626430Amith Yamasani     * Constructor for {@link #TYPE_CHOICE} type.
151df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @param key the unique key for this restriction
15286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param selectedString the current value
153df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
15486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public RestrictionEntry(String key, String selectedString) {
155f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mKey = key;
156f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mType = TYPE_CHOICE;
157f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mCurrentValue = selectedString;
158df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
159df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
160df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
161df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * Constructor for {@link #TYPE_BOOLEAN} type.
162df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @param key the unique key for this restriction
16386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param selectedState whether this restriction is selected or not
164df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
16586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public RestrictionEntry(String key, boolean selectedState) {
166f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mKey = key;
167f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mType = TYPE_BOOLEAN;
16886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani        setSelectedState(selectedState);
169df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
170df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
171df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
172df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * Constructor for {@link #TYPE_MULTI_SELECT} type.
173df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     * @param key the unique key for this restriction
17486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param selectedStrings the list of values that are currently selected
175df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
17686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public RestrictionEntry(String key, String[] selectedStrings) {
177f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mKey = key;
178f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mType = TYPE_MULTI_SELECT;
179f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mCurrentValues = selectedStrings;
180f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    }
181f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani
182f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    /**
183f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     * Constructor for {@link #TYPE_INTEGER} type.
184f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     * @param key the unique key for this restriction
185f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     * @param selectedInt the integer value of the restriction
186f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     */
187f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    public RestrictionEntry(String key, int selectedInt) {
188f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mKey = key;
189f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mType = TYPE_INTEGER;
190f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        setIntValue(selectedInt);
19186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
19286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
19386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
194262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Constructor for {@link #TYPE_BUNDLE}/{@link #TYPE_BUNDLE_ARRAY} type.
195262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * @param key the unique key for this restriction
196262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * @param restrictionEntries array of nested restriction entries. If the entry, being created
197262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * represents a {@link #TYPE_BUNDLE_ARRAY bundle-array}, {@code restrictionEntries} array may
198262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * only contain elements of type {@link #TYPE_BUNDLE bundle}.
199262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * @param isBundleArray true if this restriction represents
200262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * {@link #TYPE_BUNDLE_ARRAY bundle-array} type, otherwise the type will be set to
201262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * {@link #TYPE_BUNDLE bundle}.
202262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     */
203f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov    private RestrictionEntry(String key, RestrictionEntry[] restrictionEntries,
204262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            boolean isBundleArray) {
205262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        mKey = key;
206262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        if (isBundleArray) {
207262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            mType = TYPE_BUNDLE_ARRAY;
208262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            if (restrictionEntries != null) {
209262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                for (RestrictionEntry restriction : restrictionEntries) {
210262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                    if (restriction.getType() != TYPE_BUNDLE) {
211262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                        throw new IllegalArgumentException("bundle_array restriction can only have "
212262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                                + "nested restriction entries of type bundle");
213262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                    }
214262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                }
215262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            }
216262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        } else {
217262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            mType = TYPE_BUNDLE;
218262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        }
219262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        setRestrictions(restrictionEntries);
220262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    }
221262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov
222262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    /**
223f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     * Creates an entry of type {@link #TYPE_BUNDLE}.
224f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     * @param key the unique key for this restriction
225f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     * @param restrictionEntries array of nested restriction entries.
226f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     * @return the newly created restriction
227f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     */
228f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov    public static RestrictionEntry createBundleEntry(String key,
229f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov            RestrictionEntry[] restrictionEntries) {
230f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov        return new RestrictionEntry(key, restrictionEntries, false);
231f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov    }
232f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov
233f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov    /**
234f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     * Creates an entry of type {@link #TYPE_BUNDLE_ARRAY}.
235f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     * @param key the unique key for this restriction
236f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     * @param restrictionEntries array of nested restriction entries. The array may only contain
237f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     * elements of type {@link #TYPE_BUNDLE bundle}.
238f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     * @return the newly created restriction
239f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov     */
240f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov    public static RestrictionEntry createBundleArrayEntry(String key,
241f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov            RestrictionEntry[] restrictionEntries) {
242f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov        return new RestrictionEntry(key, restrictionEntries, true);
243f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov    }
244f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov
245f70c9346d6097be6967d0901830b00b84ae02a87Fyodor Kupolov    /**
24686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Sets the type for this restriction.
24786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param type the type for this restriction.
24886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
24986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public void setType(int type) {
250f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mType = type;
251df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
252df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
253df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
25486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Returns the type for this restriction.
25586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @return the type for this restriction
256df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
25786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public int getType() {
258f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return mType;
25986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
26086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
26186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
26286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Returns the currently selected string value.
26386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @return the currently selected value, which can be null for types that aren't for holding
26486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * single string values.
26586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
26686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public String getSelectedString() {
267f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return mCurrentValue;
268df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
269df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
270df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
27186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Returns the list of currently selected values.
27286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @return the list of current selections, if type is {@link #TYPE_MULTI_SELECT},
27386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     *  null otherwise.
274df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
27586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public String[] getAllSelectedStrings() {
276f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return mCurrentValues;
277df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
278df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
279df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
28086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Returns the current selected state for an entry of type {@link #TYPE_BOOLEAN}.
28186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @return the current selected state of the entry.
282df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
28386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public boolean getSelectedState() {
284f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return Boolean.parseBoolean(mCurrentValue);
285f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    }
286f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani
287f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    /**
288f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     * Returns the value of the entry as an integer when the type is {@link #TYPE_INTEGER}.
289f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     * @return the integer value of the entry.
290f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     */
291f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    public int getIntValue() {
292f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return Integer.parseInt(mCurrentValue);
293f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    }
294f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani
295f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    /**
296f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     * Sets the integer value of the entry when the type is {@link #TYPE_INTEGER}.
297f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     * @param value the integer value to set.
298f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani     */
299f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani    public void setIntValue(int value) {
300f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mCurrentValue = Integer.toString(value);
301df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
302df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
303df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
30486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Sets the string value to use as the selected value for this restriction. This value will
30586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * be persisted by the system for later use by the application.
30686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param selectedString the string value to select.
30786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
30886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public void setSelectedString(String selectedString) {
309f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mCurrentValue = selectedString;
31086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
31186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
31286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
31386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Sets the current selected state for an entry of type {@link #TYPE_BOOLEAN}. This value will
31486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * be persisted by the system for later use by the application.
31586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param state the current selected state
31686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
31786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public void setSelectedState(boolean state) {
318f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mCurrentValue = Boolean.toString(state);
31986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
32086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
32186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
32286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Sets the current list of selected values for an entry of type {@link #TYPE_MULTI_SELECT}.
32386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * These values will be persisted by the system for later use by the application.
32486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param allSelectedStrings the current list of selected values.
32586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
32686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public void setAllSelectedStrings(String[] allSelectedStrings) {
327f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mCurrentValues = allSelectedStrings;
32886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
32986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
33086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
33186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Sets a list of string values that can be selected by the user. If no user-visible entries
33286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * are set by a call to {@link #setChoiceEntries(String[])}, these values will be the ones
33386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * shown to the user. Values will be chosen from this list as the user's selection and the
33486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * selected values can be retrieved by a call to {@link #getAllSelectedStrings()}, or
33586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * {@link #getSelectedString()}, depending on whether it is a multi-select type or choice type.
336d5e946a52c5095c05a4621073f428649ad626430Amith Yamasani     * This method is not relevant for types other than
33786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * {@link #TYPE_CHOICE}, and {@link #TYPE_MULTI_SELECT}.
33886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param choiceValues an array of Strings which will be the selected values for the user's
33986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * selections.
34086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @see #getChoiceValues()
34186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @see #getAllSelectedStrings()
34286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
34386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public void setChoiceValues(String[] choiceValues) {
344f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mChoiceValues = choiceValues;
34586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
34686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
34786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
34886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Sets a list of string values that can be selected by the user, similar to
34986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * {@link #setChoiceValues(String[])}.
35086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param context the application context for retrieving the resources.
35186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param stringArrayResId the resource id for a string array containing the possible values.
35286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @see #setChoiceValues(String[])
35386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
3547b9c912f536925ac6ec43935d6e97506851b33d6Tor Norbye    public void setChoiceValues(Context context, @ArrayRes int stringArrayResId) {
355f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mChoiceValues = context.getResources().getStringArray(stringArrayResId);
35686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
35786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
35886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
359262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     * Returns array of possible restriction entries that this entry may contain.
360262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov     */
361262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    public RestrictionEntry[] getRestrictions() {
362262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        return mRestrictions;
363262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    }
364262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov
365262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov   /**
366262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    * Sets an array of possible restriction entries, that this entry may contain.
367262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    * <p>This method is only relevant for types {@link #TYPE_BUNDLE} and
368262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    * {@link #TYPE_BUNDLE_ARRAY}
369262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    */
370262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    public void setRestrictions(RestrictionEntry[] restrictions) {
371262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        mRestrictions = restrictions;
372262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    }
373262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov
374262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov    /**
37586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Returns the list of possible string values set earlier.
37686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @return the list of possible values.
37786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
37886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public String[] getChoiceValues() {
379f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return mChoiceValues;
38086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
38186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
38286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
38386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Sets a list of strings that will be presented as choices to the user. When the
38486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * user selects one or more of these choices, the corresponding value from the possible values
38586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * are stored as the selected strings. The size of this array must match the size of the array
38686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * set in {@link #setChoiceValues(String[])}. This method is not relevant for types other
387d5e946a52c5095c05a4621073f428649ad626430Amith Yamasani     * than {@link #TYPE_CHOICE}, and {@link #TYPE_MULTI_SELECT}.
38886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param choiceEntries the list of user-visible choices.
38986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @see #setChoiceValues(String[])
39086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
39186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public void setChoiceEntries(String[] choiceEntries) {
392f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mChoiceEntries = choiceEntries;
39386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
39486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
39586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /** Sets a list of strings that will be presented as choices to the user. This is similar to
39686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * {@link #setChoiceEntries(String[])}.
39786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param context the application context, used for retrieving the resources.
39886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param stringArrayResId the resource id of a string array containing the possible entries.
39986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
4007b9c912f536925ac6ec43935d6e97506851b33d6Tor Norbye    public void setChoiceEntries(Context context, @ArrayRes int stringArrayResId) {
401f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mChoiceEntries = context.getResources().getStringArray(stringArrayResId);
40286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
40386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
40486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
40586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Returns the list of strings, set earlier, that will be presented as choices to the user.
40686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @return the list of choices presented to the user.
40786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
40886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public String[] getChoiceEntries() {
409f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return mChoiceEntries;
41086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
41186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
41286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
41386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Returns the provided user-visible description of the entry, if any.
41486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @return the user-visible description, null if none was set earlier.
41586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
41686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public String getDescription() {
417f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return mDescription;
41886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
41986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
42086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
42186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Sets the user-visible description of the entry, as a possible sub-text for the title.
42286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * You can use this to describe the entry in more detail or to display the current state of
42386118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * the restriction.
42486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param description the user-visible description string.
42586118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     */
42686118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public void setDescription(String description) {
427f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mDescription = description;
42886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    }
42986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani
43086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    /**
43186118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * This is the unique key for the restriction entry.
43286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @return the key for the restriction.
433df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
43486118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public String getKey() {
435f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return mKey;
436df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
437df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
438df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
43986118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Returns the user-visible title for the entry, if any.
44086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @return the user-visible title for the entry, null if none was set earlier.
441df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
44286118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public String getTitle() {
443f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        return mTitle;
444df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
445df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
446df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    /**
44786118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * Sets the user-visible title for the entry.
44886118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani     * @param title the user-visible title for the entry.
449df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani     */
45086118baa4fef80c485ba51c6985a6fa082b7310cAmith Yamasani    public void setTitle(String title) {
451f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        this.mTitle = title;
452df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
453df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
454df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    @Override
455df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public boolean equals(Object o) {
456df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        if (o == this) return true;
457df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        if (!(o instanceof RestrictionEntry)) return false;
458df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        final RestrictionEntry other = (RestrictionEntry) o;
4591af7a839393152834a3659514528d8050901a4feFyodor Kupolov        if (mType != other.mType || !mKey.equals(other.mKey)) {
460262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            return false;
461262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        }
462262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        if (mCurrentValues == null && other.mCurrentValues == null
463262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                && mRestrictions == null && other.mRestrictions == null
464262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                && Objects.equals(mCurrentValue, other.mCurrentValue)) {
465262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            return true;
466262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        }
467262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        if (mCurrentValue == null && other.mCurrentValue == null
468262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                && mRestrictions == null && other.mRestrictions == null
469262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                && Arrays.equals(mCurrentValues, other.mCurrentValues)) {
470262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            return true;
471262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        }
472262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        if (mCurrentValue == null && other.mCurrentValue == null
473262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                && mCurrentValue == null && other.mCurrentValue == null
474262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                && Arrays.equals(mRestrictions, other.mRestrictions)) {
475262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            return true;
476262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        }
477262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        return false;
478df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
479df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
480df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    @Override
481df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public int hashCode() {
482df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        int result = 17;
483f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        result = 31 * result + mKey.hashCode();
484f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        if (mCurrentValue != null) {
485f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani            result = 31 * result + mCurrentValue.hashCode();
486f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        } else if (mCurrentValues != null) {
487f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani            for (String value : mCurrentValues) {
488df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani                if (value != null) {
489df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani                    result = 31 * result + value.hashCode();
490df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani                }
491df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            }
492262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        } else if (mRestrictions != null) {
493262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            result = 31 * result + Arrays.hashCode(mRestrictions);
494df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
495df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return result;
496df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
497df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
498df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public RestrictionEntry(Parcel in) {
499f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mType = in.readInt();
500f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mKey = in.readString();
501f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mTitle = in.readString();
502f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mDescription = in.readString();
503262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        mChoiceEntries = in.readStringArray();
504262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        mChoiceValues = in.readStringArray();
505f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        mCurrentValue = in.readString();
506262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        mCurrentValues = in.readStringArray();
507262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        Parcelable[] parcelables = in.readParcelableArray(null);
508262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        if (parcelables != null) {
509262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            mRestrictions = new RestrictionEntry[parcelables.length];
510262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            for (int i = 0; i < parcelables.length; i++) {
511262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                mRestrictions[i] = (RestrictionEntry) parcelables[i];
512262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov            }
513262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        }
514df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
515df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
516df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    @Override
517df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public int describeContents() {
518df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        return 0;
519df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
520df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
521df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    @Override
522df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public void writeToParcel(Parcel dest, int flags) {
523f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        dest.writeInt(mType);
524f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        dest.writeString(mKey);
525f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        dest.writeString(mTitle);
526f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        dest.writeString(mDescription);
527262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        dest.writeStringArray(mChoiceEntries);
528262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        dest.writeStringArray(mChoiceValues);
529f20d640fa2b155a971ddfe0965fc803a73b5e53cAmith Yamasani        dest.writeString(mCurrentValue);
530262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        dest.writeStringArray(mCurrentValues);
531262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        dest.writeParcelableArray(mRestrictions, 0);
532df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
533df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
534df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public static final Creator<RestrictionEntry> CREATOR = new Creator<RestrictionEntry>() {
535df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        public RestrictionEntry createFromParcel(Parcel source) {
536df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return new RestrictionEntry(source);
537df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
538df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
539df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        public RestrictionEntry[] newArray(int size) {
540df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani            return new RestrictionEntry[size];
541df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani        }
542df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    };
543df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani
544df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    @Override
545df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    public String toString() {
546262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov        return "RestrictionEntry{" +
547262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                "mType=" + mType +
548262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                ", mKey='" + mKey + '\'' +
549262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                ", mTitle='" + mTitle + '\'' +
550262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                ", mDescription='" + mDescription + '\'' +
551262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                ", mChoiceEntries=" + Arrays.toString(mChoiceEntries) +
552262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                ", mChoiceValues=" + Arrays.toString(mChoiceValues) +
553262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                ", mCurrentValue='" + mCurrentValue + '\'' +
554262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                ", mCurrentValues=" + Arrays.toString(mCurrentValues) +
555262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                ", mRestrictions=" + Arrays.toString(mRestrictions) +
556262f9952e6e78e00a6d42bab97d73dccfb9607f4Fyodor Kupolov                '}';
557df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani    }
558df2e92a535e19c00edd37318d974dab992ccc2c1Amith Yamasani}
559