From 8485dc1b859da85998a78e57ce1b88e303b733f5 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 Bug: 229771520 Test: Automated Change-Id: I93170c27d47017a81c4ef430823939fd0b9ec9c7 Merged-In: I93170c27d47017a81c4ef430823939fd0b9ec9c7 --- .../systemui/animation}/FontInterpolator.kt | 4 +- .../systemui/animation}/TextAnimator.kt | 8 ++-- .../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 | 39 ++++++++++--------- .../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 | 7 ++-- .../animation}/TextInterpolatorTest.kt | 8 ++-- .../AnimatableClockControllerTest.java | 2 +- 22 files changed, 113 insertions(+), 109 deletions(-) rename packages/SystemUI/{src/com/android/keyguard => animation/src/com/android/systemui/animation}/FontInterpolator.kt (98%) 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 (92%) 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 98% rename from packages/SystemUI/src/com/android/keyguard/FontInterpolator.kt rename to packages/SystemUI/animation/src/com/android/systemui/animation/FontInterpolator.kt index 962c0023cf3b9..3d341af3b3970 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 @@ -61,7 +61,7 @@ class FontInterpolator { var index: Int, val sortedAxes: MutableList ) { - constructor(font: Font, axes: List): + constructor(font: Font, axes: List) : this(font.sourceIdentifier, font.ttcIndex, axes.toMutableList().apply { sortBy { it.tag } } 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..f79b328190dd3 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 @@ -279,4 +279,4 @@ private fun SparseArray.getOrElse(key: Int, defaultValue: () -> V): V { put(key, v) } return v -} \ No newline at end of file +} 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 92% rename from packages/SystemUI/src/com/android/keyguard/AnimatableClockView.kt rename to packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt index b4955d28f84b8..5b1a23d4f364a 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 @@ -26,9 +26,10 @@ import android.text.TextUtils import android.text.format.DateFormat import android.util.AttributeSet import android.widget.TextView -import com.android.systemui.R +import com.android.systemui.animation.GlyphCallback import com.android.systemui.animation.Interpolators -import com.android.systemui.statusbar.notification.stack.StackStateAnimator +import com.android.systemui.animation.TextAnimator +import com.android.systemui.shared.R import java.io.PrintWriter import java.util.Calendar import java.util.Locale @@ -38,13 +39,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 = "" @@ -193,7 +194,7 @@ class AnimatableClockView @JvmOverloads constructor( ) } - fun animateFoldAppear() { + fun animateFoldAppear(animate: Boolean = true) { if (textAnimator == null) { return } @@ -210,22 +211,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, @@ -235,7 +236,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, @@ -385,14 +386,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 487e1a48044c0..c69ff7ee1cd80 100644 --- a/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java +++ b/packages/SystemUI/src/com/android/keyguard/AnimatableClockController.java @@ -32,6 +32,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; @@ -134,6 +135,21 @@ public class AnimatableClockController extends ViewController