From 5f4c7dbda573aa7ecb9a55be729368483fb89b52 Mon Sep 17 00:00:00 2001 From: Grace Cheng Date: Mon, 2 Jan 2023 10:44:38 +0000 Subject: [PATCH] Updates sfps indicator placement calculations Updates sfps indicator placement calculations given natural orientation switch from landscape to portrait Test: atest SideFpsControllerTest Fixes: 263437936 Change-Id: I5034733d8c854df27223eb08d2afafcaa93b48aa --- .../systemui/biometrics/SideFpsController.kt | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt index 17ebdadfa93f0..1afa9b26ce980 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt @@ -110,6 +110,9 @@ constructor( private val animationDuration = context.resources.getInteger(android.R.integer.config_mediumAnimTime).toLong() + private val isReverseDefaultRotation = + context.getResources().getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation) + private var overlayHideAnimator: ViewPropertyAnimator? = null private var overlayView: View? = null @@ -217,8 +220,17 @@ constructor( overlayOffsets = offsets val lottie = view.findViewById(R.id.sidefps_animation) as LottieAnimationView - view.rotation = display.asSideFpsAnimationRotation(offsets.isYAligned()) - lottie.setAnimation(display.asSideFpsAnimation(offsets.isYAligned())) + view.rotation = + display.asSideFpsAnimationRotation( + offsets.isYAligned(), + getRotationFromDefault(display.rotation) + ) + lottie.setAnimation( + display.asSideFpsAnimation( + offsets.isYAligned(), + getRotationFromDefault(display.rotation) + ) + ) lottie.addLottieOnCompositionLoadedListener { // Check that view is not stale, and that overlayView has not been hidden/removed if (overlayView != null && overlayView == view) { @@ -253,11 +265,13 @@ constructor( @VisibleForTesting internal fun updateOverlayParams(display: Display, bounds: Rect) { val isNaturalOrientation = display.isNaturalOrientation() + val isDefaultOrientation = + if (isReverseDefaultRotation) !isNaturalOrientation else isNaturalOrientation val size = windowManager.maximumWindowMetrics.bounds - val displayWidth = if (isNaturalOrientation) size.width() else size.height() - val displayHeight = if (isNaturalOrientation) size.height() else size.width() - val boundsWidth = if (isNaturalOrientation) bounds.width() else bounds.height() - val boundsHeight = if (isNaturalOrientation) bounds.height() else bounds.width() + val displayWidth = if (isDefaultOrientation) size.width() else size.height() + val displayHeight = if (isDefaultOrientation) size.height() else size.width() + val boundsWidth = if (isDefaultOrientation) bounds.width() else bounds.height() + val boundsHeight = if (isDefaultOrientation) bounds.height() else bounds.width() val sensorBounds = if (overlayOffsets.isYAligned()) { Rect( @@ -278,7 +292,7 @@ constructor( RotationUtils.rotateBounds( sensorBounds, Rect(0, 0, displayWidth, displayHeight), - display.rotation + getRotationFromDefault(display.rotation) ) overlayViewParams.x = sensorBounds.left @@ -319,6 +333,9 @@ constructor( view.visibility = View.VISIBLE } } + + private fun getRotationFromDefault(rotation: Int): Int = + if (isReverseDefaultRotation) (rotation + 1) % 4 else rotation } private val FingerprintManager?.sideFpsSensorProperties: FingerprintSensorPropertiesInternal? @@ -344,15 +361,15 @@ private fun ActivityTaskManager.topClass(): String = getTasks(1).firstOrNull()?.topActivity?.className ?: "" @RawRes -private fun Display.asSideFpsAnimation(yAligned: Boolean): Int = - when (rotation) { +private fun Display.asSideFpsAnimation(yAligned: Boolean, rotationFromDefault: Int): Int = + when (rotationFromDefault) { Surface.ROTATION_0 -> if (yAligned) R.raw.sfps_pulse else R.raw.sfps_pulse_landscape Surface.ROTATION_180 -> if (yAligned) R.raw.sfps_pulse else R.raw.sfps_pulse_landscape else -> if (yAligned) R.raw.sfps_pulse_landscape else R.raw.sfps_pulse } -private fun Display.asSideFpsAnimationRotation(yAligned: Boolean): Float = - when (rotation) { +private fun Display.asSideFpsAnimationRotation(yAligned: Boolean, rotationFromDefault: Int): Float = + when (rotationFromDefault) { Surface.ROTATION_90 -> if (yAligned) 0f else 180f Surface.ROTATION_180 -> 180f Surface.ROTATION_270 -> if (yAligned) 180f else 0f