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

Commit 4c10e993 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

FontVariationUtils caches fvar string

Also made some changes to clock logging

Bug: 397579061
Flag: NONE Bugfix
Test: Manually validated reproduction
Change-Id: I01cae98c5e43837707e3cf00236d19c6eb086b4d
parent 99e793a5
Loading
Loading
Loading
Loading
+32 −20
Original line number Diff line number Diff line
@@ -16,17 +16,18 @@

package com.android.systemui.animation

import kotlin.text.buildString

class FontVariationUtils {
    private var mWeight = -1
    private var mWidth = -1
    private var mOpticalSize = -1
    private var mRoundness = -1
    private var isUpdated = false
    private var mCurrentFVar = ""

    /*
     * generate fontVariationSettings string, used for key in typefaceCache in TextAnimator
     * the order of axes should align to the order of parameters
     * if every axis remains unchanged, return ""
     */
    fun updateFontVariation(
        weight: Int = -1,
@@ -34,15 +35,17 @@ class FontVariationUtils {
        opticalSize: Int = -1,
        roundness: Int = -1,
    ): String {
        isUpdated = false
        var isUpdated = false
        if (weight >= 0 && mWeight != weight) {
            isUpdated = true
            mWeight = weight
        }

        if (width >= 0 && mWidth != width) {
            isUpdated = true
            mWidth = width
        }

        if (opticalSize >= 0 && mOpticalSize != opticalSize) {
            isUpdated = true
            mOpticalSize = opticalSize
@@ -52,23 +55,32 @@ class FontVariationUtils {
            isUpdated = true
            mRoundness = roundness
        }
        var resultString = ""

        if (!isUpdated) {
            return mCurrentFVar
        }

        return buildString {
                if (mWeight >= 0) {
            resultString += "'${GSFAxes.WEIGHT.tag}' $mWeight"
                    if (!isBlank()) append(", ")
                    append("'${GSFAxes.WEIGHT.tag}' $mWeight")
                }

                if (mWidth >= 0) {
            resultString +=
                (if (resultString.isBlank()) "" else ", ") + "'${GSFAxes.WIDTH.tag}' $mWidth"
                    if (!isBlank()) append(", ")
                    append("'${GSFAxes.WIDTH.tag}' $mWidth")
                }

                if (mOpticalSize >= 0) {
            resultString +=
                (if (resultString.isBlank()) "" else ", ") +
                    "'${GSFAxes.OPTICAL_SIZE.tag}' $mOpticalSize"
                    if (!isBlank()) append(", ")
                    append("'${GSFAxes.OPTICAL_SIZE.tag}' $mOpticalSize")
                }

                if (mRoundness >= 0) {
            resultString +=
                (if (resultString.isBlank()) "" else ", ") + "'${GSFAxes.ROUND.tag}' $mRoundness"
                    if (!isBlank()) append(", ")
                    append("'${GSFAxes.ROUND.tag}' $mRoundness")
                }
            }
        return if (isUpdated) resultString else ""
            .also { mCurrentFVar = it }
    }
}
+15 −12
Original line number Diff line number Diff line
@@ -38,8 +38,9 @@ import com.android.systemui.animation.TypefaceVariantCacheImpl
import com.android.systemui.customization.R
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.core.LogcatOnlyMessageBuffer
import com.android.systemui.log.core.Logger
import com.android.systemui.log.core.MessageBuffer
import com.android.systemui.plugins.clocks.ClockLogger
import com.android.systemui.plugins.clocks.ClockLogger.Companion.escapeTime
import java.io.PrintWriter
import java.util.Calendar
import java.util.Locale
@@ -67,7 +68,7 @@ constructor(
    var messageBuffer: MessageBuffer
        get() = logger.buffer
        set(value) {
            logger = Logger(value, TAG)
            logger = ClockLogger(this, value, TAG)
        }

    var hasCustomPositionUpdatedAnimation: Boolean = false
@@ -185,7 +186,9 @@ constructor(
        time.timeInMillis = timeOverrideInMillis ?: System.currentTimeMillis()
        contentDescription = DateFormat.format(descFormat, time)
        val formattedText = DateFormat.format(format, time)
        logger.d({ "refreshTime: new formattedText=$str1" }) { str1 = formattedText?.toString() }
        logger.d({ "refreshTime: new formattedText=${escapeTime(str1)}" }) {
            str1 = formattedText?.toString()
        }

        // Setting text actually triggers a layout pass in TextView (because the text view is set to
        // wrap_content width and TextView always relayouts for this). This avoids needless relayout
@@ -195,7 +198,7 @@ constructor(
        }

        text = formattedText
        logger.d({ "refreshTime: done setting new time text to: $str1" }) {
        logger.d({ "refreshTime: done setting new time text to: ${escapeTime(str1)}" }) {
            str1 = formattedText?.toString()
        }

@@ -225,7 +228,7 @@ constructor(

    @SuppressLint("DrawAllocation")
    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        logger.d("onMeasure")
        logger.onMeasure(widthMeasureSpec, heightMeasureSpec)

        if (!isSingleLineInternal && MeasureSpec.getMode(heightMeasureSpec) == EXACTLY) {
            // Call straight into TextView.setTextSize to avoid setting lastUnconstrainedTextSize
@@ -263,14 +266,14 @@ constructor(
            canvas.translate(parentWidth / 4f, 0f)
        }

        logger.d({ "onDraw($str1)" }) { str1 = text.toString() }
        logger.onDraw("$text")
        // intentionally doesn't call super.onDraw here or else the text will be rendered twice
        textAnimator?.draw(canvas)
        canvas.restore()
    }

    override fun invalidate() {
        logger.d("invalidate")
        logger.invalidate()
        super.invalidate()
    }

@@ -280,7 +283,7 @@ constructor(
        lengthBefore: Int,
        lengthAfter: Int,
    ) {
        logger.d({ "onTextChanged($str1)" }) { str1 = text.toString() }
        logger.d({ "onTextChanged(${escapeTime(str1)})" }) { str1 = "$text" }
        super.onTextChanged(text, start, lengthBefore, lengthAfter)
    }

@@ -370,7 +373,7 @@ constructor(
            return
        }

        logger.d("animateCharge")
        logger.animateCharge()
        val startAnimPhase2 = Runnable {
            setTextStyle(
                weight = if (isDozing()) dozingWeight else lockScreenWeight,
@@ -394,7 +397,7 @@ constructor(
    }

    fun animateDoze(isDozing: Boolean, animate: Boolean) {
        logger.d("animateDoze")
        logger.animateDoze(isDozing, animate)
        setTextStyle(
            weight = if (isDozing) dozingWeight else lockScreenWeight,
            color = if (isDozing) dozingColor else lockScreenColor,
@@ -484,7 +487,7 @@ constructor(
                isSingleLineInternal && !use24HourFormat -> Patterns.sClockView12
                else -> DOUBLE_LINE_FORMAT_12_HOUR
            }
        logger.d({ "refreshFormat($str1)" }) { str1 = format?.toString() }
        logger.d({ "refreshFormat(${escapeTime(str1)})" }) { str1 = format?.toString() }

        descFormat = if (use24HourFormat) Patterns.sClockView24 else Patterns.sClockView12
        refreshTime()
@@ -634,7 +637,7 @@ constructor(

    companion object {
        private val TAG = AnimatableClockView::class.simpleName!!
        private val DEFAULT_LOGGER = Logger(LogcatOnlyMessageBuffer(LogLevel.WARNING), TAG)
        private val DEFAULT_LOGGER = ClockLogger(null, LogcatOnlyMessageBuffer(LogLevel.DEBUG), TAG)

        const val ANIMATION_DURATION_FOLD_TO_AOD: Int = 600
        private const val DOUBLE_LINE_FORMAT_12_HOUR = "hh\nmm"
+1 −1
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ open class SimpleDigitalClockTextView(

    fun animateDoze(isDozing: Boolean, isAnimated: Boolean) {
        if (!this::textAnimator.isInitialized) return
        logger.animateDoze()
        logger.animateDoze(isDozing, isAnimated)
        textAnimator.setTextStyle(
            TextAnimator.Style(
                fVar = if (isDozing) aodFontVariation else lsFontVariation,
+4 −16
Original line number Diff line number Diff line
@@ -41,21 +41,9 @@ class FontVariationUtilsTest : SysuiTestCase() {
    @Test
    fun testStyleValueUnchange_getBlankStr() {
        val fontVariationUtils = FontVariationUtils()
        fontVariationUtils.updateFontVariation(
            weight = 100,
            width = 100,
            opticalSize = 0,
            roundness = 100,
        )
        val updatedFvar1 =
            fontVariationUtils.updateFontVariation(
                weight = 100,
                width = 100,
                opticalSize = 0,
                roundness = 100,
            )
        Assert.assertEquals("", updatedFvar1)
        val updatedFvar2 = fontVariationUtils.updateFontVariation()
        Assert.assertEquals("", updatedFvar2)
        Assert.assertEquals("", fontVariationUtils.updateFontVariation())
        val fVar = fontVariationUtils.updateFontVariation(weight = 100)
        Assert.assertEquals(fVar, fontVariationUtils.updateFontVariation())
        Assert.assertEquals(fVar, fontVariationUtils.updateFontVariation(weight = 100))
    }
}
+8 −14
Original line number Diff line number Diff line
@@ -55,15 +55,9 @@ class ClockLogger(private val view: View?, buffer: MessageBuffer, tag: String) :
    }

    fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        d({
            val rect = VRect(int1.toShort(), int2.toShort(), long1.toShort(), long2.toShort())
            "onLayout($bool1, $rect)"
        }) {
        d({ "onLayout($bool1, ${VRect(long1.toULong())})" }) {
            bool1 = changed
            int1 = left
            int2 = top
            long1 = right.toLong()
            long2 = bottom.toLong()
            long1 = VRect(left, top, right, bottom).data.toLong()
        }
    }

@@ -110,8 +104,11 @@ class ClockLogger(private val view: View?, buffer: MessageBuffer, tag: String) :
        }
    }

    fun animateDoze() {
        d("animateDoze()")
    fun animateDoze(isDozing: Boolean, isAnimated: Boolean) {
        d({ "animateDoze(isDozing=$bool1, isAnimated=$bool2)" }) {
            bool1 = isDozing
            bool2 = isAnimated
        }
    }

    fun animateCharge() {
@@ -119,10 +116,7 @@ class ClockLogger(private val view: View?, buffer: MessageBuffer, tag: String) :
    }

    fun animateFidget(x: Float, y: Float) {
        d({ "animateFidget($str1, $str2)" }) {
            str1 = x.toString()
            str2 = y.toString()
        }
        d({ "animateFidget(${VPointF(long1.toULong())})" }) { long1 = VPointF(x, y).data.toLong() }
    }

    companion object {
Loading