Aperture: Animate SecondaryTopBarButton's verticalBias on rotation
This makes sure that button icons are properly aligned for 90/180/270
degrees rotations.
Change-Id: Ifbd5e36b8836506df98a90b48e0709721519d370
diff --git a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
index c20f6e5..c1eae05 100644
--- a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
@@ -65,6 +65,7 @@
import androidx.core.view.doOnLayout
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
+import androidx.core.view.updateLayoutParams
import androidx.lifecycle.MutableLiveData
import androidx.preference.PreferenceManager
import coil.decode.VideoFrameDecoder
@@ -1861,7 +1862,24 @@
secondaryTopBarLayout.getChildAt(0)
)?.let { layout ->
for (child in layout.children) {
- Button::class.safeCast(child)?.smoothRotate(compensationValue)
+ Button::class.safeCast(child)?.let {
+ it.smoothRotate(compensationValue)
+ ValueAnimator.ofFloat(
+ (it.layoutParams as ConstraintLayout.LayoutParams).verticalBias,
+ when (screenRotation) {
+ Rotation.ROTATION_0 -> 0.0f
+ Rotation.ROTATION_180 -> 1.0f
+ Rotation.ROTATION_90,
+ Rotation.ROTATION_270 -> 0.5f
+ }
+ ).apply {
+ addUpdateListener { anim ->
+ it.updateLayoutParams<ConstraintLayout.LayoutParams> {
+ verticalBias = anim.animatedValue as Float
+ }
+ }
+ }.start()
+ }
}
}