Files
app_Settings/src/com/android/settings/search/InlineListPayload.java
Matthew Fritze 73056522b3 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.

Change-Id: I8a593d9ff3308b2d0cd5bc65658d160abf55b07e
Fixes: 63955012
Test: robotests
2017-07-25 14:37:05 -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];
}
};
}