Loading src/com/android/settings/gestures/OneHandedEnablePreferenceController.java +2 −4 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.settings.gestures; import android.content.Context; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; import com.android.settings.widget.SettingsMainSwitchPreferenceController; /** Loading @@ -33,9 +32,8 @@ public class OneHandedEnablePreferenceController extends SettingsMainSwitchPrefe @Override public int getAvailabilityStatus() { return OneHandedSettingsUtils.isSupportOneHandedMode() ? BasePreferenceController.AVAILABLE : BasePreferenceController.UNSUPPORTED_ON_DEVICE; return OneHandedSettingsUtils.isFeatureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override Loading src/com/android/settings/gestures/OneHandedSettingsUtils.java +22 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,28 @@ public class OneHandedSettingsUtils { sCurrentUserId); } /** * Get NavigationBar mode flag from Settings provider. * @param context App context * @return Navigation bar mode: * 0 = 3 button * 1 = 2 button * 2 = fully gestural */ public static int getNavigationBarMode(Context context) { return Settings.Secure.getIntForUser(context.getContentResolver(), Settings.Secure.NAVIGATION_MODE, 2 /* fully gestural */, sCurrentUserId); } /** * * @param context App context * @return Support One-Handed mode feature or not. */ public static boolean isFeatureAvailable(Context context) { return isSupportOneHandedMode() && getNavigationBarMode(context) != 0; } /** * Registers callback for observing Settings.Secure.ONE_HANDED_MODE_ENABLED state. * @param callback for state changes Loading src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceController.java +2 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,8 @@ public class SwipeBottomToNotificationPreferenceController extends TogglePrefere @Override public int getAvailabilityStatus() { return OneHandedSettingsUtils.isSupportOneHandedMode() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return OneHandedSettingsUtils.isFeatureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override Loading tests/robotests/src/com/android/settings/gestures/OneHandedEnablePreferenceControllerTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; Loading Loading @@ -60,6 +61,7 @@ public class OneHandedEnablePreferenceControllerTest { @Test public void getAvailabilityStatus_setSupportOneHandedModeProperty_shouldAvailable() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.AVAILABLE); Loading @@ -68,6 +70,16 @@ public class OneHandedEnablePreferenceControllerTest { @Test public void getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldUnsupported() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false"); setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); } @Test public void getAvailabilityStatus_set3ButtonModeProperty_shouldUnsupported() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); setNavigationBarMode(mContext, "0" /* 3-button */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); Loading @@ -88,4 +100,18 @@ public class OneHandedEnablePreferenceControllerTest { assertThat(mController.getSummary()) .isEqualTo(mContext.getText(R.string.switch_off_text)); } /** * Set NavigationBar mode flag to Settings provider. * @param context App context * @param value Navigation bar mode: * 0 = 3 button * 1 = 2 button * 2 = fully gestural * @return true if the value was set, false on database errors. */ private boolean setNavigationBarMode(Context context, String value) { return Settings.Secure.putStringForUser(context.getContentResolver(), Settings.Secure.NAVIGATION_MODE, value, UserHandle.myUserId()); } } tests/robotests/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceControllerTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings; import com.android.settings.R; Loading Loading @@ -69,6 +70,7 @@ public class SwipeBottomToNotificationPreferenceControllerTest { @Test public void getAvailabilityStatus_oneHandedUnsupported_returnsUnsupport() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false"); setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()).isEqualTo( BasePreferenceController.UNSUPPORTED_ON_DEVICE); Loading @@ -77,10 +79,20 @@ public class SwipeBottomToNotificationPreferenceControllerTest { @Test public void getAvailabilityStatus_oneHandedSupported_returnsAvailable() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } @Test public void getAvailabilityStatus_set3ButtonModeProperty_returnsUnsupport() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); setNavigationBarMode(mContext, "0" /* 3-button */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); } @Test public void getSummary_gestureEnabled_returnsOnSummary() { mController.setChecked(true); Loading @@ -105,4 +117,18 @@ public class SwipeBottomToNotificationPreferenceControllerTest { assertThat(mController.isChecked()).isFalse(); } /** * Set NavigationBar mode flag to Settings provider. * @param context App context * @param value Navigation bar mode: * 0 = 3 button * 1 = 2 button * 2 = fully gestural * @return true if the value was set, false on database errors. */ private boolean setNavigationBarMode(Context context, String value) { return Settings.Secure.putStringForUser(context.getContentResolver(), Settings.Secure.NAVIGATION_MODE, value, UserHandle.myUserId()); } } Loading
src/com/android/settings/gestures/OneHandedEnablePreferenceController.java +2 −4 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.settings.gestures; import android.content.Context; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; import com.android.settings.widget.SettingsMainSwitchPreferenceController; /** Loading @@ -33,9 +32,8 @@ public class OneHandedEnablePreferenceController extends SettingsMainSwitchPrefe @Override public int getAvailabilityStatus() { return OneHandedSettingsUtils.isSupportOneHandedMode() ? BasePreferenceController.AVAILABLE : BasePreferenceController.UNSUPPORTED_ON_DEVICE; return OneHandedSettingsUtils.isFeatureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override Loading
src/com/android/settings/gestures/OneHandedSettingsUtils.java +22 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,28 @@ public class OneHandedSettingsUtils { sCurrentUserId); } /** * Get NavigationBar mode flag from Settings provider. * @param context App context * @return Navigation bar mode: * 0 = 3 button * 1 = 2 button * 2 = fully gestural */ public static int getNavigationBarMode(Context context) { return Settings.Secure.getIntForUser(context.getContentResolver(), Settings.Secure.NAVIGATION_MODE, 2 /* fully gestural */, sCurrentUserId); } /** * * @param context App context * @return Support One-Handed mode feature or not. */ public static boolean isFeatureAvailable(Context context) { return isSupportOneHandedMode() && getNavigationBarMode(context) != 0; } /** * Registers callback for observing Settings.Secure.ONE_HANDED_MODE_ENABLED state. * @param callback for state changes Loading
src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceController.java +2 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,8 @@ public class SwipeBottomToNotificationPreferenceController extends TogglePrefere @Override public int getAvailabilityStatus() { return OneHandedSettingsUtils.isSupportOneHandedMode() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; return OneHandedSettingsUtils.isFeatureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override Loading
tests/robotests/src/com/android/settings/gestures/OneHandedEnablePreferenceControllerTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; Loading Loading @@ -60,6 +61,7 @@ public class OneHandedEnablePreferenceControllerTest { @Test public void getAvailabilityStatus_setSupportOneHandedModeProperty_shouldAvailable() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.AVAILABLE); Loading @@ -68,6 +70,16 @@ public class OneHandedEnablePreferenceControllerTest { @Test public void getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldUnsupported() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false"); setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); } @Test public void getAvailabilityStatus_set3ButtonModeProperty_shouldUnsupported() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); setNavigationBarMode(mContext, "0" /* 3-button */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); Loading @@ -88,4 +100,18 @@ public class OneHandedEnablePreferenceControllerTest { assertThat(mController.getSummary()) .isEqualTo(mContext.getText(R.string.switch_off_text)); } /** * Set NavigationBar mode flag to Settings provider. * @param context App context * @param value Navigation bar mode: * 0 = 3 button * 1 = 2 button * 2 = fully gestural * @return true if the value was set, false on database errors. */ private boolean setNavigationBarMode(Context context, String value) { return Settings.Secure.putStringForUser(context.getContentResolver(), Settings.Secure.NAVIGATION_MODE, value, UserHandle.myUserId()); } }
tests/robotests/src/com/android/settings/gestures/SwipeBottomToNotificationPreferenceControllerTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings; import com.android.settings.R; Loading Loading @@ -69,6 +70,7 @@ public class SwipeBottomToNotificationPreferenceControllerTest { @Test public void getAvailabilityStatus_oneHandedUnsupported_returnsUnsupport() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false"); setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()).isEqualTo( BasePreferenceController.UNSUPPORTED_ON_DEVICE); Loading @@ -77,10 +79,20 @@ public class SwipeBottomToNotificationPreferenceControllerTest { @Test public void getAvailabilityStatus_oneHandedSupported_returnsAvailable() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); setNavigationBarMode(mContext, "2" /* fully gestural */); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } @Test public void getAvailabilityStatus_set3ButtonModeProperty_returnsUnsupport() { SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); setNavigationBarMode(mContext, "0" /* 3-button */); assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); } @Test public void getSummary_gestureEnabled_returnsOnSummary() { mController.setChecked(true); Loading @@ -105,4 +117,18 @@ public class SwipeBottomToNotificationPreferenceControllerTest { assertThat(mController.isChecked()).isFalse(); } /** * Set NavigationBar mode flag to Settings provider. * @param context App context * @param value Navigation bar mode: * 0 = 3 button * 1 = 2 button * 2 = fully gestural * @return true if the value was set, false on database errors. */ private boolean setNavigationBarMode(Context context, String value) { return Settings.Secure.putStringForUser(context.getContentResolver(), Settings.Secure.NAVIGATION_MODE, value, UserHandle.myUserId()); } }