Merge "Bouncer - Ensure one-handed mode bouncer side" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-03-24 09:01:02 +00:00
committed by Android (Google) Code Review
2 changed files with 17 additions and 8 deletions

View File

@@ -307,8 +307,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
void onResume(SecurityMode securityMode, boolean faceAuthEnabled) {
mSecurityViewFlipper.setWindowInsetsAnimationCallback(mWindowInsetsAnimationCallback);
updateBiometricRetry(securityMode, faceAuthEnabled);
setupViewMode();
}
void initMode(@Mode int mode, GlobalSettings globalSettings, FalsingManager falsingManager,
@@ -1044,11 +1042,13 @@ public class KeyguardSecurityContainer extends FrameLayout {
/**
* Moves the bouncer to align with a tap (most likely in the shade), so the bouncer
* appears on the same side as a touch. Will not update the user-preference.
* appears on the same side as a touch.
*/
@Override
public void updatePositionByTouchX(float x) {
updateSecurityViewLocation(x <= mView.getWidth() / 2f, /* animate= */false);
boolean isTouchOnLeft = x <= mView.getWidth() / 2f;
updateSideSetting(isTouchOnLeft);
updateSecurityViewLocation(isTouchOnLeft, /* animate= */false);
}
boolean isLeftAligned() {
@@ -1057,6 +1057,13 @@ public class KeyguardSecurityContainer extends FrameLayout {
== Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT;
}
private void updateSideSetting(boolean leftAligned) {
mGlobalSettings.putInt(
Settings.Global.ONE_HANDED_KEYGUARD_SIDE,
leftAligned ? Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT
: Settings.Global.ONE_HANDED_KEYGUARD_SIDE_RIGHT);
}
/**
* Determine if a tap on this view is on the other side. If so, will animate positions
* and record the preference to always show on this side.
@@ -1070,10 +1077,7 @@ public class KeyguardSecurityContainer extends FrameLayout {
|| (!currentlyLeftAligned && (x < mView.getWidth() / 2f))) {
boolean willBeLeftAligned = !currentlyLeftAligned;
mGlobalSettings.putInt(
Settings.Global.ONE_HANDED_KEYGUARD_SIDE,
willBeLeftAligned ? Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT
: Settings.Global.ONE_HANDED_KEYGUARD_SIDE_RIGHT);
updateSideSetting(willBeLeftAligned);
int keyguardState = willBeLeftAligned
? SysUiStatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__SWITCH_LEFT

View File

@@ -34,6 +34,7 @@ import static org.mockito.Mockito.when;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.Gravity;
@@ -204,10 +205,14 @@ public class KeyguardSecurityContainerTest extends SysuiTestCase {
mKeyguardSecurityContainer.updatePositionByTouchX(
mKeyguardSecurityContainer.getWidth() - 1f);
verify(mGlobalSettings).putInt(Settings.Global.ONE_HANDED_KEYGUARD_SIDE,
Settings.Global.ONE_HANDED_KEYGUARD_SIDE_RIGHT);
verify(mSecurityViewFlipper).setTranslationX(
mKeyguardSecurityContainer.getWidth() - mSecurityViewFlipper.getWidth());
mKeyguardSecurityContainer.updatePositionByTouchX(1f);
verify(mGlobalSettings).putInt(Settings.Global.ONE_HANDED_KEYGUARD_SIDE,
Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT);
verify(mSecurityViewFlipper).setTranslationX(0.0f);
}