Loading src/com/android/settings/search/CursorToSearchResultConverter.java +3 −0 Original line number Diff line number Diff line Loading @@ -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); Loading src/com/android/settings/search/InlineListPayload.java 0 → 100644 +62 −0 Original line number Diff line number Diff line 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]; } }; } src/com/android/settings/search/InlinePayload.java +57 −14 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -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. */ Loading @@ -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; } Loading @@ -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; } Loading @@ -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. Loading @@ -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; } } No newline at end of file src/com/android/settings/search/InlineSwitchPayload.java +15 −65 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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; } Loading @@ -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 Loading @@ -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; } } src/com/android/settings/search/ResultPayload.java +8 −3 Original line number Diff line number Diff line Loading @@ -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 { /** Loading @@ -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; } /** Loading Loading
src/com/android/settings/search/CursorToSearchResultConverter.java +3 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
src/com/android/settings/search/InlineListPayload.java 0 → 100644 +62 −0 Original line number Diff line number Diff line 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]; } }; }
src/com/android/settings/search/InlinePayload.java +57 −14 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -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. */ Loading @@ -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; } Loading @@ -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; } Loading @@ -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. Loading @@ -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; } } No newline at end of file
src/com/android/settings/search/InlineSwitchPayload.java +15 −65 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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; } Loading @@ -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 Loading @@ -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; } }
src/com/android/settings/search/ResultPayload.java +8 −3 Original line number Diff line number Diff line Loading @@ -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 { /** Loading @@ -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; } /** Loading