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
This commit is contained in:
@@ -87,6 +87,7 @@ public class AmbientDisplayAlwaysOnPreferenceController extends
|
|||||||
mContext.getString(R.string.ambient_display_screen_title));
|
mContext.getString(R.string.ambient_display_screen_title));
|
||||||
|
|
||||||
return new InlineSwitchPayload(Settings.Secure.DOZE_ALWAYS_ON,
|
return new InlineSwitchPayload(Settings.Secure.DOZE_ALWAYS_ON,
|
||||||
ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
|
ResultPayload.SettingsSource.SECURE, ON /* onValue */, intent, isAvailable(),
|
||||||
|
ON /* defaultValue */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,9 @@ public class AutoBrightnessPreferenceController extends AbstractPreferenceContro
|
|||||||
|
|
||||||
private final String mAutoBrightnessKey;
|
private final String mAutoBrightnessKey;
|
||||||
|
|
||||||
|
private final String SYSTEM_KEY = SCREEN_BRIGHTNESS_MODE;
|
||||||
|
private final int DEFAULT_VALUE = SCREEN_BRIGHTNESS_MODE_MANUAL;
|
||||||
|
|
||||||
public AutoBrightnessPreferenceController(Context context, String key) {
|
public AutoBrightnessPreferenceController(Context context, String key) {
|
||||||
super(context);
|
super(context);
|
||||||
mAutoBrightnessKey = key;
|
mAutoBrightnessKey = key;
|
||||||
@@ -56,15 +59,15 @@ public class AutoBrightnessPreferenceController extends AbstractPreferenceContro
|
|||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
int brightnessMode = Settings.System.getInt(mContext.getContentResolver(),
|
int brightnessMode = Settings.System.getInt(mContext.getContentResolver(),
|
||||||
SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
|
SYSTEM_KEY, DEFAULT_VALUE);
|
||||||
((SwitchPreference) preference).setChecked(brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL);
|
((SwitchPreference) preference).setChecked(brightnessMode != DEFAULT_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
boolean auto = (Boolean) newValue;
|
boolean auto = (Boolean) newValue;
|
||||||
Settings.System.putInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS_MODE,
|
Settings.System.putInt(mContext.getContentResolver(), SYSTEM_KEY,
|
||||||
auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL);
|
auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : DEFAULT_VALUE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +77,8 @@ public class AutoBrightnessPreferenceController extends AbstractPreferenceContro
|
|||||||
DisplaySettings.class.getName(), mAutoBrightnessKey,
|
DisplaySettings.class.getName(), mAutoBrightnessKey,
|
||||||
mContext.getString(R.string.display_settings));
|
mContext.getString(R.string.display_settings));
|
||||||
|
|
||||||
return new InlineSwitchPayload(SCREEN_BRIGHTNESS_MODE,
|
return new InlineSwitchPayload(SYSTEM_KEY,
|
||||||
ResultPayload.SettingsSource.SYSTEM, SCREEN_BRIGHTNESS_MODE_AUTOMATIC, intent,
|
ResultPayload.SettingsSource.SYSTEM, SCREEN_BRIGHTNESS_MODE_AUTOMATIC, intent,
|
||||||
isAvailable());
|
isAvailable(), DEFAULT_VALUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -32,6 +32,8 @@ import com.android.settings.search.ResultPayload;
|
|||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED;
|
||||||
|
|
||||||
public class AssistGesturePreferenceController extends GesturePreferenceController
|
public class AssistGesturePreferenceController extends GesturePreferenceController
|
||||||
implements OnResume {
|
implements OnResume {
|
||||||
|
|
||||||
@@ -41,6 +43,8 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll
|
|||||||
private static final String PREF_KEY_VIDEO = "gesture_assist_video";
|
private static final String PREF_KEY_VIDEO = "gesture_assist_video";
|
||||||
private final String mAssistGesturePrefKey;
|
private final String mAssistGesturePrefKey;
|
||||||
|
|
||||||
|
private final String SECURE_KEY = ASSIST_GESTURE_ENABLED;
|
||||||
|
|
||||||
private final AssistGestureFeatureProvider mFeatureProvider;
|
private final AssistGestureFeatureProvider mFeatureProvider;
|
||||||
private boolean mWasAvailable;
|
private boolean mWasAvailable;
|
||||||
|
|
||||||
@@ -142,8 +146,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean enabled = (boolean) newValue;
|
final boolean enabled = (boolean) newValue;
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF);
|
||||||
Settings.Secure.ASSIST_GESTURE_ENABLED, enabled ? ON : OFF);
|
|
||||||
updateState(preference);
|
updateState(preference);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -161,7 +164,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll
|
|||||||
@Override
|
@Override
|
||||||
protected boolean isSwitchPrefEnabled() {
|
protected boolean isSwitchPrefEnabled() {
|
||||||
final int assistGestureEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
final int assistGestureEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
|
SECURE_KEY, ON);
|
||||||
return assistGestureEnabled != 0;
|
return assistGestureEnabled != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +174,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll
|
|||||||
AssistGestureSettings.class.getName(), mAssistGesturePrefKey,
|
AssistGestureSettings.class.getName(), mAssistGesturePrefKey,
|
||||||
mContext.getString(R.string.display_settings));
|
mContext.getString(R.string.display_settings));
|
||||||
|
|
||||||
return new InlineSwitchPayload(Settings.Secure.ASSIST_GESTURE_ENABLED,
|
return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE,
|
||||||
ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
|
ON /* onValue */, intent, isAvailable(), ON /* defaultValue */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,14 +22,14 @@ import android.content.SharedPreferences;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.DisplaySettings;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
|
||||||
import com.android.settings.search.DatabaseIndexingUtils;
|
import com.android.settings.search.DatabaseIndexingUtils;
|
||||||
import com.android.settings.search.InlineSwitchPayload;
|
import com.android.settings.search.InlineSwitchPayload;
|
||||||
import com.android.settings.search.ResultPayload;
|
import com.android.settings.search.ResultPayload;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
|
||||||
|
|
||||||
public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
|
public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
|
||||||
|
|
||||||
private final int ON = 0;
|
private final int ON = 0;
|
||||||
@@ -38,6 +38,8 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
|
|||||||
private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video";
|
private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video";
|
||||||
private final String mDoubleTapPowerKey;
|
private final String mDoubleTapPowerKey;
|
||||||
|
|
||||||
|
private final String SECURE_KEY = CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
|
||||||
|
|
||||||
public DoubleTapPowerPreferenceController(Context context, Lifecycle lifecycle, String key) {
|
public DoubleTapPowerPreferenceController(Context context, Lifecycle lifecycle, String key) {
|
||||||
super(context, lifecycle);
|
super(context, lifecycle);
|
||||||
mDoubleTapPowerKey = key;
|
mDoubleTapPowerKey = key;
|
||||||
@@ -71,15 +73,14 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
boolean enabled = (boolean) newValue;
|
boolean enabled = (boolean) newValue;
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF);
|
||||||
Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, enabled ? ON : OFF);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSwitchPrefEnabled() {
|
protected boolean isSwitchPrefEnabled() {
|
||||||
final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
|
SECURE_KEY, ON);
|
||||||
return cameraDisabled == 0;
|
return cameraDisabled == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
|
|||||||
DoubleTapPowerSettings.class.getName(), mDoubleTapPowerKey,
|
DoubleTapPowerSettings.class.getName(), mDoubleTapPowerKey,
|
||||||
mContext.getString(R.string.display_settings));
|
mContext.getString(R.string.display_settings));
|
||||||
|
|
||||||
return new InlineSwitchPayload(Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
|
return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE,
|
||||||
ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
|
ON /* onValue */, intent, isAvailable(), ON /* defaultValue */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,12 +25,13 @@ import android.support.v7.preference.Preference;
|
|||||||
|
|
||||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
|
||||||
import com.android.settings.search.DatabaseIndexingUtils;
|
import com.android.settings.search.DatabaseIndexingUtils;
|
||||||
import com.android.settings.search.InlineSwitchPayload;
|
import com.android.settings.search.InlineSwitchPayload;
|
||||||
import com.android.settings.search.ResultPayload;
|
import com.android.settings.search.ResultPayload;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP;
|
||||||
|
|
||||||
public class DoubleTapScreenPreferenceController extends GesturePreferenceController {
|
public class DoubleTapScreenPreferenceController extends GesturePreferenceController {
|
||||||
|
|
||||||
private final int ON = 1;
|
private final int ON = 1;
|
||||||
@@ -39,6 +40,8 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
|
|||||||
private static final String PREF_KEY_VIDEO = "gesture_double_tap_screen_video";
|
private static final String PREF_KEY_VIDEO = "gesture_double_tap_screen_video";
|
||||||
private final String mDoubleTapScreenPrefKey;
|
private final String mDoubleTapScreenPrefKey;
|
||||||
|
|
||||||
|
private final String SECURE_KEY = DOZE_PULSE_ON_DOUBLE_TAP;
|
||||||
|
|
||||||
private final AmbientDisplayConfiguration mAmbientConfig;
|
private final AmbientDisplayConfiguration mAmbientConfig;
|
||||||
@UserIdInt
|
@UserIdInt
|
||||||
private final int mUserId;
|
private final int mUserId;
|
||||||
@@ -70,8 +73,7 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean enabled = (boolean) newValue;
|
final boolean enabled = (boolean) newValue;
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF);
|
||||||
Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? ON : OFF);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
|
|||||||
DoubleTapScreenSettings.class.getName(), mDoubleTapScreenPrefKey,
|
DoubleTapScreenSettings.class.getName(), mDoubleTapScreenPrefKey,
|
||||||
mContext.getString(R.string.display_settings));
|
mContext.getString(R.string.display_settings));
|
||||||
|
|
||||||
return new InlineSwitchPayload(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP,
|
return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE,
|
||||||
ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
|
ON /* onValue */, intent, isAvailable(), ON /* defaultValue */);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -30,6 +30,8 @@ import com.android.settings.search.InlineSwitchPayload;
|
|||||||
import com.android.settings.search.ResultPayload;
|
import com.android.settings.search.ResultPayload;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.DOZE_PULSE_ON_PICK_UP;
|
||||||
|
|
||||||
public class PickupGesturePreferenceController extends GesturePreferenceController {
|
public class PickupGesturePreferenceController extends GesturePreferenceController {
|
||||||
|
|
||||||
private final int ON = 1;
|
private final int ON = 1;
|
||||||
@@ -38,6 +40,8 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
|
|||||||
private static final String PREF_KEY_VIDEO = "gesture_pick_up_video";
|
private static final String PREF_KEY_VIDEO = "gesture_pick_up_video";
|
||||||
private final String mPickUpPrefKey;
|
private final String mPickUpPrefKey;
|
||||||
|
|
||||||
|
private final String SECURE_KEY = DOZE_PULSE_ON_PICK_UP;
|
||||||
|
|
||||||
private final AmbientDisplayConfiguration mAmbientConfig;
|
private final AmbientDisplayConfiguration mAmbientConfig;
|
||||||
@UserIdInt
|
@UserIdInt
|
||||||
private final int mUserId;
|
private final int mUserId;
|
||||||
@@ -80,7 +84,7 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
|
|||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean enabled = (boolean) newValue;
|
final boolean enabled = (boolean) newValue;
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.DOZE_PULSE_ON_PICK_UP, enabled ? ON : OFF);
|
SECURE_KEY, enabled ? ON : OFF);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +99,7 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
|
|||||||
PickupGestureSettings.class.getName(), mPickUpPrefKey,
|
PickupGestureSettings.class.getName(), mPickUpPrefKey,
|
||||||
mContext.getString(R.string.display_settings));
|
mContext.getString(R.string.display_settings));
|
||||||
|
|
||||||
return new InlineSwitchPayload(Settings.Secure.DOZE_PULSE_ON_PICK_UP,
|
return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE,
|
||||||
ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
|
ON /* onValue */, intent, isAvailable(), ON /* defaultValue */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,8 @@ import com.android.settings.search.InlineSwitchPayload;
|
|||||||
import com.android.settings.search.ResultPayload;
|
import com.android.settings.search.ResultPayload;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
|
||||||
|
import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED;
|
||||||
|
|
||||||
public class SwipeToNotificationPreferenceController extends GesturePreferenceController {
|
public class SwipeToNotificationPreferenceController extends GesturePreferenceController {
|
||||||
|
|
||||||
private final int ON = 1;
|
private final int ON = 1;
|
||||||
@@ -37,6 +39,8 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
|
|||||||
private static final String PREF_KEY_VIDEO = "gesture_swipe_down_fingerprint_video";
|
private static final String PREF_KEY_VIDEO = "gesture_swipe_down_fingerprint_video";
|
||||||
private final String mSwipeDownFingerPrefKey;
|
private final String mSwipeDownFingerPrefKey;
|
||||||
|
|
||||||
|
private final String SECURE_KEY = SYSTEM_NAVIGATION_KEYS_ENABLED;
|
||||||
|
|
||||||
public SwipeToNotificationPreferenceController(Context context, Lifecycle lifecycle,
|
public SwipeToNotificationPreferenceController(Context context, Lifecycle lifecycle,
|
||||||
String key) {
|
String key) {
|
||||||
super(context, lifecycle);
|
super(context, lifecycle);
|
||||||
@@ -71,16 +75,14 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
|
||||||
Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, (boolean) newValue ? ON : OFF);
|
(boolean) newValue ? ON : OFF);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isSwitchPrefEnabled() {
|
protected boolean isSwitchPrefEnabled() {
|
||||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
return Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY, OFF) == ON;
|
||||||
Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0)
|
|
||||||
== 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -89,7 +91,7 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
|
|||||||
SwipeToNotificationSettings.class.getName(), mSwipeDownFingerPrefKey,
|
SwipeToNotificationSettings.class.getName(), mSwipeDownFingerPrefKey,
|
||||||
mContext.getString(R.string.display_settings));
|
mContext.getString(R.string.display_settings));
|
||||||
|
|
||||||
return new InlineSwitchPayload(Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED,
|
return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE,
|
||||||
ResultPayload.SettingsSource.SECURE, ON, intent, isAvailable());
|
ON /* onValue */, intent, isAvailable(), ON /* defaultValue */);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -133,7 +133,6 @@ public class LocationPreferenceController extends AbstractPreferenceController
|
|||||||
|
|
||||||
return new InlineListPayload(Secure.LOCATION_MODE,
|
return new InlineListPayload(Secure.LOCATION_MODE,
|
||||||
ResultPayload.SettingsSource.SECURE, intent, isAvailable(),
|
ResultPayload.SettingsSource.SECURE, intent, isAvailable(),
|
||||||
Secure.LOCATION_MODE_HIGH_ACCURACY + 1);
|
Secure.LOCATION_MODE_HIGH_ACCURACY + 1, Secure.LOCATION_MODE_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,8 @@ public class InlineListPayload extends InlinePayload {
|
|||||||
private int mNumOptions;
|
private int mNumOptions;
|
||||||
|
|
||||||
public InlineListPayload(String key, @PayloadType int payloadType, Intent intent,
|
public InlineListPayload(String key, @PayloadType int payloadType, Intent intent,
|
||||||
boolean isDeviceSupported, int numOptions) {
|
boolean isDeviceSupported, int numOptions, int defaultValue) {
|
||||||
super(key, payloadType, intent, isDeviceSupported);
|
super(key, payloadType, intent, isDeviceSupported, defaultValue);
|
||||||
mNumOptions = numOptions;
|
mNumOptions = numOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,6 +48,11 @@ public abstract class InlinePayload extends ResultPayload {
|
|||||||
*/
|
*/
|
||||||
final boolean mIsDeviceSupported;
|
final boolean mIsDeviceSupported;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default value for the setting.
|
||||||
|
*/
|
||||||
|
final int mDefaultvalue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key uniquely identifies the stored setting.
|
* @param key uniquely identifies the stored setting.
|
||||||
* @param source of the setting. Used to determine where to get and set the setting.
|
* @param source of the setting. Used to determine where to get and set the setting.
|
||||||
@@ -55,18 +60,20 @@ public abstract class InlinePayload extends ResultPayload {
|
|||||||
* @param isDeviceSupported is true when the setting is valid for the given device.
|
* @param isDeviceSupported is true when the setting is valid for the given device.
|
||||||
*/
|
*/
|
||||||
public InlinePayload(String key, @SettingsSource int source, Intent intent,
|
public InlinePayload(String key, @SettingsSource int source, Intent intent,
|
||||||
boolean isDeviceSupported) {
|
boolean isDeviceSupported, int defaultValue) {
|
||||||
super(intent);
|
super(intent);
|
||||||
mSettingKey = key;
|
mSettingKey = key;
|
||||||
mSettingSource = source;
|
mSettingSource = source;
|
||||||
mIsDeviceSupported = isDeviceSupported;
|
mIsDeviceSupported = isDeviceSupported;
|
||||||
|
mDefaultvalue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
InlinePayload(Parcel parcel) {
|
InlinePayload(Parcel parcel) {
|
||||||
super((Intent) parcel.readParcelable(Intent.class.getClassLoader()));
|
super(parcel.readParcelable(Intent.class.getClassLoader()));
|
||||||
mSettingKey = parcel.readString();
|
mSettingKey = parcel.readString();
|
||||||
mSettingSource = parcel.readInt();
|
mSettingSource = parcel.readInt();
|
||||||
mIsDeviceSupported = parcel.readInt() == TRUE;
|
mIsDeviceSupported = parcel.readInt() == TRUE;
|
||||||
|
mDefaultvalue = parcel.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -75,6 +82,7 @@ public abstract class InlinePayload extends ResultPayload {
|
|||||||
dest.writeString(mSettingKey);
|
dest.writeString(mSettingKey);
|
||||||
dest.writeInt(mSettingSource);
|
dest.writeInt(mSettingSource);
|
||||||
dest.writeInt(mIsDeviceSupported ? TRUE : FALSE);
|
dest.writeInt(mIsDeviceSupported ? TRUE : FALSE);
|
||||||
|
dest.writeInt(mDefaultvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -108,24 +116,19 @@ public abstract class InlinePayload extends ResultPayload {
|
|||||||
switch(mSettingSource) {
|
switch(mSettingSource) {
|
||||||
case SettingsSource.SECURE:
|
case SettingsSource.SECURE:
|
||||||
settingsValue = Settings.Secure.getInt(context.getContentResolver(),
|
settingsValue = Settings.Secure.getInt(context.getContentResolver(),
|
||||||
mSettingKey, -1);
|
mSettingKey, mDefaultvalue);
|
||||||
break;
|
break;
|
||||||
case SettingsSource.SYSTEM:
|
case SettingsSource.SYSTEM:
|
||||||
settingsValue = Settings.System.getInt(context.getContentResolver(),
|
settingsValue = Settings.System.getInt(context.getContentResolver(),
|
||||||
mSettingKey, -1);
|
mSettingKey, mDefaultvalue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SettingsSource.GLOBAL:
|
case SettingsSource.GLOBAL:
|
||||||
settingsValue = Settings.Global.getInt(context.getContentResolver(),
|
settingsValue = Settings.Global.getInt(context.getContentResolver(),
|
||||||
mSettingKey, -1);
|
mSettingKey, mDefaultvalue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settingsValue == -1) {
|
|
||||||
throw new IllegalStateException("Unable to find setting from uri: "
|
|
||||||
+ mSettingKey.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return standardizeInput(settingsValue);
|
return standardizeInput(settingsValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,8 +45,8 @@ public class InlineSwitchPayload extends InlinePayload {
|
|||||||
* @param isDeviceSupported is true when the setting is valid for the given device.
|
* @param isDeviceSupported is true when the setting is valid for the given device.
|
||||||
*/
|
*/
|
||||||
public InlineSwitchPayload(String key, @SettingsSource int source,
|
public InlineSwitchPayload(String key, @SettingsSource int source,
|
||||||
int onValue, Intent intent, boolean isDeviceSupported) {
|
int onValue, Intent intent, boolean isDeviceSupported, int defaultValue) {
|
||||||
super(key, source, intent, isDeviceSupported);
|
super(key, source, intent, isDeviceSupported, defaultValue);
|
||||||
// If on is stored as TRUE then the switch is standard.
|
// If on is stored as TRUE then the switch is standard.
|
||||||
mIsStandard = onValue == TRUE;
|
mIsStandard = onValue == TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -220,7 +220,7 @@ public class CursorToSearchResultConverterTest {
|
|||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.putExtra(intentKey, intentVal);
|
intent.putExtra(intentKey, intentVal);
|
||||||
final InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, 1 /* onValue */,
|
final InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, 1 /* onValue */,
|
||||||
intent, true /* isDeviceSupported */);
|
intent, true /* isDeviceSupported */, 0 /* defautValue */);
|
||||||
|
|
||||||
cursor.addRow(new Object[]{
|
cursor.addRow(new Object[]{
|
||||||
KEY.hashCode(), // Doc ID
|
KEY.hashCode(), // Doc ID
|
||||||
|
@@ -114,7 +114,7 @@ public class DatabaseRowTest {
|
|||||||
public void testRowWithInlinePayload_genericPayloadNotAdded() {
|
public void testRowWithInlinePayload_genericPayloadNotAdded() {
|
||||||
final String URI = "test uri";
|
final String URI = "test uri";
|
||||||
final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0 /* mSettingSource */,
|
final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0 /* mSettingSource */,
|
||||||
1 /* onValue */, null /* intent */, true /* isDeviceSupported */);
|
1 /* onValue */, null /* intent */, true /* isDeviceSupported */, 1 /* default */);
|
||||||
mBuilder.setPayload(payload);
|
mBuilder.setPayload(payload);
|
||||||
final DatabaseRow row = generateRow();
|
final DatabaseRow row = generateRow();
|
||||||
final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
|
final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
|
||||||
@@ -133,7 +133,7 @@ public class DatabaseRowTest {
|
|||||||
intent.setComponent(component);
|
intent.setComponent(component);
|
||||||
|
|
||||||
final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0 /* mSettingSource */,
|
final InlineSwitchPayload payload = new InlineSwitchPayload(URI, 0 /* mSettingSource */,
|
||||||
1 /* onValue */, intent, true /* isDeviceSupported */);
|
1 /* onValue */, intent, true /* isDeviceSupported */, 1 /* default */);
|
||||||
mBuilder.setPayload(payload);
|
mBuilder.setPayload(payload);
|
||||||
final DatabaseRow row = generateRow();
|
final DatabaseRow row = generateRow();
|
||||||
final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
|
final InlineSwitchPayload unmarshalledPayload = ResultPayloadUtils
|
||||||
|
@@ -37,7 +37,7 @@ public class InlineListPayloadTest {
|
|||||||
intent.putExtra(intentKey, intentVal);
|
intent.putExtra(intentKey, intentVal);
|
||||||
|
|
||||||
InlineListPayload payload = new InlineListPayload(uri, source,
|
InlineListPayload payload = new InlineListPayload(uri, source,
|
||||||
intent, true /* isAvailable */, 1);
|
intent, true /* isAvailable */, 1 /* numOptions */, 1 /* default */);
|
||||||
|
|
||||||
final Intent retainedIntent = payload.getIntent();
|
final Intent retainedIntent = payload.getIntent();
|
||||||
assertThat(payload.mSettingKey).isEqualTo(uri);
|
assertThat(payload.mSettingKey).isEqualTo(uri);
|
||||||
@@ -80,7 +80,7 @@ public class InlineListPayloadTest {
|
|||||||
public void testInputStandardization_inputDoesntChange() {
|
public void testInputStandardization_inputDoesntChange() {
|
||||||
InlineListPayload payload = new InlineListPayload(DUMMY_SETTING,
|
InlineListPayload payload = new InlineListPayload(DUMMY_SETTING,
|
||||||
ResultPayload.SettingsSource.SYSTEM, null /* intent */, true /* isDeviceSupport */,
|
ResultPayload.SettingsSource.SYSTEM, null /* intent */, true /* isDeviceSupport */,
|
||||||
3 /* numOptions */);
|
3 /* numOptions */, 0 /* default */);
|
||||||
int input = 2;
|
int input = 2;
|
||||||
|
|
||||||
assertThat(payload.standardizeInput(input)).isEqualTo(input);
|
assertThat(payload.standardizeInput(input)).isEqualTo(input);
|
||||||
@@ -90,7 +90,7 @@ public class InlineListPayloadTest {
|
|||||||
public void testSetSystem_negativeValue_throwsError() {
|
public void testSetSystem_negativeValue_throwsError() {
|
||||||
InlineListPayload payload = new InlineListPayload(DUMMY_SETTING,
|
InlineListPayload payload = new InlineListPayload(DUMMY_SETTING,
|
||||||
ResultPayload.SettingsSource.SYSTEM, null /* intent */, true /* isDeviceSupport */,
|
ResultPayload.SettingsSource.SYSTEM, null /* intent */, true /* isDeviceSupport */,
|
||||||
3 /* numOptions */);
|
3 /* numOptions */, 0 /* default */);
|
||||||
|
|
||||||
payload.setValue(mContext, -1);
|
payload.setValue(mContext, -1);
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ public class InlineListPayloadTest {
|
|||||||
int maxOptions = 4;
|
int maxOptions = 4;
|
||||||
InlineListPayload payload = new InlineListPayload(DUMMY_SETTING,
|
InlineListPayload payload = new InlineListPayload(DUMMY_SETTING,
|
||||||
ResultPayload.SettingsSource.SYSTEM, null /* intent */, true /* isDeviceSupport */,
|
ResultPayload.SettingsSource.SYSTEM, null /* intent */, true /* isDeviceSupport */,
|
||||||
maxOptions /* numOptions */);
|
maxOptions /* numOptions */, 0 /* default */);
|
||||||
|
|
||||||
payload.setValue(mContext, maxOptions + 1);
|
payload.setValue(mContext, maxOptions + 1);
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ public class InlinePayloadTest {
|
|||||||
|
|
||||||
public ConcreteInlinePayload(String key, @SettingsSource int source, Intent intent,
|
public ConcreteInlinePayload(String key, @SettingsSource int source, Intent intent,
|
||||||
boolean isDeviceSupported) {
|
boolean isDeviceSupported) {
|
||||||
super(key, source, intent, isDeviceSupported);
|
super(key, source, intent, isDeviceSupported, 0 /* defaultValue */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -61,7 +61,8 @@ public class InlineSwitchPayloadTest {
|
|||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.putExtra(intentKey, intentVal);
|
intent.putExtra(intentKey, intentVal);
|
||||||
|
|
||||||
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, 1, intent, true);
|
InlineSwitchPayload payload = new InlineSwitchPayload(uri, source, 1, intent, true,
|
||||||
|
1 /* default */);
|
||||||
final Intent retainedIntent = payload.getIntent();
|
final Intent retainedIntent = payload.getIntent();
|
||||||
assertThat(payload.mSettingKey).isEqualTo(uri);
|
assertThat(payload.mSettingKey).isEqualTo(uri);
|
||||||
assertThat(payload.getType()).isEqualTo(type);
|
assertThat(payload.getType()).isEqualTo(type);
|
||||||
@@ -86,6 +87,7 @@ public class InlineSwitchPayloadTest {
|
|||||||
parcel.writeInt(source);
|
parcel.writeInt(source);
|
||||||
parcel.writeInt(InlineSwitchPayload.TRUE);
|
parcel.writeInt(InlineSwitchPayload.TRUE);
|
||||||
parcel.writeInt(InlineSwitchPayload.TRUE);
|
parcel.writeInt(InlineSwitchPayload.TRUE);
|
||||||
|
parcel.writeInt(InlineSwitchPayload.TRUE);
|
||||||
parcel.setDataPosition(0);
|
parcel.setDataPosition(0);
|
||||||
|
|
||||||
InlineSwitchPayload payload = InlineSwitchPayload.CREATOR.createFromParcel(parcel);
|
InlineSwitchPayload payload = InlineSwitchPayload.CREATOR.createFromParcel(parcel);
|
||||||
@@ -103,7 +105,7 @@ public class InlineSwitchPayloadTest {
|
|||||||
public void testGetSystem_flippedSetting_returnsFlippedValue() {
|
public void testGetSystem_flippedSetting_returnsFlippedValue() {
|
||||||
// Stores 1s as 0s, and vis versa
|
// Stores 1s as 0s, and vis versa
|
||||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
||||||
FLIPPED_ON, null /* intent */, true);
|
FLIPPED_ON, null /* intent */, true, 1 /* default */);
|
||||||
int currentValue = 1;
|
int currentValue = 1;
|
||||||
Settings.System.putInt(mContext.getContentResolver(), DUMMY_SETTING, currentValue);
|
Settings.System.putInt(mContext.getContentResolver(), DUMMY_SETTING, currentValue);
|
||||||
|
|
||||||
@@ -116,7 +118,7 @@ public class InlineSwitchPayloadTest {
|
|||||||
public void testSetSystem_flippedSetting_updatesToFlippedValue() {
|
public void testSetSystem_flippedSetting_updatesToFlippedValue() {
|
||||||
// Stores 1s as 0s, and vis versa
|
// Stores 1s as 0s, and vis versa
|
||||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
||||||
FLIPPED_ON, null /* intent */, true);
|
FLIPPED_ON, null /* intent */, true, 1 /* default */);
|
||||||
int newValue = 1;
|
int newValue = 1;
|
||||||
ContentResolver resolver = mContext.getContentResolver();
|
ContentResolver resolver = mContext.getContentResolver();
|
||||||
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, newValue);
|
Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, newValue);
|
||||||
@@ -130,7 +132,7 @@ public class InlineSwitchPayloadTest {
|
|||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testSetSystem_negativeValue_ThrowsError() {
|
public void testSetSystem_negativeValue_ThrowsError() {
|
||||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
||||||
STANDARD_ON, null /* intent */, true);
|
STANDARD_ON, null /* intent */, true, 1 /* default */);
|
||||||
|
|
||||||
payload.setValue(mContext, -1);
|
payload.setValue(mContext, -1);
|
||||||
}
|
}
|
||||||
@@ -138,7 +140,7 @@ public class InlineSwitchPayloadTest {
|
|||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testSetSystem_highValue_ThrowsError() {
|
public void testSetSystem_highValue_ThrowsError() {
|
||||||
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
InlineSwitchPayload payload = new InlineSwitchPayload(DUMMY_SETTING, SettingsSource.SYSTEM,
|
||||||
STANDARD_ON, null /* intent */, true);
|
STANDARD_ON, null /* intent */, true, 1 /* default */);
|
||||||
|
|
||||||
payload.setValue(mContext, 2);
|
payload.setValue(mContext, 2);
|
||||||
}
|
}
|
||||||
|
@@ -107,7 +107,8 @@ public class InlineSwitchViewHolderTest {
|
|||||||
.setSummary(SUMMARY)
|
.setSummary(SUMMARY)
|
||||||
.setRank(1)
|
.setRank(1)
|
||||||
.setPayload(new InlineSwitchPayload("" /* uri */, 0 /* mSettingSource */,
|
.setPayload(new InlineSwitchPayload("" /* uri */, 0 /* mSettingSource */,
|
||||||
1 /* onValue */, null /* intent */, true /* isDeviceSupported */))
|
1 /* onValue */, null /* intent */, true /* isDeviceSupported */,
|
||||||
|
1 /* default */))
|
||||||
.addBreadcrumbs(new ArrayList<>())
|
.addBreadcrumbs(new ArrayList<>())
|
||||||
.setIcon(mIcon)
|
.setIcon(mIcon)
|
||||||
.setPayload(mPayload)
|
.setPayload(mPayload)
|
||||||
|
Reference in New Issue
Block a user