diff options
7 files changed, 76 insertions, 67 deletions
diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/FontVariationUtils.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/FontVariationUtils.kt index 9a746870c6ff..e07d7b337ba2 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/FontVariationUtils.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/FontVariationUtils.kt @@ -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 (mWeight >= 0) { - resultString += "'${GSFAxes.WEIGHT.tag}' $mWeight" - } - if (mWidth >= 0) { - resultString += - (if (resultString.isBlank()) "" else ", ") + "'${GSFAxes.WIDTH.tag}' $mWidth" - } - if (mOpticalSize >= 0) { - resultString += - (if (resultString.isBlank()) "" else ", ") + - "'${GSFAxes.OPTICAL_SIZE.tag}' $mOpticalSize" - } - if (mRoundness >= 0) { - resultString += - (if (resultString.isBlank()) "" else ", ") + "'${GSFAxes.ROUND.tag}' $mRoundness" + + if (!isUpdated) { + return mCurrentFVar } - return if (isUpdated) resultString else "" + + return buildString { + if (mWeight >= 0) { + if (!isBlank()) append(", ") + append("'${GSFAxes.WEIGHT.tag}' $mWeight") + } + + if (mWidth >= 0) { + if (!isBlank()) append(", ") + append("'${GSFAxes.WIDTH.tag}' $mWidth") + } + + if (mOpticalSize >= 0) { + if (!isBlank()) append(", ") + append("'${GSFAxes.OPTICAL_SIZE.tag}' $mOpticalSize") + } + + if (mRoundness >= 0) { + if (!isBlank()) append(", ") + append("'${GSFAxes.ROUND.tag}' $mRoundness") + } + } + .also { mCurrentFVar = it } } } 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 4bf0ceb51784..6e29e6932629 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 @@ -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" diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt index 5d5fa98a7ebc..272882330eae 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt @@ -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, diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/animation/FontVariationUtilsTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/animation/FontVariationUtilsTest.kt index 8d3640d8d809..53b364c13063 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/animation/FontVariationUtilsTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/animation/FontVariationUtilsTest.kt @@ -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)) } } diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockLogger.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockLogger.kt index 6e967f12899e..f9ff75d5fdc8 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockLogger.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockLogger.kt @@ -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 { diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/VPoint.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/VPoint.kt index 6ec9bb45a917..1fb37ec28835 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/VPoint.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/VPoint.kt @@ -37,7 +37,7 @@ private fun pack(x: Int, y: Int): ULong { } @JvmInline -value class VPointF(private val data: ULong) { +value class VPointF(val data: ULong) { val x: Float get() = Float.fromBits(unpackX(data)) @@ -137,7 +137,7 @@ value class VPointF(private val data: ULong) { } @JvmInline -value class VPoint(private val data: ULong) { +value class VPoint(val data: ULong) { val x: Int get() = unpackX(data) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/VRect.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/VRect.kt index 8d8e3fbabc90..3c1adf22a405 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/VRect.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/VRect.kt @@ -41,7 +41,7 @@ private fun pack(left: Short, top: Short, right: Short, bottom: Short): ULong { } @JvmInline -value class VRectF(private val data: ULong) { +value class VRectF(val data: ULong) { val left: Float get() = fromBits(unpackLeft(data)) @@ -109,7 +109,7 @@ value class VRectF(private val data: ULong) { } @JvmInline -value class VRect(private val data: ULong) { +value class VRect(val data: ULong) { val left: Int get() = unpackLeft(data).toInt() @@ -138,6 +138,18 @@ value class VRect(private val data: ULong) { ) constructor( + left: Int, + top: Int, + right: Int, + bottom: Int, + ) : this( + left = left.toShort(), + top = top.toShort(), + right = right.toShort(), + bottom = bottom.toShort(), + ) + + constructor( left: Short, top: Short, right: Short, |