From 7f2496219feb66c9a2b174e9acd335959023cfa0 Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Sat, 3 Jul 2021 06:02:25 +0800 Subject: [PATCH] Fix landscape to reverse landscape issue Fingerprint enrollment page needs to display different types of layout for both landscape mode and reverse landscape mode. However onConfigurationChanged doesn't get called when landscape mode rotates to reverse landscape mode directly, that causes it displays a wrong layout in the both landscape and reverse landscape modes. Trying to monitor rotation event and checking if the case that directly turns landscape mode to reverse landscape mode happens, if so, reCreate method will get called to re-lay out the page. There will be a flicker problem happening in re-laying out the page but this solution still works for users to have the correct layout. Fix: 186372522 Test: manual test 1) Navigate to fingerprint enrollment page 2) Rotate the screen from landscape mode to reverse landscape mode 3) Observe the page and see if it has a correct layout Change-Id: Ie94f43a6546f453c10ae9f1c3ba83e1178784950 --- .../FingerprintEnrollEnrolling.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java index 9b19ef796c0..714e210f9f1 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java @@ -36,6 +36,8 @@ import android.os.Vibrator; import android.text.TextUtils; import android.util.Log; import android.view.MotionEvent; +import android.view.OrientationEventListener; +import android.view.Surface; import android.view.View; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; @@ -116,6 +118,9 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { private AccessibilityManager mAccessibilityManager; private boolean mIsAccessibilityEnabled; + private OrientationEventListener mOrientationEventListener; + private int mPreviousRotation = 0; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -128,6 +133,8 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { mAccessibilityManager = getSystemService(AccessibilityManager.class); mIsAccessibilityEnabled = mAccessibilityManager.isEnabled(); + listenOrientationEvent(); + if (mCanAssumeUdfps) { if (BiometricUtils.isReverseLandscape(getApplicationContext())) { setContentView(R.layout.udfps_enroll_enrolling_land); @@ -255,6 +262,12 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { stopIconAnimation(); } + @Override + protected void onDestroy() { + stopListenOrientationEvent(); + super.onDestroy(); + } + private void animateProgress(int progress) { if (mCanAssumeUdfps) { // UDFPS animations are owned by SystemUI @@ -451,6 +464,31 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { } } + private void listenOrientationEvent() { + mOrientationEventListener = new OrientationEventListener(this) { + @Override + public void onOrientationChanged(int orientation) { + final int currentRotation = getDisplay().getRotation(); + if ((mPreviousRotation == Surface.ROTATION_90 + && currentRotation == Surface.ROTATION_270) || ( + mPreviousRotation == Surface.ROTATION_270 + && currentRotation == Surface.ROTATION_90)) { + mPreviousRotation = currentRotation; + recreate(); + } + } + }; + mOrientationEventListener.enable(); + mPreviousRotation = getDisplay().getRotation(); + } + + private void stopListenOrientationEvent() { + if (mOrientationEventListener != null) { + mOrientationEventListener.disable(); + } + mOrientationEventListener = null; + } + private final Animator.AnimatorListener mProgressAnimationListener = new Animator.AnimatorListener() {