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
Merged-In: 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 85c34077d3
commit 3c4c3fc5c7
40 changed files with 320 additions and 429 deletions

View File

@@ -35,12 +35,14 @@
<Preference
android:key="ambient_display_double_tap"
android:title="@string/ambient_display_title"
android:fragment="com.android.settings.gestures.DoubleTapScreenSettings" />
android:fragment="com.android.settings.gestures.DoubleTapScreenSettings"
settings:controller="com.android.settings.gestures.DoubleTapScreenPreferenceController" />
<Preference
android:key="ambient_display_pick_up"
android:title="@string/ambient_display_pickup_title"
android:fragment="com.android.settings.gestures.PickupGestureSettings" />
android:fragment="com.android.settings.gestures.PickupGestureSettings"
settings:controller="com.android.settings.gestures.PickupGesturePreferenceController" />
</PreferenceCategory>

View File

@@ -29,6 +29,7 @@
<SwitchPreference
android:key="gesture_assist"
android:title="@string/assist_gesture_title"
app:keywords="@string/keywords_assist_gesture_launch" />
app:keywords="@string/keywords_assist_gesture_launch"
app:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" />
</PreferenceScreen>

View File

@@ -46,7 +46,8 @@
<Preference
android:key="gesture_swipe_down_fingerprint_notifications"
android:title="@string/fingerprint_swipe_for_notifications_title"
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings" />
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings"
settings:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController" />
<com.android.settingslib.RestrictedPreference
android:key="zen_mode_notifications"

View File

@@ -30,6 +30,7 @@
android:key="gesture_double_tap_power"
android:title="@string/double_tap_power_for_camera_title"
android:summary="@string/double_tap_power_for_camera_summary"
app:keywords="@string/keywords_gesture" />
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController" />
</PreferenceScreen>

View File

@@ -30,6 +30,7 @@
android:key="gesture_double_tap_screen"
android:title="@string/ambient_display_title"
android:summary="@string/ambient_display_summary"
app:keywords="@string/keywords_gesture" />
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.DoubleTapScreenPreferenceController" />
</PreferenceScreen>

View File

@@ -30,6 +30,7 @@
android:key="gesture_double_twist"
android:title="@string/double_twist_for_camera_mode_title"
android:summary="@string/double_twist_for_camera_mode_summary"
app:keywords="@string/keywords_gesture" />
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.DoubleTwistPreferenceController" />
</PreferenceScreen>

View File

@@ -17,38 +17,45 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="gesture_settings_screen"
android:title="@string/gesture_preference_title">
<Preference
android:key="gesture_assist_input_summary"
android:title="@string/assist_gesture_title"
android:fragment="com.android.settings.gestures.AssistGestureSettings" />
android:fragment="com.android.settings.gestures.AssistGestureSettings"
settings:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" />
<Preference
android:key="gesture_swipe_down_fingerprint_input_summary"
android:title="@string/fingerprint_swipe_for_notifications_title"
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings" />
android:fragment="com.android.settings.gestures.SwipeToNotificationSettings"
settings:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController" />
<Preference
android:key="gesture_double_tap_power_input_summary"
android:title="@string/double_tap_power_for_camera_title"
android:fragment="com.android.settings.gestures.DoubleTapPowerSettings" />
android:fragment="com.android.settings.gestures.DoubleTapPowerSettings"
settings:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController" />
<Preference
android:key="gesture_double_twist_input_summary"
android:title="@string/double_twist_for_camera_mode_title"
android:fragment="com.android.settings.gestures.DoubleTwistGestureSettings" />
android:fragment="com.android.settings.gestures.DoubleTwistGestureSettings"
settings:controller="com.android.settings.gestures.DoubleTwistPreferenceController" />
<Preference
android:key="gesture_double_tap_screen_input_summary"
android:title="@string/ambient_display_title"
android:fragment="com.android.settings.gestures.DoubleTapScreenSettings" />
android:fragment="com.android.settings.gestures.DoubleTapScreenSettings"
settings:controller="com.android.settings.gestures.DoubleTapScreenPreferenceController" />
<Preference
android:key="gesture_pick_up_input_summary"
android:title="@string/ambient_display_pickup_title"
android:fragment="com.android.settings.gestures.PickupGestureSettings" />
android:fragment="com.android.settings.gestures.PickupGestureSettings"
settings:controller="com.android.settings.gestures.PickupGesturePreferenceController" />
<Preference
android:key="gesture_prevent_ringing_summary"

View File

@@ -17,6 +17,7 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="manage_assist_screen"
android:title="@string/assist_and_voice_input_title">
@@ -29,7 +30,8 @@
<Preference
android:key="gesture_assist_application"
android:title="@string/assist_gesture_title"
android:fragment="com.android.settings.gestures.AssistGestureSettings"/>
android:fragment="com.android.settings.gestures.AssistGestureSettings"
settings:controller="com.android.settings.gestures.AssistGestureSettingsPreferenceController" />
<SwitchPreference
android:key="context"

View File

@@ -30,6 +30,7 @@
android:key="gesture_pick_up"
android:title="@string/ambient_display_pickup_title"
android:summary="@string/ambient_display_pickup_summary"
app:keywords="@string/keywords_gesture" />
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.PickupGesturePreferenceController" />
</PreferenceScreen>

View File

@@ -29,6 +29,7 @@
android:key="gesture_swipe_down_fingerprint"
android:title="@string/fingerprint_swipe_for_notifications_title"
android:summary="@string/fingerprint_swipe_for_notifications_summary"
app:keywords="@string/keywords_gesture"/>
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.SwipeToNotificationPreferenceController" />
</PreferenceScreen>

View File

@@ -60,6 +60,12 @@ public class ManageAssist extends DashboardFragment {
return MetricsEvent.APPLICATIONS_MANAGE_ASSIST;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(AssistGestureSettingsPreferenceController.class).setAssistOnly(true);
}
@Override
public void onResume() {
super.onResume();
@@ -73,8 +79,6 @@ public class ManageAssist extends DashboardFragment {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new DefaultAssistPreferenceController(context, "default_assist",
true /* showSetting */));
controllers.add(new AssistGestureSettingsPreferenceController(context, lifecycle,
KEY_ASSIST, true /* assistOnly */));
controllers.add(new AssistContextPreferenceController(context, lifecycle));
controllers.add(new AssistScreenshotPreferenceController(context, lifecycle));
controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle));

View File

@@ -69,12 +69,16 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference
return true;
}
public void setConfig(AmbientDisplayConfiguration config) {
public AmbientDisplayAlwaysOnPreferenceController setConfig(
AmbientDisplayConfiguration config) {
mConfig = config;
return this;
}
public void setCallback(OnPreferenceChangedCallback callback) {
public AmbientDisplayAlwaysOnPreferenceController setCallback(
OnPreferenceChangedCallback callback) {
mCallback = callback;
return this;
}
public static boolean isAlwaysOnEnabled(AmbientDisplayConfiguration config) {

View File

@@ -56,8 +56,10 @@ public class AmbientDisplayNotificationsPreferenceController extends
*
* @param config AmbientDisplayConfiguration for this controller
*/
public void setConfig(AmbientDisplayConfiguration config) {
public AmbientDisplayNotificationsPreferenceController setConfig(
AmbientDisplayConfiguration config) {
mConfig = config;
return this;
}
@Override

View File

@@ -44,35 +44,18 @@ public class AmbientDisplaySettings extends DashboardFragment {
public static final String KEY_AMBIENT_DISPLAY_ALWAYS_ON = "ambient_display_always_on";
private static final String TAG = "AmbientDisplaySettings";
private static final int MY_USER_ID = UserHandle.myUserId();
private static final String KEY_AMBIENT_DISPLAY_DOUBLE_TAP = "ambient_display_double_tap";
private static final String KEY_AMBIENT_DISPLAY_PICK_UP = "ambient_display_pick_up";
private static final String KEY_AMBIENT_DISPLAY_NOTIFICATION = "ambient_display_notification";
private AmbientDisplayConfiguration mConfig;
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, AmbientDisplayConfiguration config) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle, config,
MY_USER_ID, KEY_AMBIENT_DISPLAY_DOUBLE_TAP));
controllers.add(new PickupGesturePreferenceController(context, lifecycle, config,
MY_USER_ID, KEY_AMBIENT_DISPLAY_PICK_UP));
return controllers;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
final AmbientDisplayAlwaysOnPreferenceController controller = use(
AmbientDisplayAlwaysOnPreferenceController.class);
controller.setConfig(getConfig(context));
controller.setCallback(this::updatePreferenceStates);
final AmbientDisplayNotificationsPreferenceController notificationController = use(
AmbientDisplayNotificationsPreferenceController.class);
notificationController.setConfig(getConfig(context));
use(AmbientDisplayAlwaysOnPreferenceController.class)
.setConfig(getConfig(context))
.setCallback(this::updatePreferenceStates);
use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context));
use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
use(PickupGesturePreferenceController.class).setConfig(getConfig(context));
}
@Override
@@ -85,11 +68,6 @@ public class AmbientDisplaySettings extends DashboardFragment {
return R.xml.ambient_display_settings;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle(), getConfig(context));
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.AMBIENT_DISPLAY_SETTINGS;
@@ -107,13 +85,6 @@ public class AmbientDisplaySettings extends DashboardFragment {
result.add(sir);
return result;
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null,
new AmbientDisplayConfiguration(context));
}
};
private AmbientDisplayConfiguration getConfig(Context context) {

View File

@@ -82,9 +82,11 @@ public class AssistGestureSettings extends DashboardFragment {
@Override
protected boolean isPageSearchEnabled(Context context) {
return new AssistGestureSettingsPreferenceController(context,
null /* lifecycle */, null /* key */, false /* assistOnly */)
.isAvailable();
AssistGestureSettingsPreferenceController controller =
new AssistGestureSettingsPreferenceController(context,
"gesture_assist_input_summary");
controller.setAssistOnly(false);
return controller.isAvailable();
}
};
}

View File

@@ -24,7 +24,6 @@ import android.content.Intent;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.TwoStatePreference;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
@@ -32,11 +31,8 @@ import com.android.settings.overlay.FeatureFactory;
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 com.android.settingslib.core.lifecycle.events.OnResume;
public class AssistGestureSettingsPreferenceController extends GesturePreferenceController
implements OnResume {
public class AssistGestureSettingsPreferenceController extends GesturePreferenceController {
private static final String PREF_KEY_VIDEO = "gesture_assist_video";
@@ -55,30 +51,25 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
@VisibleForTesting
boolean mAssistOnly;
public AssistGestureSettingsPreferenceController(Context context, Lifecycle lifecycle,
String key, boolean assistOnly) {
super(context, lifecycle);
public AssistGestureSettingsPreferenceController(Context context,
String key) {
super(context, key);
mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
mWasAvailable = isAvailable();
mAssistGesturePrefKey = key;
mAssistOnly = assistOnly;
}
@Override
public boolean isAvailable() {
if (mAssistOnly) {
return mFeatureProvider.isSupported(mContext);
} else {
return mFeatureProvider.isSensorAvailable(mContext);
}
public int getAvailabilityStatus() {
final boolean isAvailable = mAssistOnly ? mFeatureProvider.isSupported(mContext)
: mFeatureProvider.isSensorAvailable(mContext);
return isAvailable ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
public void displayPreference(PreferenceScreen screen) {
mScreen = screen;
mPreference = screen.findPreference(getPreferenceKey());
// Call super last or AbstractPreferenceController might remove the preference from the
// screen (if !isAvailable()) before we can save a reference to it.
super.displayPreference(screen);
}
@@ -92,6 +83,11 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
}
}
public AssistGestureSettingsPreferenceController setAssistOnly(boolean assistOnly) {
mAssistOnly = assistOnly;
return this;
}
private void updatePreference() {
if (mPreference == null) {
return;
@@ -117,31 +113,9 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
}
@Override
public void updateState(Preference preference) {
boolean isEnabled = isAssistGestureEnabled() && mFeatureProvider.isSupported(mContext);
if (!mAssistOnly) {
isEnabled = isEnabled || isSilenceGestureEnabled();
}
if (preference != null) {
if (preference instanceof TwoStatePreference) {
((TwoStatePreference) preference).setChecked(isSwitchPrefEnabled());
} else {
preference.setSummary(isEnabled
? R.string.gesture_setting_on
: R.string.gesture_setting_off);
}
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enabled = (boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY_ASSIST,
enabled ? ON : OFF);
updateState(preference);
return true;
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY_ASSIST,
isChecked ? ON : OFF);
}
@Override
@@ -150,17 +124,22 @@ public class AssistGestureSettingsPreferenceController extends GesturePreference
}
@Override
public String getPreferenceKey() {
return mAssistGesturePrefKey;
public CharSequence getSummary() {
boolean isEnabled = isAssistGestureEnabled() && mFeatureProvider.isSupported(mContext);
if (!mAssistOnly) {
isEnabled = isEnabled || isSilenceGestureEnabled();
}
return mContext.getText(
isEnabled ? R.string.gesture_setting_on : R.string.gesture_setting_off);
}
@Override
protected boolean isSwitchPrefEnabled() {
// Does nothing
return true;
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(), SECURE_KEY_ASSIST, OFF) == ON;
}
@Override
//TODO (b/69808376): Remove result payload
public ResultPayload getResultPayload() {
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
AssistGestureSettings.class.getName(), mAssistGesturePrefKey,

View File

@@ -23,13 +23,11 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
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;
public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
@@ -43,8 +41,8 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
private final String SECURE_KEY = CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
public DoubleTapPowerPreferenceController(Context context, Lifecycle lifecycle, String key) {
super(context, lifecycle);
public DoubleTapPowerPreferenceController(Context context, String key) {
super(context, key);
mDoubleTapPowerKey = key;
}
@@ -59,8 +57,8 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
}
@Override
public boolean isAvailable() {
return isGestureAvailable(mContext);
public int getAvailabilityStatus() {
return isGestureAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
@@ -69,25 +67,20 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
}
@Override
public String getPreferenceKey() {
return mDoubleTapPowerKey;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enabled = (boolean) newValue;
Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, enabled ? ON : OFF);
return true;
}
@Override
protected boolean isSwitchPrefEnabled() {
public boolean isChecked() {
final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
SECURE_KEY, ON);
return cameraDisabled == ON;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
isChecked ? ON : OFF);
}
@Override
//TODO (b/69808376): Remove result payload
public ResultPayload getResultPayload() {
final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext,
DoubleTapPowerSettings.class.getName(), mDoubleTapPowerKey,

View File

@@ -26,17 +26,13 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class DoubleTapPowerSettings extends DashboardFragment {
private static final String TAG = "DoubleTapPower";
private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_double_tap_power_suggestion_complete";
@@ -65,19 +61,6 @@ public class DoubleTapPowerSettings extends DashboardFragment {
return R.xml.double_tap_power_settings;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle,
KEY_DOUBLE_TAP_POWER));
return controllers;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -87,11 +70,5 @@ public class DoubleTapPowerSettings extends DashboardFragment {
sir.xmlResId = R.xml.double_tap_power_settings;
return Arrays.asList(sir);
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null /* lifecycle */);
}
};
}

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,

View File

@@ -28,8 +28,6 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.Arrays;
@@ -38,7 +36,6 @@ import java.util.List;
public class DoubleTapScreenSettings extends DashboardFragment {
private static final String TAG = "DoubleTapScreen";
private static final String KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_double_tap_screen_suggestion_complete";
@@ -50,6 +47,9 @@ public class DoubleTapScreenSettings extends DashboardFragment {
.getSuggestionFeatureProvider(context);
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
use(DoubleTapScreenPreferenceController.class)
.setConfig(new AmbientDisplayConfiguration(context));
}
@Override
@@ -72,20 +72,6 @@ public class DoubleTapScreenSettings extends DashboardFragment {
return R.string.help_url_double_tap_screen;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle,
new AmbientDisplayConfiguration(context), UserHandle.myUserId(),
KEY_DOUBLE_TAP_SCREEN));
return controllers;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -95,11 +81,5 @@ public class DoubleTapScreenSettings extends DashboardFragment {
sir.xmlResId = R.xml.double_tap_screen_settings;
return Arrays.asList(sir);
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null /* lifecycle */);
}
};
}

View File

@@ -26,17 +26,13 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class DoubleTwistGestureSettings extends DashboardFragment {
private static final String TAG = "DoubleTwistGesture";
private static final String KEY_DOUBLE_TWIST = "gesture_double_twist";
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_double_twist_suggestion_complete";
@@ -65,18 +61,6 @@ public class DoubleTwistGestureSettings extends DashboardFragment {
return R.xml.double_twist_gesture_settings;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST));
return controllers;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -86,11 +70,6 @@ public class DoubleTwistGestureSettings extends DashboardFragment {
sir.xmlResId = R.xml.double_twist_gesture_settings;
return Arrays.asList(sir);
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, null /* lifecycle */);
}
};
}

View File

@@ -25,12 +25,10 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class DoubleTwistPreferenceController extends GesturePreferenceController {
@@ -41,8 +39,8 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
private final String mDoubleTwistPrefKey;
private final UserManager mUserManager;
public DoubleTwistPreferenceController(Context context, Lifecycle lifecycle, String key) {
super(context, lifecycle);
public DoubleTwistPreferenceController(Context context, String key) {
super(context, key);
mDoubleTwistPrefKey = key;
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
}
@@ -69,8 +67,8 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
}
@Override
public boolean isAvailable() {
return isGestureAvailable(mContext);
public int getAvailabilityStatus() {
return isGestureAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
@@ -84,9 +82,8 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final int enabled = (boolean) newValue ? ON : OFF;
setDoubleTwistPreference(mContext, mUserManager, enabled);
public boolean setChecked(boolean isChecked) {
setDoubleTwistPreference(mContext, mUserManager, isChecked ? ON : OFF);
return true;
}
@@ -97,12 +94,13 @@ public class DoubleTwistPreferenceController extends GesturePreferenceController
final int managedProfileUserId = getManagedProfileId(userManager);
if (managedProfileUserId != UserHandle.USER_NULL) {
Settings.Secure.putIntForUser(context.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled, managedProfileUserId);
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, enabled,
managedProfileUserId);
}
}
@Override
protected boolean isSwitchPrefEnabled() {
public boolean isChecked() {
final int doubleTwistEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, ON);
return doubleTwistEnabled != 0;

View File

@@ -24,18 +24,16 @@ import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.TwoStatePreference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.widget.VideoPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnCreate;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
public abstract class GesturePreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
public abstract class GesturePreferenceController extends TogglePreferenceController
implements Preference.OnPreferenceChangeListener,
LifecycleObserver, OnResume, OnPause, OnCreate, OnSaveInstanceState {
@VisibleForTesting
@@ -45,11 +43,8 @@ public abstract class GesturePreferenceController extends AbstractPreferenceCont
@VisibleForTesting
boolean mVideoPaused;
public GesturePreferenceController(Context context, Lifecycle lifecycle) {
super(context);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
public GesturePreferenceController(Context context, String key) {
super(context, key);
}
@Override
@@ -63,20 +58,21 @@ public abstract class GesturePreferenceController extends AbstractPreferenceCont
@Override
public void updateState(Preference preference) {
super.updateState(preference);
final boolean isEnabled = isSwitchPrefEnabled();
if (preference != null) {
if (preference instanceof TwoStatePreference) {
((TwoStatePreference) preference).setChecked(isEnabled);
} else {
preference.setSummary(isEnabled
? R.string.gesture_setting_on
: R.string.gesture_setting_off);
if (!(preference instanceof TwoStatePreference)) {
preference.setSummary(getSummary());
}
// Different meanings of "Enabled" for the Preference and Controller.
preference.setEnabled(canHandleClicks());
}
}
@Override
public CharSequence getSummary() {
return mContext.getText(
isChecked() ? R.string.gesture_setting_on : R.string.gesture_setting_off);
}
@Override
public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
@@ -106,8 +102,6 @@ public abstract class GesturePreferenceController extends AbstractPreferenceCont
protected abstract String getVideoPrefKey();
protected abstract boolean isSwitchPrefEnabled();
protected boolean canHandleClicks() {
return true;
}

View File

@@ -65,33 +65,32 @@ public class GestureSettings extends DashboardFragment {
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
if (mAmbientDisplayConfig == null) {
mAmbientDisplayConfig = new AmbientDisplayConfiguration(context);
}
return buildPreferenceControllers(context, getLifecycle(), mAmbientDisplayConfig);
return buildPreferenceControllers(context, getLifecycle());
}
static List<AbstractPreferenceController> buildPreferenceControllers(
@NonNull Context context, @Nullable Lifecycle lifecycle,
@NonNull AmbientDisplayConfiguration ambientDisplayConfiguration) {
@NonNull Context context, @Nullable Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new AssistGestureSettingsPreferenceController(context, lifecycle,
KEY_ASSIST, false /* assistOnly */));
controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle,
KEY_SWIPE_DOWN));
controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST));
controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle,
KEY_DOUBLE_TAP_POWER));
controllers.add(new PickupGesturePreferenceController(context, lifecycle,
ambientDisplayConfiguration, UserHandle.myUserId(), KEY_PICK_UP));
controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle,
ambientDisplayConfiguration, UserHandle.myUserId(), KEY_DOUBLE_TAP_SCREEN));
controllers.add(new PreventRingingPreferenceController(
context, lifecycle, UserHandle.myUserId(), KEY_PREVENT_RINGING));
return controllers;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(AssistGestureSettingsPreferenceController.class).setAssistOnly(false);
use(PickupGesturePreferenceController.class).setConfig(getConfig(context));
use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
}
private AmbientDisplayConfiguration getConfig(Context context) {
if (mAmbientDisplayConfig == null) {
mAmbientDisplayConfig = new AmbientDisplayConfiguration(context);
}
return mAmbientDisplayConfig;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -105,8 +104,7 @@ public class GestureSettings extends DashboardFragment {
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null,
new AmbientDisplayConfiguration(context));
return buildPreferenceControllers(context, null);
}
@Override

View File

@@ -19,6 +19,7 @@ package com.android.settings.gestures;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import android.support.annotation.NonNull;
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.R;
@@ -33,6 +34,7 @@ public class GesturesSettingPreferenceController extends BasePreferenceControlle
private List<AbstractPreferenceController> mGestureControllers;
private static final String KEY_GESTURES_SETTINGS = "gesture_settings";
private static final String FAKE_PREF_KEY = "fake_key_only_for_get_available";
public GesturesSettingPreferenceController(Context context) {
super(context, KEY_GESTURES_SETTINGS);
@@ -42,16 +44,38 @@ public class GesturesSettingPreferenceController extends BasePreferenceControlle
@Override
public int getAvailabilityStatus() {
if (mGestureControllers == null) {
mGestureControllers = GestureSettings.buildPreferenceControllers(mContext,
null /* lifecycle */, new AmbientDisplayConfiguration(mContext));
mGestureControllers = buildAllPreferenceControllers(mContext);
}
boolean isAvailable = false;
for (AbstractPreferenceController controller : mGestureControllers) {
isAvailable = isAvailable || controller.isAvailable();
}
return isAvailable
? AVAILABLE
: DISABLED_UNSUPPORTED;
return isAvailable ? AVAILABLE : DISABLED_UNSUPPORTED;
}
/**
* Get all controllers for their availability status when doing getAvailabilityStatus.
* Do not use this method to add controllers into fragment, most of below controllers already
* convert to TogglePreferenceController, please register them in xml.
* The key is fake because those controllers won't be use to control preference.
*/
private static List<AbstractPreferenceController> buildAllPreferenceControllers(
@NonNull Context context) {
final AmbientDisplayConfiguration ambientDisplayConfiguration =
new AmbientDisplayConfiguration(context);
final List<AbstractPreferenceController> controllers =
GestureSettings.buildPreferenceControllers(context, null);
controllers.add(new AssistGestureSettingsPreferenceController(context, FAKE_PREF_KEY)
.setAssistOnly(false));
controllers.add(new SwipeToNotificationPreferenceController(context, FAKE_PREF_KEY));
controllers.add(new DoubleTwistPreferenceController(context, FAKE_PREF_KEY));
controllers.add(new DoubleTapPowerPreferenceController(context, FAKE_PREF_KEY));
controllers.add(new PickupGesturePreferenceController(context, FAKE_PREF_KEY)
.setConfig(ambientDisplayConfiguration));
controllers.add(new DoubleTapScreenPreferenceController(context, FAKE_PREF_KEY)
.setConfig(ambientDisplayConfiguration));
return controllers;
}
@Override

View File

@@ -22,8 +22,8 @@ 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;
import com.android.internal.hardware.AmbientDisplayConfiguration;
@@ -31,7 +31,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;
public class PickupGesturePreferenceController extends GesturePreferenceController {
@@ -43,18 +42,21 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
private final String SECURE_KEY = DOZE_PULSE_ON_PICK_UP;
private final AmbientDisplayConfiguration mAmbientConfig;
private AmbientDisplayConfiguration mAmbientConfig;
@UserIdInt
private final int mUserId;
public PickupGesturePreferenceController(Context context, Lifecycle lifecycle,
AmbientDisplayConfiguration config, @UserIdInt int userId, String key) {
super(context, lifecycle);
mAmbientConfig = config;
mUserId = userId;
public PickupGesturePreferenceController(Context context, String key) {
super(context, key);
mUserId = UserHandle.myUserId();
mPickUpPrefKey = key;
}
public PickupGesturePreferenceController setConfig(AmbientDisplayConfiguration config) {
mAmbientConfig = config;
return this;
}
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
AmbientDisplayConfiguration ambientConfig = new AmbientDisplayConfiguration(context);
return prefs.getBoolean(PickupGestureSettings.PREF_KEY_SUGGESTION_COMPLETE, false)
@@ -62,8 +64,11 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
}
@Override
public boolean isAvailable() {
return mAmbientConfig.pulseOnPickupAvailable();
public int getAvailabilityStatus() {
if (mAmbientConfig == null) {
mAmbientConfig = new AmbientDisplayConfiguration(mContext);
}
return mAmbientConfig.pulseOnPickupAvailable() ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
@@ -72,7 +77,7 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
}
@Override
protected boolean isSwitchPrefEnabled() {
public boolean isChecked() {
return mAmbientConfig.pulseOnPickupEnabled(mUserId);
}
@@ -82,11 +87,9 @@ public class PickupGesturePreferenceController extends GesturePreferenceControll
}
@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

View File

@@ -18,7 +18,6 @@ package com.android.settings.gestures;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
import com.android.internal.hardware.AmbientDisplayConfiguration;
@@ -28,17 +27,13 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PickupGestureSettings extends DashboardFragment {
private static final String TAG = "PickupGestureSettings";
private static final String KEY_PICK_UP = "gesture_pick_up";
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_pickup_gesture_suggestion_complete";
@@ -50,6 +45,9 @@ public class PickupGestureSettings extends DashboardFragment {
.getSuggestionFeatureProvider(context);
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
use(PickupGesturePreferenceController.class)
.setConfig(new AmbientDisplayConfiguration(context));
}
@Override
@@ -72,19 +70,6 @@ public class PickupGestureSettings extends DashboardFragment {
return R.string.help_url_pickup_gesture;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new PickupGesturePreferenceController(context, lifecycle,
new AmbientDisplayConfiguration(context), UserHandle.myUserId(), KEY_PICK_UP));
return controllers;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -94,12 +79,6 @@ public class PickupGestureSettings extends DashboardFragment {
sir.xmlResId = R.xml.pick_up_gesture_settings;
return Arrays.asList(sir);
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null /* lifecycle */);
}
};
}

View File

@@ -21,10 +21,8 @@ import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.v7.preference.Preference;
import com.android.settings.Utils;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class SwipeToNotificationPreferenceController extends GesturePreferenceController {
@@ -32,14 +30,11 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
private static final int OFF = 0;
private static final String PREF_KEY_VIDEO = "gesture_swipe_down_fingerprint_video";
private final String mSwipeDownFingerPrefKey;
private static final String SECURE_KEY = SYSTEM_NAVIGATION_KEYS_ENABLED;
public SwipeToNotificationPreferenceController(Context context, Lifecycle lifecycle,
String key) {
super(context, lifecycle);
mSwipeDownFingerPrefKey = key;
public SwipeToNotificationPreferenceController(Context context, String key) {
super(context, key);
}
public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
@@ -54,29 +49,24 @@ public class SwipeToNotificationPreferenceController extends GesturePreferenceCo
.getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys);
}
@Override
public String getPreferenceKey() {
return mSwipeDownFingerPrefKey;
}
@Override
protected String getVideoPrefKey() {
return PREF_KEY_VIDEO;
}
@Override
public boolean isAvailable() {
return SwipeToNotificationPreferenceController.isAvailable(mContext);
public int getAvailabilityStatus() {
return isAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
setSwipeToNotification(mContext, (boolean) newValue);
public boolean setChecked(boolean isChecked) {
setSwipeToNotification(mContext, isChecked);
return true;
}
@Override
protected boolean isSwitchPrefEnabled() {
public boolean isChecked() {
return isSwipeToNotificationOn(mContext);
}

View File

@@ -26,10 +26,7 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -37,8 +34,6 @@ public class SwipeToNotificationSettings extends DashboardFragment {
private static final String TAG = "SwipeToNotifSettings";
private static final String KEY = "gesture_swipe_down_fingerprint";
public static final String PREF_KEY_SUGGESTION_COMPLETE =
"pref_swipe_to_notification_suggestion_complete";
@@ -66,18 +61,6 @@ public class SwipeToNotificationSettings extends DashboardFragment {
return R.xml.swipe_to_notification_settings;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle, KEY));
return controllers;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -87,11 +70,5 @@ public class SwipeToNotificationSettings extends DashboardFragment {
sir.xmlResId = R.xml.swipe_to_notification_settings;
return Arrays.asList(sir);
}
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null /* lifecycle */);
}
};
}

View File

@@ -106,8 +106,6 @@ public class ConfigureNotificationSettings extends DashboardFragment {
}
controllers.add(new RecentNotifyingAppsPreferenceController(
context, new NotificationBackend(), app, host));
controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle,
KEY_SWIPE_DOWN));
controllers.add(badgeController);
controllers.add(pulseController);
controllers.add(lockScreenNotificationController);

View File

@@ -24,6 +24,8 @@ import static org.mockito.Mockito.verify;
import android.content.Context;
import com.android.settings.gestures.DoubleTapScreenPreferenceController;
import com.android.settings.gestures.PickupGesturePreferenceController;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -48,18 +50,48 @@ public class AmbientDisplaySettingsTest {
}
@Test
public void onAttach_shouldInvokeSetters() {
final AmbientDisplayAlwaysOnPreferenceController controller = mock(
AmbientDisplayAlwaysOnPreferenceController.class);
public void onAttach_alwaysOn_shouldInvokeSetters() {
final AmbientDisplayAlwaysOnPreferenceController controller = spy(
new AmbientDisplayAlwaysOnPreferenceController(mContext, "key"));
doReturn(controller).when(mTestFragment).use(
AmbientDisplayAlwaysOnPreferenceController.class);
mTestFragment.onAttach(mContext);
verify(controller).setConfig(any());
verify(controller).setCallback(any());
}
@Test
public void onAttach_notifications_shouldInvokeSetters() {
final AmbientDisplayNotificationsPreferenceController controller = spy(
new AmbientDisplayNotificationsPreferenceController(mContext, "key"));
doReturn(controller).when(mTestFragment).use(
AmbientDisplayNotificationsPreferenceController.class);
mTestFragment.onAttach(mContext);
verify(controller).setConfig(any());
}
@Test
public void onAttach_doubleTap_shouldInvokeSetters() {
final DoubleTapScreenPreferenceController controller = spy(
new DoubleTapScreenPreferenceController(mContext, "key"));
doReturn(controller).when(mTestFragment).use(DoubleTapScreenPreferenceController.class);
mTestFragment.onAttach(mContext);
verify(controller).setConfig(any());
}
@Test
public void onAttach_pickUp_shouldInvokeSetters() {
final PickupGesturePreferenceController controller = spy(
new PickupGesturePreferenceController(mContext, "key"));
doReturn(controller).when(mTestFragment).use(PickupGesturePreferenceController.class);
mTestFragment.onAttach(mContext);
verify(controller).setConfig(any());
}
public static class TestFragment extends AmbientDisplaySettings {
@Override
protected <T extends AbstractPreferenceController> T use(Class<T> clazz) {

View File

@@ -55,8 +55,8 @@ public class AssistGestureSettingsPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mFactory = FakeFeatureFactory.setupForTest();
mController =
new AssistGestureSettingsPreferenceController(mContext, null, KEY_ASSIST, false);
mController = new AssistGestureSettingsPreferenceController(mContext, KEY_ASSIST);
mController.setAssistOnly(false);
}
@Test
@@ -76,8 +76,8 @@ public class AssistGestureSettingsPreferenceControllerTest {
public void testPreferenceController_ProperResultPayloadType() {
final Context context = RuntimeEnvironment.application;
AssistGestureSettingsPreferenceController controller =
new AssistGestureSettingsPreferenceController(context, null /* lifecycle */,
KEY_ASSIST, false /* assistOnly */);
new AssistGestureSettingsPreferenceController(context, KEY_ASSIST);
controller.setAssistOnly(false);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}

View File

@@ -56,7 +56,7 @@ public class DoubleTapPowerPreferenceControllerTest {
public void setUp() {
mContext = RuntimeEnvironment.application;
mContentResolver = mContext.getContentResolver();
mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
}
@After
@@ -81,28 +81,27 @@ public class DoubleTapPowerPreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnTrue() {
public void testIsChecked_configIsNotSet_shouldReturnTrue() {
// Set the setting to be enabled.
Settings.System.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnFalse() {
public void testIsChecked_configIsSet_shouldReturnFalse() {
// Set the setting to be disabled.
Settings.System.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testPreferenceController_ProperResultPayloadType() {
DoubleTapPowerPreferenceController controller =
new DoubleTapPowerPreferenceController(mContext, null /* lifecycle */,
KEY_DOUBLE_TAP_POWER);
new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}

View File

@@ -56,8 +56,8 @@ public class DoubleTapScreenPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new DoubleTapScreenPreferenceController(
mContext, null, mAmbientDisplayConfiguration, 0, KEY_DOUBLE_TAP_SCREEN);
mController = new DoubleTapScreenPreferenceController(mContext, KEY_DOUBLE_TAP_SCREEN);
mController.setConfig(mAmbientDisplayConfiguration);
}
@Test
@@ -75,26 +75,26 @@ public class DoubleTapScreenPreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
public void testIsChecked_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(true);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
public void testIsChecked_configIsNotSet_shouldReturnFalse() {
when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testPreferenceController_ProperResultPayloadType() {
final Context context = RuntimeEnvironment.application;
DoubleTapScreenPreferenceController controller =
new DoubleTapScreenPreferenceController(context, null /* lifecycle */,
mAmbientDisplayConfiguration, 0 /* userid */, KEY_DOUBLE_TAP_SCREEN);
new DoubleTapScreenPreferenceController(context, KEY_DOUBLE_TAP_SCREEN);
controller.setConfig(mAmbientDisplayConfiguration);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}

View File

@@ -61,7 +61,7 @@ public class DoubleTwistPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mock(UserManager.class));
mController = new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST);
mController = new DoubleTwistPreferenceController(mContext, KEY_DOUBLE_TWIST);
}
@After
@@ -120,7 +120,7 @@ public class DoubleTwistPreferenceControllerTest {
Settings.Secure.putIntForUser(
null, Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId);
DoubleTwistPreferenceController controller =
spy(new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST));
spy(new DoubleTwistPreferenceController(mContext, KEY_DOUBLE_TWIST));
ShadowDoubleTwistPreferenceController.setManagedProfileId(managedId);
// enable the gesture
@@ -135,24 +135,24 @@ public class DoubleTwistPreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
public void testIsChecked_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
mController = new DoubleTwistPreferenceController(context, KEY_DOUBLE_TWIST);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
public void testIsChecked_configIsNotSet_shouldReturnFalse() {
// Set the setting to be disabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
mController = new DoubleTwistPreferenceController(context, KEY_DOUBLE_TWIST);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
}

View File

@@ -17,6 +17,9 @@
package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
@@ -31,7 +34,6 @@ import android.support.v7.preference.TwoStatePreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.VideoPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
@@ -49,7 +51,6 @@ public class GesturePreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Lifecycle mLifecycle;
private TestPrefController mController;
private Preference mPreference;
@@ -57,7 +58,7 @@ public class GesturePreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new TestPrefController(mContext, mLifecycle);
mController = new TestPrefController(mContext, "testKey");
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
@@ -187,7 +188,8 @@ public class GesturePreferenceControllerTest {
mController.updateState(preference);
// Verify summary is set to off (as setting is disabled).
verify(preference).setSummary(com.android.settings.R.string.gesture_setting_off);
assertThat(preference.getSummary()).isEqualTo(
mContext.getString(com.android.settings.R.string.gesture_setting_off));
}
private class TestPrefController extends GesturePreferenceController {
@@ -196,18 +198,13 @@ public class GesturePreferenceControllerTest {
boolean mIsPrefEnabled;
private TestPrefController(Context context,
Lifecycle lifecycle) {
super(context, lifecycle);
String key) {
super(context, key);
}
@Override
public boolean isAvailable() {
return mIsPrefAvailable;
}
@Override
public String getPreferenceKey() {
return "testKey";
public int getAvailabilityStatus() {
return mIsPrefAvailable ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
@@ -216,12 +213,12 @@ public class GesturePreferenceControllerTest {
}
@Override
protected boolean isSwitchPrefEnabled() {
public boolean isChecked() {
return mIsPrefEnabled;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean setChecked(boolean isChecked) {
return false;
}
}

View File

@@ -57,8 +57,8 @@ public class PickupGesturePreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new PickupGesturePreferenceController(
mContext, null, mAmbientDisplayConfiguration, 0, KEY_PICK_UP);
mController = new PickupGesturePreferenceController(mContext, KEY_PICK_UP);
mController.setConfig(mAmbientDisplayConfiguration);
}
@Test
@@ -76,19 +76,19 @@ public class PickupGesturePreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
public void testIsChecked_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(true);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
public void testIsChecked_configIsNotSet_shouldReturnFalse() {
// Set the setting to be disabled.
when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(false);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
@Test
@@ -111,8 +111,8 @@ public class PickupGesturePreferenceControllerTest {
public void testPreferenceController_ProperResultPayloadType() {
final Context context = RuntimeEnvironment.application;
PickupGesturePreferenceController controller =
new PickupGesturePreferenceController(
context, null, mAmbientDisplayConfiguration, 0, KEY_PICK_UP);
new PickupGesturePreferenceController(context, KEY_PICK_UP);
controller.setConfig(mAmbientDisplayConfiguration);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}

View File

@@ -53,7 +53,7 @@ public class SwipeToNotificationPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new SwipeToNotificationPreferenceController(mContext, null, KEY_SWIPE_DOWN);
mController = new SwipeToNotificationPreferenceController(mContext, KEY_SWIPE_DOWN);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
.thenReturn(mFingerprintManager);
@@ -93,27 +93,27 @@ public class SwipeToNotificationPreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
public void testIsChecked_configIsSet_shouldReturnTrue() {
stubFingerprintSupported(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
// Set the setting to be enabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 1);
mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN);
mController = new SwipeToNotificationPreferenceController(context, KEY_SWIPE_DOWN);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
public void testIsChecked_configIsNotSet_shouldReturnFalse() {
stubFingerprintSupported(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
// Set the setting to be disabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 0);
mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN);
mController = new SwipeToNotificationPreferenceController(context, KEY_SWIPE_DOWN);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
@Test

View File

@@ -53,14 +53,6 @@ public class SwipeToNotificationSettingsTest {
.isEqualTo(R.xml.swipe_to_notification_settings);
}
@Test
public void testGetPreferenceControllers_shouldAllBeCreated() {
final List<AbstractPreferenceController> controllers =
mFragment.createPreferenceControllers(mContext);
assertThat(controllers.isEmpty()).isFalse();
}
@Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =