Merge "Add list-select as an inline result" into oc-dr1-dev am: e455c8f377
am: 46483a1a29
Change-Id: Ia2f55440571504c66b67276990e9fde19a1709fa
This commit is contained in:
@@ -113,6 +113,9 @@ public class CursorToSearchResultConverter {
|
||||
case ResultPayload.PayloadType.INLINE_SWITCH:
|
||||
return ResultPayloadUtils.unmarshall(marshalledPayload,
|
||||
InlineSwitchPayload.CREATOR);
|
||||
case ResultPayload.PayloadType.INLINE_LIST:
|
||||
return ResultPayloadUtils.unmarshall(marshalledPayload,
|
||||
InlineListPayload.CREATOR);
|
||||
}
|
||||
} catch (BadParcelableException e) {
|
||||
Log.w(TAG, "Error creating parcelable: " + e);
|
||||
|
62
src/com/android/settings/search/InlineListPayload.java
Normal file
62
src/com/android/settings/search/InlineListPayload.java
Normal file
@@ -0,0 +1,62 @@
|
||||
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) {
|
||||
super(key, payloadType, intent, isDeviceSupported);
|
||||
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];
|
||||
}
|
||||
};
|
||||
}
|
@@ -21,6 +21,7 @@ import android.content.Intent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.provider.Settings;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
/**
|
||||
@@ -37,11 +38,6 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
@VisibleForTesting
|
||||
final String mSettingKey;
|
||||
|
||||
/**
|
||||
* The UI type for the inline result.
|
||||
*/
|
||||
@PayloadType final int mInlineType;
|
||||
|
||||
/**
|
||||
* Defines where the Setting is stored.
|
||||
*/
|
||||
@@ -54,16 +50,14 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
|
||||
/**
|
||||
* @param key uniquely identifies the stored setting.
|
||||
* @param payloadType of the setting being stored.
|
||||
* @param source of the setting. Used to determine where to get and set the setting.
|
||||
* @param intent to the setting page.
|
||||
* @param isDeviceSupported is true when the setting is valid for the given device.
|
||||
*/
|
||||
public InlinePayload(String key, @PayloadType int payloadType, @SettingsSource int source,
|
||||
Intent intent, boolean isDeviceSupported) {
|
||||
public InlinePayload(String key, @SettingsSource int source, Intent intent,
|
||||
boolean isDeviceSupported) {
|
||||
super(intent);
|
||||
mSettingKey = key;
|
||||
mInlineType = payloadType;
|
||||
mSettingSource = source;
|
||||
mIsDeviceSupported = isDeviceSupported;
|
||||
}
|
||||
@@ -71,7 +65,6 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
InlinePayload(Parcel parcel) {
|
||||
super((Intent) parcel.readParcelable(Intent.class.getClassLoader()));
|
||||
mSettingKey = parcel.readString();
|
||||
mInlineType = parcel.readInt();
|
||||
mSettingSource = parcel.readInt();
|
||||
mIsDeviceSupported = parcel.readInt() == TRUE;
|
||||
}
|
||||
@@ -80,11 +73,13 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(mSettingKey);
|
||||
dest.writeInt(mInlineType);
|
||||
dest.writeInt(mSettingSource);
|
||||
dest.writeInt(mIsDeviceSupported ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PayloadType public abstract int getType();
|
||||
|
||||
/**
|
||||
* @returns the status of the underlying setting. See {@link ResultPayload.Availability} for
|
||||
* possible values.
|
||||
@@ -96,16 +91,64 @@ public abstract class InlinePayload extends ResultPayload {
|
||||
return Availability.DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the input is valid for the given setting.
|
||||
*
|
||||
* @param input The number to be get or set for the setting.
|
||||
* @return {@param input} mapped to the public-facing API for settings.
|
||||
* @throws IllegalArgumentException when the input is not valid for the given inline type.
|
||||
*/
|
||||
protected abstract int standardizeInput(int input) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* @returns the current value of the setting.
|
||||
*/
|
||||
public abstract int getValue(Context context);
|
||||
public int getValue(Context context) {
|
||||
int settingsValue = -1;
|
||||
switch(mSettingSource) {
|
||||
case SettingsSource.SECURE:
|
||||
settingsValue = Settings.Secure.getInt(context.getContentResolver(),
|
||||
mSettingKey, -1);
|
||||
break;
|
||||
case SettingsSource.SYSTEM:
|
||||
settingsValue = Settings.System.getInt(context.getContentResolver(),
|
||||
mSettingKey, -1);
|
||||
break;
|
||||
|
||||
case SettingsSource.GLOBAL:
|
||||
settingsValue = Settings.Global.getInt(context.getContentResolver(),
|
||||
mSettingKey, -1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (settingsValue == -1) {
|
||||
throw new IllegalStateException("Unable to find setting from uri: "
|
||||
+ mSettingKey.toString());
|
||||
}
|
||||
|
||||
return standardizeInput(settingsValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to set the setting value.
|
||||
*
|
||||
* @param newValue is the requested new value for the setting.
|
||||
* @param newValue is the requested value for the setting.
|
||||
* @returns true when the setting was changed, and false otherwise.
|
||||
*/
|
||||
public abstract boolean setValue(Context context, int newValue);
|
||||
public boolean setValue(Context context, int newValue) {
|
||||
newValue = standardizeInput(newValue);
|
||||
|
||||
switch(mSettingSource) {
|
||||
case SettingsSource.GLOBAL:
|
||||
return Settings.Global.putInt(context.getContentResolver(), mSettingKey, newValue);
|
||||
case SettingsSource.SECURE:
|
||||
return Settings.Secure.putInt(context.getContentResolver(), mSettingKey, newValue);
|
||||
case SettingsSource.SYSTEM:
|
||||
return Settings.System.putInt(context.getContentResolver(), mSettingKey, newValue);
|
||||
case SettingsSource.UNKNOWN:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -17,17 +17,18 @@
|
||||
|
||||
package com.android.settings.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.Settings;
|
||||
|
||||
/**
|
||||
* Payload for inline Switch results. Mappings from integer to boolean.
|
||||
*/
|
||||
public class InlineSwitchPayload extends InlinePayload {
|
||||
|
||||
private static final int ON = 1;
|
||||
private static final int OFF = 0;
|
||||
|
||||
/**
|
||||
* Provides a mapping for how switches are stored.
|
||||
* If mIsStandard is true, then (0 == false) and (1 == true)
|
||||
@@ -45,7 +46,7 @@ public class InlineSwitchPayload extends InlinePayload {
|
||||
*/
|
||||
public InlineSwitchPayload(String key, @SettingsSource int source,
|
||||
int onValue, Intent intent, boolean isDeviceSupported) {
|
||||
super(key, PayloadType.INLINE_SWITCH, source, intent, isDeviceSupported);
|
||||
super(key, source, intent, isDeviceSupported);
|
||||
// If on is stored as TRUE then the switch is standard.
|
||||
mIsStandard = onValue == TRUE;
|
||||
}
|
||||
@@ -56,13 +57,20 @@ public class InlineSwitchPayload extends InlinePayload {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return mInlineType;
|
||||
@PayloadType public int getType() {
|
||||
return PayloadType.INLINE_SWITCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
protected int standardizeInput(int value) {
|
||||
if (value != OFF && value != ON) {
|
||||
throw new IllegalArgumentException("Invalid input for InlineSwitch. Expected: "
|
||||
+ ON + " or " + OFF
|
||||
+ " but found: " + value);
|
||||
}
|
||||
return mIsStandard
|
||||
? value
|
||||
: 1 - value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,65 +92,7 @@ public class InlineSwitchPayload extends InlinePayload {
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int getValue(Context context) {
|
||||
int settingsValue = -1;
|
||||
switch(mSettingSource) {
|
||||
case SettingsSource.SECURE:
|
||||
settingsValue = Settings.Secure.getInt(context.getContentResolver(),
|
||||
mSettingKey, -1);
|
||||
break;
|
||||
case SettingsSource.SYSTEM:
|
||||
settingsValue = Settings.System.getInt(context.getContentResolver(),
|
||||
mSettingKey, -1);
|
||||
break;
|
||||
|
||||
case SettingsSource.GLOBAL:
|
||||
settingsValue = Settings.Global.getInt(context.getContentResolver(),
|
||||
mSettingKey, -1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (settingsValue == -1) {
|
||||
throw new IllegalStateException("Unable to find setting from uri: "
|
||||
+ mSettingKey.toString());
|
||||
}
|
||||
|
||||
settingsValue = standardizeInput(settingsValue);
|
||||
|
||||
return settingsValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setValue(Context context, int newValue) {
|
||||
if (newValue != 0 && newValue != 1) {
|
||||
throw new IllegalArgumentException("newValue should be 0 for off and 1 for on."
|
||||
+ "The passed value was: " + newValue);
|
||||
}
|
||||
|
||||
newValue = standardizeInput(newValue);
|
||||
|
||||
switch(mSettingSource) {
|
||||
case SettingsSource.GLOBAL:
|
||||
return Settings.Global.putInt(context.getContentResolver(), mSettingKey, newValue);
|
||||
case SettingsSource.SECURE:
|
||||
return Settings.Secure.putInt(context.getContentResolver(), mSettingKey, newValue);
|
||||
case SettingsSource.SYSTEM:
|
||||
return Settings.System.putInt(context.getContentResolver(), mSettingKey, newValue);
|
||||
case SettingsSource.UNKNOWN:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStandard() {
|
||||
return mIsStandard;
|
||||
}
|
||||
|
||||
private int standardizeInput(int value) {
|
||||
return mIsStandard
|
||||
? value
|
||||
: 1 - value;
|
||||
}
|
||||
}
|
||||
|
@@ -32,8 +32,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
public class ResultPayload implements Parcelable {
|
||||
protected final Intent mIntent;
|
||||
|
||||
@IntDef({PayloadType.INLINE_SLIDER, PayloadType.INLINE_SWITCH,
|
||||
PayloadType.INTENT, PayloadType.SAVED_QUERY})
|
||||
@IntDef({PayloadType.INTENT, PayloadType.INLINE_SLIDER, PayloadType.INLINE_SWITCH,
|
||||
PayloadType.INLINE_LIST, PayloadType.SAVED_QUERY})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface PayloadType {
|
||||
/**
|
||||
@@ -51,10 +51,15 @@ public class ResultPayload implements Parcelable {
|
||||
*/
|
||||
int INLINE_SWITCH = 2;
|
||||
|
||||
/**
|
||||
* Result is an inline list-select, with an undefined UI.
|
||||
*/
|
||||
int INLINE_LIST = 3;
|
||||
|
||||
/**
|
||||
* Result is a recently saved query.
|
||||
*/
|
||||
int SAVED_QUERY = 3;
|
||||
int SAVED_QUERY = 4;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -110,6 +110,10 @@ public class SearchResultsAdapter extends RecyclerView.Adapter<SearchViewHolder>
|
||||
// InlineSwitchViewHolder.
|
||||
view = inflater.inflate(R.layout.search_intent_item, parent, false);
|
||||
return new IntentSearchViewHolder(view);
|
||||
case ResultPayload.PayloadType.INLINE_LIST:
|
||||
// TODO (b/62807132) build a inline-list view holder & layout.
|
||||
view = inflater.inflate(R.layout.search_intent_item, parent, false);
|
||||
return new IntentSearchViewHolder(view);
|
||||
case ResultPayload.PayloadType.SAVED_QUERY:
|
||||
view = inflater.inflate(R.layout.search_saved_query_item, parent, false);
|
||||
return new SavedQueryViewHolder(view);
|
||||
|
Reference in New Issue
Block a user