Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10192fb9 authored by Sherry Zhou's avatar Sherry Zhou
Browse files

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
parent 4c5d3987
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -531,8 +531,10 @@ constructor(
        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 @@ constructor(
                )
            val moveAmountForDigit = currentMoveAmount * digitFraction
            val moveAmountDeltaForDigit = moveAmountForDigit - currentMoveAmount
            glyphOffsets[i] = digitOffsetDirection * moveAmountDeltaForDigit
            glyphOffsets[i] = moveAmountDeltaForDigit
        }
        invalidate()
    }
@@ -582,6 +584,17 @@ constructor(
        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).