Fix default clock text moving right in larger display size
The reason is that when height of default clock is constrained, the font
size using half of the height is not small enough and cause TextView to
scroll when textAlignment is default. Added more detailed explanation in the
bug link.
Bug: 342505732
Test: manually test for 1) both normal and largerst display size, observe
that default clock aligned center when there's no notification, and move
left when there's notifications; 2) set system language to Arabic,
observe the symmetric behavior.
Flag: com.android.systemui.migrate_clocks_to_blueprint
Change-Id: I21e3fd04b8d656408fea822b3d176bdca6628ba6
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/AnimatableClockView.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/AnimatableClockView.kt
index 079c1d9..1863cd8 100644
--- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/AnimatableClockView.kt
+++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/AnimatableClockView.kt
@@ -531,8 +531,10 @@
moveFraction: Float,
) {
val isMovingToCenter = if (isLayoutRtl) clockMoveDirection < 0 else clockMoveDirection > 0
+ // The sign of moveAmountDeltaForDigit is already set here
+ // we can interpret (left - clockStartLeft) as (destinationPosition - originPosition)
+ // so we no longer need to multiply direct sign to moveAmountDeltaForDigit
val currentMoveAmount = left - clockStartLeft
- val digitOffsetDirection = if (isLayoutRtl) -1 else 1
for (i in 0 until NUM_DIGITS) {
val digitFraction =
getDigitFraction(
@@ -542,7 +544,7 @@
)
val moveAmountForDigit = currentMoveAmount * digitFraction
val moveAmountDeltaForDigit = moveAmountForDigit - currentMoveAmount
- glyphOffsets[i] = digitOffsetDirection * moveAmountDeltaForDigit
+ glyphOffsets[i] = moveAmountDeltaForDigit
}
invalidate()
}
@@ -582,6 +584,17 @@
invalidate()
}
+ override fun onRtlPropertiesChanged(layoutDirection: Int) {
+ if (migratedClocks) {
+ if (layoutDirection == LAYOUT_DIRECTION_RTL) {
+ textAlignment = TEXT_ALIGNMENT_TEXT_END
+ } else {
+ textAlignment = TEXT_ALIGNMENT_TEXT_START
+ }
+ }
+ super.onRtlPropertiesChanged(layoutDirection)
+ }
+
private fun getDigitFraction(digit: Int, isMovingToCenter: Boolean, fraction: Float): Float {
// The delay for the digit, in terms of fraction.
// (i.e. the digit should not move during 0.0 - 0.1).