Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.content; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 22 | /** |
| 23 | * Applications can expose restrictions for a restricted user on a |
| 24 | * multiuser device. The administrator can configure these restrictions that will then be |
| 25 | * applied to the restricted user. Each RestrictionsEntry is one configurable restriction. |
| 26 | * <p/> |
| 27 | * Any application that chooses to expose such restrictions does so by implementing a |
Amith Yamasani | 1eab5f2 | 2013-03-20 23:54:07 -0700 | [diff] [blame] | 28 | * receiver that handles the {@link Intent#ACTION_GET_RESTRICTION_ENTRIES} action. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 29 | * The receiver then returns a result bundle that contains an entry called "restrictions", whose |
| 30 | * value is an ArrayList<RestrictionsEntry>. |
| 31 | */ |
| 32 | public class RestrictionEntry implements Parcelable { |
| 33 | |
| 34 | /** |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 35 | * A type of restriction. Use this type for information that needs to be transferred across |
| 36 | * but shouldn't be presented to the user in the UI. Stores a single String value. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 37 | */ |
| 38 | public static final int TYPE_NULL = 0; |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 39 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 40 | /** |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 41 | * A type of restriction. Use this for storing a boolean value, typically presented as |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 42 | * a checkbox in the UI. |
| 43 | */ |
| 44 | public static final int TYPE_BOOLEAN = 1; |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 45 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 46 | /** |
| 47 | * A type of restriction. Use this for storing a string value, typically presented as |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 48 | * a single-select list. Call {@link #setChoiceEntries(String[])} and |
| 49 | * {@link #setChoiceValues(String[])} to set the localized list entries to present to the user |
| 50 | * and the corresponding values, respectively. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 51 | */ |
| 52 | public static final int TYPE_CHOICE = 2; |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 53 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 54 | /** |
| 55 | * A type of restriction. Use this for storing a string value, typically presented as |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 56 | * a single-select list. Call {@link #setChoiceEntries(String[])} and |
| 57 | * {@link #setChoiceValues(String[])} to set the localized list entries to present to the user |
| 58 | * and the corresponding values, respectively. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 59 | * The presentation could imply that values in lower array indices are included when a |
| 60 | * particular value is chosen. |
Amith Yamasani | d5e946a | 2013-04-24 21:37:36 -0700 | [diff] [blame] | 61 | * @hide |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 62 | */ |
| 63 | public static final int TYPE_CHOICE_LEVEL = 3; |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 64 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 65 | /** |
| 66 | * A type of restriction. Use this for presenting a multi-select list where more than one |
| 67 | * entry can be selected, such as for choosing specific titles to white-list. |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 68 | * Call {@link #setChoiceEntries(String[])} and |
| 69 | * {@link #setChoiceValues(String[])} to set the localized list entries to present to the user |
| 70 | * and the corresponding values, respectively. |
| 71 | * Use {@link #getAllSelectedStrings()} and {@link #setAllSelectedStrings(String[])} to |
| 72 | * manipulate the selections. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 73 | */ |
| 74 | public static final int TYPE_MULTI_SELECT = 4; |
| 75 | |
| 76 | /** The type of restriction. */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 77 | private int type; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 78 | |
| 79 | /** The unique key that identifies the restriction. */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 80 | private String key; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 81 | |
| 82 | /** The user-visible title of the restriction. */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 83 | private String title; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 84 | |
| 85 | /** The user-visible secondary description of the restriction. */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 86 | private String description; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 87 | |
| 88 | /** The user-visible set of choices used for single-select and multi-select lists. */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 89 | private String [] choices; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 90 | |
| 91 | /** The values corresponding to the user-visible choices. The value(s) of this entry will |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 92 | * one or more of these, returned by {@link #getAllSelectedStrings()} and |
| 93 | * {@link #getSelectedString()}. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 94 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 95 | private String [] values; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 96 | |
| 97 | /* The chosen value, whose content depends on the type of the restriction. */ |
| 98 | private String currentValue; |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 99 | |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 100 | /* List of selected choices in the multi-select case. */ |
| 101 | private String[] currentValues; |
| 102 | |
| 103 | /** |
Amith Yamasani | d5e946a | 2013-04-24 21:37:36 -0700 | [diff] [blame] | 104 | * Constructor for {@link #TYPE_CHOICE} type. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 105 | * @param key the unique key for this restriction |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 106 | * @param selectedString the current value |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 107 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 108 | public RestrictionEntry(String key, String selectedString) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 109 | this.key = key; |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 110 | this.type = TYPE_CHOICE; |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 111 | this.currentValue = selectedString; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Constructor for {@link #TYPE_BOOLEAN} type. |
| 116 | * @param key the unique key for this restriction |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 117 | * @param selectedState whether this restriction is selected or not |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 118 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 119 | public RestrictionEntry(String key, boolean selectedState) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 120 | this.key = key; |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 121 | this.type = TYPE_BOOLEAN; |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 122 | setSelectedState(selectedState); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Constructor for {@link #TYPE_MULTI_SELECT} type. |
| 127 | * @param key the unique key for this restriction |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 128 | * @param selectedStrings the list of values that are currently selected |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 129 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 130 | public RestrictionEntry(String key, String[] selectedStrings) { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 131 | this.key = key; |
Amith Yamasani | 0d8750d | 2013-05-01 15:25:28 -0700 | [diff] [blame] | 132 | this.type = TYPE_MULTI_SELECT; |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 133 | this.currentValues = selectedStrings; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /** |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 137 | * Sets the type for this restriction. |
| 138 | * @param type the type for this restriction. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 139 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 140 | public void setType(int type) { |
| 141 | this.type = type; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Returns the type for this restriction. |
| 146 | * @return the type for this restriction |
| 147 | */ |
| 148 | public int getType() { |
| 149 | return type; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Returns the currently selected string value. |
| 154 | * @return the currently selected value, which can be null for types that aren't for holding |
| 155 | * single string values. |
| 156 | */ |
| 157 | public String getSelectedString() { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 158 | return currentValue; |
| 159 | } |
| 160 | |
| 161 | /** |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 162 | * Returns the list of currently selected values. |
| 163 | * @return the list of current selections, if type is {@link #TYPE_MULTI_SELECT}, |
| 164 | * null otherwise. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 165 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 166 | public String[] getAllSelectedStrings() { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 167 | return currentValues; |
| 168 | } |
| 169 | |
| 170 | /** |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 171 | * Returns the current selected state for an entry of type {@link #TYPE_BOOLEAN}. |
| 172 | * @return the current selected state of the entry. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 173 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 174 | public boolean getSelectedState() { |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 175 | return Boolean.parseBoolean(currentValue); |
| 176 | } |
| 177 | |
| 178 | /** |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 179 | * Sets the string value to use as the selected value for this restriction. This value will |
| 180 | * be persisted by the system for later use by the application. |
| 181 | * @param selectedString the string value to select. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 182 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 183 | public void setSelectedString(String selectedString) { |
| 184 | currentValue = selectedString; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /** |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 188 | * Sets the current selected state for an entry of type {@link #TYPE_BOOLEAN}. This value will |
| 189 | * be persisted by the system for later use by the application. |
| 190 | * @param state the current selected state |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 191 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 192 | public void setSelectedState(boolean state) { |
| 193 | currentValue = Boolean.toString(state); |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 197 | * Sets the current list of selected values for an entry of type {@link #TYPE_MULTI_SELECT}. |
| 198 | * These values will be persisted by the system for later use by the application. |
| 199 | * @param allSelectedStrings the current list of selected values. |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 200 | */ |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 201 | public void setAllSelectedStrings(String[] allSelectedStrings) { |
| 202 | currentValues = allSelectedStrings; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Sets a list of string values that can be selected by the user. If no user-visible entries |
| 207 | * are set by a call to {@link #setChoiceEntries(String[])}, these values will be the ones |
| 208 | * shown to the user. Values will be chosen from this list as the user's selection and the |
| 209 | * selected values can be retrieved by a call to {@link #getAllSelectedStrings()}, or |
| 210 | * {@link #getSelectedString()}, depending on whether it is a multi-select type or choice type. |
Amith Yamasani | d5e946a | 2013-04-24 21:37:36 -0700 | [diff] [blame] | 211 | * This method is not relevant for types other than |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 212 | * {@link #TYPE_CHOICE}, and {@link #TYPE_MULTI_SELECT}. |
| 213 | * @param choiceValues an array of Strings which will be the selected values for the user's |
| 214 | * selections. |
| 215 | * @see #getChoiceValues() |
| 216 | * @see #getAllSelectedStrings() |
| 217 | */ |
| 218 | public void setChoiceValues(String[] choiceValues) { |
| 219 | values = choiceValues; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Sets a list of string values that can be selected by the user, similar to |
| 224 | * {@link #setChoiceValues(String[])}. |
| 225 | * @param context the application context for retrieving the resources. |
| 226 | * @param stringArrayResId the resource id for a string array containing the possible values. |
| 227 | * @see #setChoiceValues(String[]) |
| 228 | */ |
| 229 | public void setChoiceValues(Context context, int stringArrayResId) { |
| 230 | values = context.getResources().getStringArray(stringArrayResId); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Returns the list of possible string values set earlier. |
| 235 | * @return the list of possible values. |
| 236 | */ |
| 237 | public String[] getChoiceValues() { |
| 238 | return values; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Sets a list of strings that will be presented as choices to the user. When the |
| 243 | * user selects one or more of these choices, the corresponding value from the possible values |
| 244 | * are stored as the selected strings. The size of this array must match the size of the array |
| 245 | * set in {@link #setChoiceValues(String[])}. This method is not relevant for types other |
Amith Yamasani | d5e946a | 2013-04-24 21:37:36 -0700 | [diff] [blame] | 246 | * than {@link #TYPE_CHOICE}, and {@link #TYPE_MULTI_SELECT}. |
Amith Yamasani | 86118ba | 2013-03-28 14:33:16 -0700 | [diff] [blame] | 247 | * @param choiceEntries the list of user-visible choices. |
| 248 | * @see #setChoiceValues(String[]) |
| 249 | */ |
| 250 | public void setChoiceEntries(String[] choiceEntries) { |
| 251 | choices = choiceEntries; |
| 252 | } |
| 253 | |
| 254 | /** Sets a list of strings that will be presented as choices to the user. This is similar to |
| 255 | * {@link #setChoiceEntries(String[])}. |
| 256 | * @param context the application context, used for retrieving the resources. |
| 257 | * @param stringArrayResId the resource id of a string array containing the possible entries. |
| 258 | */ |
| 259 | public void setChoiceEntries(Context context, int stringArrayResId) { |
| 260 | choices = context.getResources().getStringArray(stringArrayResId); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Returns the list of strings, set earlier, that will be presented as choices to the user. |
| 265 | * @return the list of choices presented to the user. |
| 266 | */ |
| 267 | public String[] getChoiceEntries() { |
| 268 | return choices; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Returns the provided user-visible description of the entry, if any. |
| 273 | * @return the user-visible description, null if none was set earlier. |
| 274 | */ |
| 275 | public String getDescription() { |
| 276 | return description; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Sets the user-visible description of the entry, as a possible sub-text for the title. |
| 281 | * You can use this to describe the entry in more detail or to display the current state of |
| 282 | * the restriction. |
| 283 | * @param description the user-visible description string. |
| 284 | */ |
| 285 | public void setDescription(String description) { |
| 286 | this.description = description; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * This is the unique key for the restriction entry. |
| 291 | * @return the key for the restriction. |
| 292 | */ |
| 293 | public String getKey() { |
| 294 | return key; |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Returns the user-visible title for the entry, if any. |
| 299 | * @return the user-visible title for the entry, null if none was set earlier. |
| 300 | */ |
| 301 | public String getTitle() { |
| 302 | return title; |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Sets the user-visible title for the entry. |
| 307 | * @param title the user-visible title for the entry. |
| 308 | */ |
| 309 | public void setTitle(String title) { |
| 310 | this.title = title; |
Amith Yamasani | df2e92a | 2013-03-01 17:04:38 -0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | private boolean equalArrays(String[] one, String[] other) { |
| 314 | if (one.length != other.length) return false; |
| 315 | for (int i = 0; i < one.length; i++) { |
| 316 | if (!one[i].equals(other[i])) return false; |
| 317 | } |
| 318 | return true; |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public boolean equals(Object o) { |
| 323 | if (o == this) return true; |
| 324 | if (!(o instanceof RestrictionEntry)) return false; |
| 325 | final RestrictionEntry other = (RestrictionEntry) o; |
| 326 | // Make sure that either currentValue matches or currentValues matches. |
| 327 | return type == other.type && key.equals(other.key) |
| 328 | && |
| 329 | ((currentValues == null && other.currentValues == null |
| 330 | && currentValue != null && currentValue.equals(other.currentValue)) |
| 331 | || |
| 332 | (currentValue == null && other.currentValue == null |
| 333 | && currentValues != null && equalArrays(currentValues, other.currentValues))); |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public int hashCode() { |
| 338 | int result = 17; |
| 339 | result = 31 * result + key.hashCode(); |
| 340 | if (currentValue != null) { |
| 341 | result = 31 * result + currentValue.hashCode(); |
| 342 | } else if (currentValues != null) { |
| 343 | for (String value : currentValues) { |
| 344 | if (value != null) { |
| 345 | result = 31 * result + value.hashCode(); |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | return result; |
| 350 | } |
| 351 | |
| 352 | private String[] readArray(Parcel in) { |
| 353 | int count = in.readInt(); |
| 354 | String[] values = new String[count]; |
| 355 | for (int i = 0; i < count; i++) { |
| 356 | values[i] = in.readString(); |
| 357 | } |
| 358 | return values; |
| 359 | } |
| 360 | |
| 361 | public RestrictionEntry(Parcel in) { |
| 362 | type = in.readInt(); |
| 363 | key = in.readString(); |
| 364 | title = in.readString(); |
| 365 | description = in.readString(); |
| 366 | choices = readArray(in); |
| 367 | values = readArray(in); |
| 368 | currentValue = in.readString(); |
| 369 | currentValues = readArray(in); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public int describeContents() { |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | private void writeArray(Parcel dest, String[] values) { |
| 378 | if (values == null) { |
| 379 | dest.writeInt(0); |
| 380 | } else { |
| 381 | dest.writeInt(values.length); |
| 382 | for (int i = 0; i < values.length; i++) { |
| 383 | dest.writeString(values[i]); |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public void writeToParcel(Parcel dest, int flags) { |
| 390 | dest.writeInt(type); |
| 391 | dest.writeString(key); |
| 392 | dest.writeString(title); |
| 393 | dest.writeString(description); |
| 394 | writeArray(dest, choices); |
| 395 | writeArray(dest, values); |
| 396 | dest.writeString(currentValue); |
| 397 | writeArray(dest, currentValues); |
| 398 | } |
| 399 | |
| 400 | public static final Creator<RestrictionEntry> CREATOR = new Creator<RestrictionEntry>() { |
| 401 | public RestrictionEntry createFromParcel(Parcel source) { |
| 402 | return new RestrictionEntry(source); |
| 403 | } |
| 404 | |
| 405 | public RestrictionEntry[] newArray(int size) { |
| 406 | return new RestrictionEntry[size]; |
| 407 | } |
| 408 | }; |
| 409 | |
| 410 | @Override |
| 411 | public String toString() { |
| 412 | return "RestrictionsEntry {type=" + type + ", key=" + key + ", value=" + currentValue + "}"; |
| 413 | } |
| 414 | } |