Files
app_Settings/src/com/android/settings/search/InlineListPayload.java
Matthew Fritze 458bb887e1 Add default value to inline payloads
If we try to set an inline result when it has not yet been
accessed in settings, nothing is read from Settings.
Thus, include a default value for a fallback.

Manual merge for: ag/2588219/

Change-Id: I3b8eea4f82764852cea642db4455ba57f10a7d37
Fixes: 63955012
Test: robotests
2017-07-25 10:44:15 -07:00

63 lines
1.9 KiB
Java

package com.android.settings.search;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
/**
* Payload for settings which are selected from multiple values. For example, Location can be
* set to multiple degrees of accuracy.
*/
public class InlineListPayload extends InlinePayload {
/**
* Number of selections in the list.
*/
private int mNumOptions;
public InlineListPayload(String key, @PayloadType int payloadType, Intent intent,
boolean isDeviceSupported, int numOptions, int defaultValue) {
super(key, payloadType, intent, isDeviceSupported, defaultValue);
mNumOptions = numOptions;
}
private InlineListPayload(Parcel in) {
super(in);
mNumOptions = in.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeInt(mNumOptions);
}
@Override
protected int standardizeInput(int input) throws IllegalArgumentException {
if (input < 0 || input >= mNumOptions) {
throw new IllegalArgumentException(
"Invalid argument for ListSelect. Expected between 0 and "
+ mNumOptions + " but found: " + input);
}
return input;
}
@Override
@PayloadType public int getType() {
return PayloadType.INLINE_LIST;
}
public static final Parcelable.Creator<InlineListPayload> CREATOR =
new Parcelable.Creator<InlineListPayload>() {
@Override
public InlineListPayload createFromParcel(Parcel in) {
return new InlineListPayload(in);
}
@Override
public InlineListPayload[] newArray(int size) {
return new InlineListPayload[size];
}
};
}