From 18c08045e9dd039b5a37925f9de7660a25bc93b6 Mon Sep 17 00:00:00 2001 From: Hawkwood Glazier Date: Sat, 21 May 2022 18:35:22 +0000 Subject: [PATCH] Migrate AnimatableClockView to SystemUISharedLib Attempt #2 Bug: 229771520 Test: Automated Change-Id: I93170c27d47017a81c4ef430823939fd0b9ec9c7 --- .../systemui/animation}/FontInterpolator.kt | 2 +- .../systemui/animation}/TextAnimator.kt | 6 +-- .../systemui/animation}/TextInterpolator.kt | 2 +- .../layout/keyguard_clock_switch.xml | 4 +- .../SystemUI/res-keyguard/values/attrs.xml | 6 --- .../res-keyguard/values/donottranslate.xml | 6 --- packages/SystemUI/shared/Android.bp | 1 + packages/SystemUI/shared/res/values/attrs.xml | 28 +++++++++++ .../shared/res/values/donottranslate.xml | 23 +++++++++ .../shared/clocks}/AnimatableClockView.kt | 47 ++++++++++--------- .../keyguard/AnimatableClockController.java | 32 +++++++------ .../android/keyguard/KeyguardClockSwitch.java | 1 + .../KeyguardClockSwitchController.java | 11 ----- .../KeyguardStatusViewController.java | 10 ---- .../stack/StackStateAnimator.java | 4 +- .../KeyguardClockSwitchControllerTest.java | 1 + .../keyguard/KeyguardClockSwitchTest.java | 1 + .../KeyguardStatusViewControllerTest.java | 22 --------- .../animation}/FontInterpolatorTest.kt | 2 +- .../animation}/TextAnimatorTest.kt | 2 +- .../animation}/TextInterpolatorTest.kt | 2 +- .../AnimatableClockControllerTest.java | 2 +- 22 files changed, 110 insertions(+), 105 deletions(-) rename packages/SystemUI/{src/com/android/keyguard => animation/src/com/android/systemui/animation}/FontInterpolator.kt (99%) rename packages/SystemUI/{src/com/android/keyguard => animation/src/com/android/systemui/animation}/TextAnimator.kt (98%) rename packages/SystemUI/{src/com/android/keyguard => animation/src/com/android/systemui/animation}/TextInterpolator.kt (99%) create mode 100644 packages/SystemUI/shared/res/values/attrs.xml create mode 100644 packages/SystemUI/shared/res/values/donottranslate.xml rename packages/SystemUI/{src/com/android/keyguard => shared/src/com/android/systemui/shared/clocks}/AnimatableClockView.kt (91%) rename packages/SystemUI/tests/src/com/android/{keyguard => systemui/animation}/FontInterpolatorTest.kt (99%) rename packages/SystemUI/tests/src/com/android/{keyguard => systemui/animation}/TextAnimatorTest.kt (99%) rename packages/SystemUI/tests/src/com/android/{keyguard => systemui/animation}/TextInterpolatorTest.kt (99%) diff --git a/packages/SystemUI/src/com/android/keyguard/FontInterpolator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/FontInterpolator.kt similarity index 99% rename from packages/SystemUI/src/com/android/keyguard/FontInterpolator.kt rename to packages/SystemUI/animation/src/com/android/systemui/animation/FontInterpolator.kt index 962c0023cf3b9..fbaf81678b633 100644 --- a/packages/SystemUI/src/com/android/keyguard/FontInterpolator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/FontInterpolator.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.keyguard +package com.android.systemui.animation import android.graphics.fonts.Font import android.graphics.fonts.FontVariationAxis diff --git a/packages/SystemUI/src/com/android/keyguard/TextAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt similarity index 98% rename from packages/SystemUI/src/com/android/keyguard/TextAnimator.kt rename to packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt index ade89af81bd7c..7d21124ca8077 100644 --- a/packages/SystemUI/src/com/android/keyguard/TextAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.keyguard +package com.android.systemui.animation import android.animation.Animator import android.animation.AnimatorListenerAdapter @@ -61,8 +61,8 @@ class TextAnimator( private val invalidateCallback: () -> Unit ) { // Following two members are for mutable for testing purposes. - internal var textInterpolator: TextInterpolator = TextInterpolator(layout) - internal var animator: ValueAnimator = ValueAnimator.ofFloat(1f).apply { + public var textInterpolator: TextInterpolator = TextInterpolator(layout) + public var animator: ValueAnimator = ValueAnimator.ofFloat(1f).apply { duration = DEFAULT_ANIMATION_DURATION addUpdateListener { textInterpolator.progress = it.animatedValue as Float diff --git a/packages/SystemUI/src/com/android/keyguard/TextInterpolator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/TextInterpolator.kt similarity index 99% rename from packages/SystemUI/src/com/android/keyguard/TextInterpolator.kt rename to packages/SystemUI/animation/src/com/android/systemui/animation/TextInterpolator.kt index 20dbe29efb35f..ff64c78911285 100644 --- a/packages/SystemUI/src/com/android/keyguard/TextInterpolator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/TextInterpolator.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.keyguard +package com.android.systemui.animation import android.graphics.Canvas import android.graphics.Paint diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml index 87a9825af1cb9..6a38507b2ad75 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml @@ -31,7 +31,7 @@ android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:paddingStart="@dimen/clock_padding_start"> - - - - - - - - diff --git a/packages/SystemUI/res-keyguard/values/donottranslate.xml b/packages/SystemUI/res-keyguard/values/donottranslate.xml index e677797dc4a7a..f9872f8da1920 100644 --- a/packages/SystemUI/res-keyguard/values/donottranslate.xml +++ b/packages/SystemUI/res-keyguard/values/donottranslate.xml @@ -23,11 +23,5 @@ MMMd - - hm - - - Hm - 1 diff --git a/packages/SystemUI/shared/Android.bp b/packages/SystemUI/shared/Android.bp index 114ea657a7583..165f9eba6f4c7 100644 --- a/packages/SystemUI/shared/Android.bp +++ b/packages/SystemUI/shared/Android.bp @@ -47,6 +47,7 @@ android_library { ], static_libs: [ "PluginCoreLib", + "SystemUIAnimationLib", "SystemUIUnfoldLib", "androidx.dynamicanimation_dynamicanimation", "androidx.concurrent_concurrent-futures", diff --git a/packages/SystemUI/shared/res/values/attrs.xml b/packages/SystemUI/shared/res/values/attrs.xml new file mode 100644 index 0000000000000..f9d66ee583da1 --- /dev/null +++ b/packages/SystemUI/shared/res/values/attrs.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + diff --git a/packages/SystemUI/shared/res/values/donottranslate.xml b/packages/SystemUI/shared/res/values/donottranslate.xml new file mode 100644 index 0000000000000..383d5521f1566 --- /dev/null +++ b/packages/SystemUI/shared/res/values/donottranslate.xml @@ -0,0 +1,23 @@ + + + + + + hm + + + Hm + diff --git a/packages/SystemUI/src/com/android/keyguard/AnimatableClockView.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt similarity index 91% rename from packages/SystemUI/src/com/android/keyguard/AnimatableClockView.kt rename to packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt index d44598049806d..57340234e5403 100644 --- a/packages/SystemUI/src/com/android/keyguard/AnimatableClockView.kt +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.keyguard +package com.android.systemui.shared.clocks import android.animation.TimeInterpolator import android.annotation.ColorInt @@ -27,9 +27,10 @@ import android.text.format.DateFormat import android.util.AttributeSet import android.util.Log import android.widget.TextView -import com.android.systemui.R import com.android.systemui.animation.Interpolators -import com.android.systemui.statusbar.notification.stack.StackStateAnimator +import com.android.systemui.animation.TextAnimator +import com.android.systemui.animation.GlyphCallback +import com.android.systemui.shared.R import java.io.PrintWriter import java.util.Calendar import java.util.Locale @@ -39,13 +40,13 @@ import java.util.TimeZone * Displays the time with the hour positioned above the minutes. (ie: 09 above 30 is 9:30) * The time's text color is a gradient that changes its colors based on its controller. */ +@SuppressLint("AppCompatCustomView") class AnimatableClockView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 ) : TextView(context, attrs, defStyleAttr, defStyleRes) { - private val tag = "AnimatableClockView" private var lastMeasureCall: CharSequence = "" @@ -134,7 +135,7 @@ class AnimatableClockView @JvmOverloads constructor( if (!TextUtils.equals(text, formattedText)) { text = formattedText Log.d( - tag, "refreshTime this=$this" + + TAG, "refreshTime this=$this" + " currTimeContextDesc=$contentDescription" + " measuredHeight=$measuredHeight" + " lastMeasureCall=$lastMeasureCall" + @@ -142,7 +143,7 @@ class AnimatableClockView @JvmOverloads constructor( ) } else { Log.d( - tag, "refreshTime (skipped due to unchanged text)" + + TAG, "refreshTime (skipped due to unchanged text)" + " this=$this" + " currTimeContextDesc=$contentDescription" + " measuredHeight=$measuredHeight" + @@ -169,7 +170,7 @@ class AnimatableClockView @JvmOverloads constructor( } else { animator.updateLayout(layout) } - Log.v(tag, "onMeasure this=$this" + + Log.v(TAG, "onMeasure this=$this" + " currTimeContextDesc=$contentDescription" + " heightMeasureSpecMode=${MeasureSpec.getMode(heightMeasureSpec)}" + " heightMeasureSpecSize=${MeasureSpec.getSize(heightMeasureSpec)}" + @@ -180,7 +181,7 @@ class AnimatableClockView @JvmOverloads constructor( override fun onDraw(canvas: Canvas) { // intentionally doesn't call super.onDraw here or else the text will be rendered twice - Log.d(tag, "onDraw this=$this" + + Log.d(TAG, "onDraw this=$this" + " currTimeContextDesc=$contentDescription" + " isSingleLineInternal=$isSingleLineInternal") textAnimator?.draw(canvas) @@ -220,7 +221,7 @@ class AnimatableClockView @JvmOverloads constructor( ) } - fun animateFoldAppear() { + fun animateFoldAppear(animate: Boolean = true) { if (textAnimator == null) { return } @@ -237,22 +238,22 @@ class AnimatableClockView @JvmOverloads constructor( weight = dozingWeightInternal, textSize = -1f, color = dozingColor, - animate = true, + animate = animate, interpolator = Interpolators.EMPHASIZED_DECELERATE, - duration = StackStateAnimator.ANIMATION_DURATION_FOLD_TO_AOD.toLong(), + duration = ANIMATION_DURATION_FOLD_TO_AOD.toLong(), delay = 0, onAnimationEnd = null ) } - fun animateCharge(dozeStateGetter: DozeStateGetter) { + fun animateCharge(isDozing: () -> Boolean) { if (textAnimator == null || textAnimator!!.isRunning()) { // Skip charge animation if dozing animation is already playing. return } val startAnimPhase2 = Runnable { setTextStyle( - weight = if (dozeStateGetter.isDozing) dozingWeight else lockScreenWeight, + weight = if (isDozing()) dozingWeight else lockScreenWeight, textSize = -1f, color = null, animate = true, @@ -262,7 +263,7 @@ class AnimatableClockView @JvmOverloads constructor( ) } setTextStyle( - weight = if (dozeStateGetter.isDozing) lockScreenWeight else dozingWeight, + weight = if (isDozing()) lockScreenWeight else dozingWeight, textSize = -1f, color = null, animate = true, @@ -412,14 +413,14 @@ class AnimatableClockView @JvmOverloads constructor( } } - interface DozeStateGetter { - val isDozing: Boolean + companion object { + private val TAG = AnimatableClockView::class.simpleName + const val ANIMATION_DURATION_FOLD_TO_AOD: Int = 600 + private const val DOUBLE_LINE_FORMAT_12_HOUR = "hh\nmm" + private const val DOUBLE_LINE_FORMAT_24_HOUR = "HH\nmm" + private const val DOZE_ANIM_DURATION: Long = 300 + private const val APPEAR_ANIM_DURATION: Long = 350 + private const val CHARGE_ANIM_DURATION_PHASE_0: Long = 500 + private const val CHARGE_ANIM_DURATION_PHASE_1: Long = 1000 } } - -private const val DOUBLE_LINE_FORMAT_12_HOUR = "hh\nmm" -private const val DOUBLE_LINE_FORMAT_24_HOUR = "HH\nmm" -private const val DOZE_ANIM_DURATION: Long = 300 -private const val APPEAR_ANIM_DURATION: Long = 350 -private const val CHARGE_ANIM_DURATION_PHASE_0: Long = 500 -private const val CHARGE_ANIM_DURATION_PHASE_1: Long = 1000 diff --git a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java index 3c4c1b6dc2d12..1c8ffb9b56b24 100644 --- a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java +++ b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java @@ -33,6 +33,7 @@ import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.plugins.statusbar.StatusBarStateController; +import com.android.systemui.shared.clocks.AnimatableClockView; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.util.ViewController; @@ -135,6 +136,21 @@ public class AnimatableClockController extends ViewController