GesturesSettingPreferenceController to Toggle

Convert GesturesSettingPreferenceController to
TogglePreferenceController,
All of its children need follow the change,
add setter and robotest for them:
AssistGestureSettingsPreferenceController
DoubleTapPowerPreferenceController
DoubleTapScreenPreferenceController
DoubleTwistPreferenceController
PickupGesturePreferenceController
SwipeToNotificationPreferenceController

Change-Id: I792b2d370eea828bf345fb2b1cc3eac260eb66f4
Fixes: 74913806
Fixes: 67998110
Fixes: 67998098
Fixes: 67998048
Fixes: 67998069
Fixes: 67997452
Test: make RunSettingsRoboTests
This commit is contained in:
HJ ChangLiao
2018-04-02 17:06:55 +08:00
parent 9914ef7635
commit 22f53c0274
40 changed files with 320 additions and 429 deletions

View File

@@ -20,6 +20,7 @@ import android.annotation.UserIdInt;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.UserHandle;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.annotation.VisibleForTesting;
@@ -29,7 +30,6 @@ import com.android.settings.R;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.InlineSwitchPayload;
import com.android.settings.search.ResultPayload;
import com.android.settingslib.core.lifecycle.Lifecycle;
import static android.provider.Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP;
@@ -43,18 +43,21 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
private final String SECURE_KEY = DOZE_PULSE_ON_DOUBLE_TAP;
private final AmbientDisplayConfiguration mAmbientConfig;
private AmbientDisplayConfiguration mAmbientConfig;
@UserIdInt
private final int mUserId;
public DoubleTapScreenPreferenceController(Context context, Lifecycle lifecycle,
AmbientDisplayConfiguration config, @UserIdInt int userId, String key) {
super(context, lifecycle);
mAmbientConfig = config;
mUserId = userId;
public DoubleTapScreenPreferenceController(Context context, String key) {
super(context, key);
mUserId = UserHandle.myUserId();
mDoubleTapScreenPrefKey = key;
}
public DoubleTapScreenPreferenceController setConfig(AmbientDisplayConfiguration config) {
mAmbientConfig = config;
return this;
}
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
return isSuggestionComplete(new AmbientDisplayConfiguration(context), prefs);
}
@@ -67,20 +70,17 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
}
@Override
public boolean isAvailable() {
return mAmbientConfig.pulseOnDoubleTapAvailable();
public int getAvailabilityStatus() {
if (mAmbientConfig == null) {
mAmbientConfig = new AmbientDisplayConfiguration(mContext);
}
return mAmbientConfig.pulseOnDoubleTapAvailable() ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
public String getPreferenceKey() {
return mDoubleTapScreenPrefKey;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enabled = (boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF);
return true;
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
isChecked ? ON : OFF);
}
@Override
@@ -89,11 +89,12 @@ public class DoubleTapScreenPreferenceController extends GesturePreferenceContro
}
@Override
protected boolean isSwitchPrefEnabled() {
public boolean isChecked() {
return mAmbientConfig.pulseOnDoubleTapEnabled(mUserId);
}
@Override
//TODO (b/69808376): Remove result payload
public ResultPayload getResultPayload() {
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
DoubleTapScreenSettings.class.getName(), mDoubleTapScreenPrefKey,