Fix refresh in Gestures, not reflecting the changes after

toggling on/off one-handed mode

1) Remove disabling on swipe down notification.
2) Update to align asset with One-Handed mode temporarily.
3) Change some states when toggle on/off and align with
One-Handed mode.
4) Set temporary asset style to "centerInside" to avoid image
corrupted problem when device rotate.
5) Add new string on Swipe down notification toggle switch.

Bug: 177679988
Bug: 181970213

Test: manual verified on Settings > System > Gesture page
Test: make RunSettingsRoboTests ROBOTEST_FILTER=
      "com.android.settings.gestures.OneHandedSettingsTest"
Test: make RunSettingsRoboTests ROBOTEST_FILTER=
      "com.android.settings.gestures
      .OneHandedAppTapsExitPreferenceControllerTest"
Test: make RunSettingsRoboTests ROBOTEST_FILTER=
      "com.android.settings.gestures
      .OneHandedEnablePreferenceControllerTest"
Test: make RunSettingsRoboTests ROBOTEST_FILTER=
      "com.android.settings.gestures
      .OneHandedTimeoutPreferenceControllerTest"
Test: make RunSettingsRoboTests ROBOTEST_FILTER=
      "com.android.settings.gestures.OneHandedSettingsUtilsTest"
Test: make RunSettingsRoboTests ROBOTEST_FILTER=
      "com.android.settings.gestures.SwipeBottomToNotificationPreferenceControllerTest"
Test: make RunSettingsRoboTests ROBOTEST_FILTER=
      "com.android.settings.gestures.SwipeBottomToNotificationSettingsTest"

Change-Id: Ifd2346a7694323d21eb424891987c8317847e7c5
This commit is contained in:
Jason Chang
2021-03-12 17:26:42 +08:00
parent 59aa4f9cb1
commit 858bda81f1
12 changed files with 85 additions and 84 deletions

View File

@@ -21,7 +21,7 @@
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:scaleType="centerInside"
android:cropToPadding="true"
android:src="@drawable/one_handed_guideline"
android:contentDescription="@null" />

View File

@@ -11280,8 +11280,8 @@
<!-- Title text for swiping downwards on the bottom of the screen for notifications [CHAR LIMIT=60]-->
<string name="swipe_bottom_to_notifications_title">Swipe for notifications</string>
<!-- Summary text for swiping downwards on the bottom of the screen for notifications [CHAR LIMIT=80]-->
<string name="swipe_bottom_to_notifications_summary">Swipe down on the bottom edge of the screen to show your notifications</string>
<!-- Summary text for swiping downwards on the bottom of the screen for notifications [CHAR LIMIT=NONE]-->
<string name="swipe_bottom_to_notifications_summary">Swipe down on the bottom edge of the screen to show your notifications.\nYou can\'t use one-handed mode when this feature is turned on.</string>
<!-- Preference and settings suggestion title text for one handed [CHAR LIMIT=60] -->
<string name="one_handed_title">One-Handed mode</string>

View File

@@ -20,11 +20,13 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/swipe_bottom_to_notifications_title">
<com.android.settings.widget.VideoPreference
android:title="@string/swipe_bottom_to_notifications_title"
settings:animation="@raw/gesture_fingerprint_swipe"
settings:preview="@drawable/gesture_fingerprint_swipe"
settings:controller="com.android.settings.widget.VideoPreferenceController"/>
<com.android.settingslib.widget.LayoutPreference
android:key="one_handed_header"
android:layout="@layout/one_handed_header"
android:persistent="false"
android:selectable="false"
settings:allowDividerBelow="false"
settings:searchable="false"/>
<SwitchPreference
android:key="gesture_swipe_bottom_to_notification"

View File

@@ -17,7 +17,6 @@
package com.android.settings.gestures;
import android.content.Context;
import android.os.SystemProperties;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
@@ -28,15 +27,13 @@ import com.android.settings.core.TogglePreferenceController;
**/
public class OneHandedEnablePreferenceController extends TogglePreferenceController {
static final String SUPPORT_ONE_HANDED_MODE = "ro.support_one_handed_mode";
public OneHandedEnablePreferenceController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false)
return OneHandedSettingsUtils.isSupportOneHandedMode()
? BasePreferenceController.AVAILABLE
: BasePreferenceController.UNSUPPORTED_ON_DEVICE;
}
@@ -45,6 +42,7 @@ public class OneHandedEnablePreferenceController extends TogglePreferenceControl
public boolean setChecked(boolean isChecked) {
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext,
isChecked);
OneHandedSettingsUtils.setSwipeDownNotificationEnabled(mContext, !isChecked);
return true;
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.gestures;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.SystemProperties;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -52,8 +51,7 @@ public class OneHandedSettings extends DashboardFragment {
new BaseSearchIndexProvider(R.xml.one_handed_settings) {
@Override
protected boolean isPageSearchEnabled(Context context) {
return SystemProperties.getBoolean(
OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, false);
return OneHandedSettingsUtils.isSupportOneHandedMode();
}
};
}

View File

@@ -22,6 +22,7 @@ import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemProperties;
import android.provider.Settings;
/**
@@ -29,6 +30,8 @@ import android.provider.Settings;
*/
public class OneHandedSettingsUtils {
static final String SUPPORT_ONE_HANDED_MODE = "ro.support_one_handed_mode";
public enum OneHandedTimeout {
NEVER(0), SHORT(4), MEDIUM(8), LONG(12);
@@ -51,6 +54,13 @@ public class OneHandedSettingsUtils {
mSettingsObserver = new SettingsObserver(new Handler(Looper.getMainLooper()));
}
/**
* Get One-Handed mode support flag.
*/
public static boolean isSupportOneHandedMode() {
return SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false);
}
/**
* Get one-handed mode enable or disable flag from Settings provider.
*
@@ -118,6 +128,28 @@ public class OneHandedSettingsUtils {
Settings.Secure.ONE_HANDED_MODE_TIMEOUT, timeout);
}
/**
* Get Swipe-down-notification enable or disable flag from Settings provider.
*
* @param context App context
* @return enable or disable Swipe-down-notification flag.
*/
public static boolean isSwipeDownNotificationEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, 0) == 1;
}
/**
* Set Swipe-down-notification enable or disable flag to Settings provider.
*
* @param context App context
* @param enable enable or disable Swipe-down-notification.
*/
public static void setSwipeDownNotificationEnabled(Context context, boolean enable) {
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, enable ? 1 : 0);
}
/**
* Register callback for observing Settings.Secure.ONE_HANDED_MODE_ENABLED state.
* @param callback for state changes

View File

@@ -16,14 +16,8 @@
package com.android.settings.gestures;
import static android.provider.Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED;
import static com.android.settings.gestures.OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE;
import android.content.Context;
import android.os.SystemProperties;
import android.provider.Settings;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
@@ -33,32 +27,20 @@ import com.android.settings.core.TogglePreferenceController;
**/
public class SwipeBottomToNotificationPreferenceController extends TogglePreferenceController {
private static final int ON = 1;
private static final int OFF = 0;
private static final String PREF_KEY = "gesture_swipe_bottom_to_notification";
public SwipeBottomToNotificationPreferenceController(Context context, String key) {
super(context, key);
}
/** Indicates whether the gesture is available or not. */
public static boolean isGestureAvailable(Context context) {
// Disable the gesture once One-Handed mode gesture enabled.
if (SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false)) {
return !OneHandedSettingsUtils.isOneHandedModeEnabled(context);
}
return true;
}
@Override
public int getAvailabilityStatus() {
return isGestureAvailable(mContext) ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
return OneHandedSettingsUtils.isSupportOneHandedMode() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean isSliceable() {
return TextUtils.equals(getPreferenceKey(), PREF_KEY);
return true;
}
@Override
@@ -68,15 +50,16 @@ public class SwipeBottomToNotificationPreferenceController extends TogglePrefere
@Override
public boolean setChecked(boolean isChecked) {
Settings.Secure.putInt(mContext.getContentResolver(),
SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, isChecked ? ON : OFF);
if (isChecked) {
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, false);
}
OneHandedSettingsUtils.setSwipeDownNotificationEnabled(mContext, isChecked);
return true;
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(),
SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, OFF) == ON;
return OneHandedSettingsUtils.isSwipeDownNotificationEnabled(mContext);
}
@Override

View File

@@ -50,8 +50,10 @@ public class SwipeBottomToNotificationSettings extends DashboardFragment {
@Override
protected boolean isPageSearchEnabled(Context context) {
return SwipeBottomToNotificationPreferenceController
.isGestureAvailable(context);
if (!OneHandedSettingsUtils.isSupportOneHandedMode()) {
return false;
}
return !OneHandedSettingsUtils.isOneHandedModeEnabled(context);
}
};
}

View File

@@ -51,14 +51,16 @@ public class OneHandedEnablePreferenceControllerTest {
public void setChecked_setBoolean_checkIsTrueOrFalse() {
mController.setChecked(false);
assertThat(OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)).isFalse();
assertThat(OneHandedSettingsUtils.isSwipeDownNotificationEnabled(mContext)).isTrue();
mController.setChecked(true);
assertThat(OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)).isTrue();
assertThat(OneHandedSettingsUtils.isSwipeDownNotificationEnabled(mContext)).isFalse();
}
@Test
public void getAvailabilityStatus_setSupportOneHandedModeProperty_shouldAvailable() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "true");
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
@@ -66,7 +68,7 @@ public class OneHandedEnablePreferenceControllerTest {
@Test
public void getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldUnsupported() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "false");
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false");
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);

View File

@@ -55,7 +55,7 @@ public class OneHandedSettingsTest {
@Test
public void isPageSearchEnabled_setSupportOneHandedModeProperty_shouldReturnTrue() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "true");
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
final Object obj = ReflectionHelpers.callInstanceMethod(
OneHandedSettings.SEARCH_INDEX_DATA_PROVIDER, "isPageSearchEnabled",
@@ -66,7 +66,7 @@ public class OneHandedSettingsTest {
@Test
public void isPageSearchEnabled_unsetSupportOneHandedModeProperty_shouldReturnFalse() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "false");
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false");
final Object obj = ReflectionHelpers.callInstanceMethod(
OneHandedSettings.SEARCH_INDEX_DATA_PROVIDER, "isPageSearchEnabled",

View File

@@ -16,10 +16,7 @@
package com.android.settings.gestures;
import static android.provider.Settings.Secure.SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
import static com.google.common.truth.Truth.assertThat;
@@ -28,6 +25,7 @@ import android.os.SystemProperties;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Test;
@@ -57,43 +55,32 @@ public class SwipeBottomToNotificationPreferenceControllerTest {
public void setChecked_toggledOn_enablesSwipeBottomToNotification() {
mController.setChecked(true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, 0)).isEqualTo(1);
assertThat(OneHandedSettingsUtils.isSwipeDownNotificationEnabled(mContext)).isTrue();
assertThat(OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)).isFalse();
}
@Test
public void setChecked_toggledOff_disablesSwipeBottomToNotification() {
mController.setChecked(false);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
SWIPE_BOTTOM_TO_NOTIFICATION_ENABLED, 0)).isEqualTo(0);
assertThat(OneHandedSettingsUtils.isSwipeDownNotificationEnabled(mContext)).isFalse();
}
@Test
public void getAvailabilityStatus_oneHandedUnsupported_returnsAvailable() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "false");
public void getAvailabilityStatus_oneHandedUnsupported_returnsUnsupport() {
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false");
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_oneHandedSupported_returnsAvailable() {
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void getAvailabilityStatus_oneHandedDisabled_returnsAvailable() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "true");
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ONE_HANDED_MODE_ENABLED, 0);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void getAvailabilityStatus_oneHandedEnabled_returnsDisabled() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "true");
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ONE_HANDED_MODE_ENABLED, 1);
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
public void getSummary_gestureEnabled_returnsOnSummary() {
mController.setChecked(true);
@@ -111,8 +98,8 @@ public class SwipeBottomToNotificationPreferenceControllerTest {
}
@Test
public void getDefaultConfig_returnsOffState() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "false");
public void isChecked_getDefaultConfig_returnFalse() {
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false");
Settings.Secure.resetToDefaults(mContext.getContentResolver(),
Settings.Secure.ONE_HANDED_MODE_ENABLED);

View File

@@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.os.SystemProperties;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import com.android.settings.R;
@@ -64,22 +63,21 @@ public class SwipeBottomToNotificationSettingsTest {
}
@Test
public void isPageSearchEnabled_oneHandedUnsupported_shouldReturnTrue() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "false");
public void isPageSearchEnabled_oneHandedUnsupported_shouldReturnFalse() {
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false");
final Object obj = ReflectionHelpers.callInstanceMethod(
SwipeBottomToNotificationSettings.SEARCH_INDEX_DATA_PROVIDER, "isPageSearchEnabled",
ReflectionHelpers.ClassParameter.from(Context.class, mContext));
final boolean isEnabled = (Boolean) obj;
assertThat(isEnabled).isTrue();
assertThat(isEnabled).isFalse();
}
@Test
public void isPageSearchEnabled_oneHandedDisabled_shouldReturnTrue() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "true");
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ONE_HANDED_MODE_ENABLED, 0);
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, false);
final Object obj = ReflectionHelpers.callInstanceMethod(
SwipeBottomToNotificationSettings.SEARCH_INDEX_DATA_PROVIDER, "isPageSearchEnabled",
@@ -91,9 +89,8 @@ public class SwipeBottomToNotificationSettingsTest {
@Test
public void isPageSearchEnabled_oneHandedEnabled_shouldReturnFalse() {
SystemProperties.set(OneHandedEnablePreferenceController.SUPPORT_ONE_HANDED_MODE, "true");
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ONE_HANDED_MODE_ENABLED, 1);
SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
OneHandedSettingsUtils.setSettingsOneHandedModeEnabled(mContext, true);
final Object obj = ReflectionHelpers.callInstanceMethod(
SwipeBottomToNotificationSettings.SEARCH_INDEX_DATA_PROVIDER, "isPageSearchEnabled",