From 82cec88397fb885a3d52f24162c9ca7725c91a06 Mon Sep 17 00:00:00 2001 From: Jamie Garside Date: Tue, 13 Sep 2022 00:15:13 +0100 Subject: [PATCH] Add large screen clock motion - method 2. When the clock moves on a large screen (e.g. when locking/unlocking the device), this adds a subtle offset for each digit of the clock. This hooks a new transition in to the existing clock move transition, which just forwards progress through to the actual clock. This also adds a feature flag (210) to enable/disable this, since it needs a little more polish yet. As above, this needs more polish (tweaking the time and/or easing), but this at least gets something moving to start with :). Bug: 199051139 Test: Manually verified. Change-Id: Icec0bcfdb431d24b9405c5dfe8993016f687cac5 --- .../systemui/animation/TextAnimator.kt | 8 + .../systemui/animation/TextInterpolator.kt | 8 +- .../systemui/plugins/ClockProviderPlugin.kt | 12 ++ .../layout/keyguard_clock_switch.xml | 1 + .../shared/clocks/AnimatableClockView.kt | 175 +++++++++++++++++- .../shared/clocks/DefaultClockController.kt | 12 ++ .../KeyguardClockSwitchController.java | 7 +- .../KeyguardStatusViewController.java | 6 + .../src/com/android/systemui/flags/Flags.java | 6 + .../NotificationPanelViewController.java | 86 ++++++++- .../KeyguardClockSwitchControllerTest.java | 15 ++ .../KeyguardStatusViewControllerTest.java | 16 ++ 12 files changed, 344 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt index 6780fb7fafe37..65d6c83d74a8f 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt @@ -82,6 +82,14 @@ class TextAnimator(layout: Layout, private val invalidateCallback: () -> Unit) { /** Mutable Y coordinate of the glyph position relative from the baseline. */ var y: Float = 0f + /** + * The current line of text being drawn, in a multi-line TextView. + */ + var lineNo: Int = 0 + + /** + * Mutable text size of the glyph in pixels. + */ /** Mutable text size of the glyph in pixels. */ var textSize: Float = 0f diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/TextInterpolator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/TextInterpolator.kt index db14fdf5930b7..f9fb42cd1670a 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/TextInterpolator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/TextInterpolator.kt @@ -231,7 +231,9 @@ class TextInterpolator(layout: Layout) { val origin = layout.getDrawOrigin(lineNo) canvas.translate(origin, layout.getLineBaseline(lineNo).toFloat()) - run.fontRuns.forEach { fontRun -> drawFontRun(canvas, run, fontRun, tmpPaint) } + run.fontRuns.forEach { fontRun -> + drawFontRun(canvas, run, fontRun, lineNo, tmpPaint) + } } finally { canvas.restore() } @@ -341,7 +343,7 @@ class TextInterpolator(layout: Layout) { var glyphFilter: GlyphCallback? = null // Draws single font run. - private fun drawFontRun(c: Canvas, line: Run, run: FontRun, paint: Paint) { + private fun drawFontRun(c: Canvas, line: Run, run: FontRun, lineNo: Int, paint: Paint) { var arrayIndex = 0 val font = fontInterpolator.lerp(run.baseFont, run.targetFont, progress) @@ -360,11 +362,13 @@ class TextInterpolator(layout: Layout) { tmpGlyph.font = font tmpGlyph.runStart = run.start tmpGlyph.runLength = run.end - run.start + tmpGlyph.lineNo = lineNo tmpPaintForGlyph.set(paint) var prevStart = run.start for (i in run.start until run.end) { + tmpGlyph.glyphIndex = i tmpGlyph.glyphId = line.glyphIds[i] tmpGlyph.x = MathUtils.lerp(line.baseX[i], line.targetX[i], progress) tmpGlyph.y = MathUtils.lerp(line.baseY[i], line.targetY[i], progress) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt index 1e74c3d68efc2..dabb43b6074d3 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/ClockProviderPlugin.kt @@ -14,6 +14,7 @@ package com.android.systemui.plugins import android.content.res.Resources +import android.graphics.Rect import android.graphics.drawable.Drawable import android.view.View import com.android.systemui.plugins.annotations.ProvidesInterface @@ -114,6 +115,17 @@ interface ClockAnimations { /** Runs the battery animation (if any). */ fun charge() { } + + /** Move the clock, for example, if the notification tray appears in split-shade mode. */ + fun onPositionUpdated(fromRect: Rect, toRect: Rect, fraction: Float) { } + + /** + * Whether this clock has a custom position update animation. If true, the keyguard will call + * `onPositionUpdated` to notify the clock of a position update animation. If false, a default + * animation will be used (e.g. a simple translation). + */ + val hasCustomPositionUpdatedAnimation + get() = false } /** Events that have specific data about the related face */ diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml index 3ad7c8c4369ca..d64587dcf362f 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml @@ -37,6 +37,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="@dimen/keyguard_large_clock_top_margin" + android:clipChildren="false" android:visibility="gone" />