1 package com.android.settings.search; 2 3 import android.content.Intent; 4 import android.os.Parcel; 5 import android.os.Parcelable; 6 7 /** 8 * Payload for settings which are selected from multiple values. For example, Location can be 9 * set to multiple degrees of accuracy. 10 */ 11 public class InlineListPayload extends InlinePayload { 12 13 /** 14 * Number of selections in the list. 15 */ 16 private int mNumOptions; 17 18 public InlineListPayload(String key, @PayloadType int payloadType, Intent intent, 19 boolean isDeviceSupported, int numOptions, int defaultValue) { 20 super(key, payloadType, intent, isDeviceSupported, defaultValue); 21 mNumOptions = numOptions; 22 } 23 24 private InlineListPayload(Parcel in) { 25 super(in); 26 mNumOptions = in.readInt(); 27 } 28 29 @Override 30 public void writeToParcel(Parcel dest, int flags) { 31 super.writeToParcel(dest, flags); 32 dest.writeInt(mNumOptions); 33 } 34 35 @Override 36 protected int standardizeInput(int input) throws IllegalArgumentException { 37 if (input < 0 || input >= mNumOptions) { 38 throw new IllegalArgumentException( 39 "Invalid argument for ListSelect. Expected between 0 and " 40 + mNumOptions + " but found: " + input); 41 } 42 return input; 43 } 44 45 @Override 46 @PayloadType public int getType() { 47 return PayloadType.INLINE_LIST; 48 } 49 50 public static final Parcelable.Creator<InlineListPayload> CREATOR = 51 new Parcelable.Creator<InlineListPayload>() { 52 @Override 53 public InlineListPayload createFromParcel(Parcel in) { 54 return new InlineListPayload(in); 55 } 56 57 @Override 58 public InlineListPayload[] newArray(int size) { 59 return new InlineListPayload[size]; 60 } 61 }; 62 } 63