Merge "Migrate AnimatableClockView to SystemUISharedLib" into tm-qpr-dev

This commit is contained in:
Hawkwood Glazier
2022-07-26 18:22:47 +00:00
committed by Android (Google) Code Review
22 changed files with 113 additions and 109 deletions

View File

@@ -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<FontVariationAxis>
) {
constructor(font: Font, axes: List<FontVariationAxis>):
constructor(font: Font, axes: List<FontVariationAxis>) :
this(font.sourceIdentifier,
font.ttcIndex,
axes.toMutableList().apply { sortBy { it.tag } }

View File

@@ -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 <V> SparseArray<V>.getOrElse(key: Int, defaultValue: () -> V): V {
put(key, v)
}
return v
}
}

View File

@@ -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

View File

@@ -31,7 +31,7 @@
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:paddingStart="@dimen/clock_padding_start">
<com.android.keyguard.AnimatableClockView
<com.android.systemui.shared.clocks.AnimatableClockView
android:id="@+id/animatable_clock_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -53,7 +53,7 @@
android:layout_height="wrap_content"
android:layout_below="@id/keyguard_slice_view"
android:visibility="gone">
<com.android.keyguard.AnimatableClockView
<com.android.systemui.shared.clocks.AnimatableClockView
android:id="@+id/animatable_clock_view_large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@@ -41,10 +41,4 @@
<attr name="passwordStyle" format="reference" />
<attr name="numPadKeyStyle" format="reference" />
<declare-styleable name="AnimatableClockView">
<attr name="dozeWeight" format="integer" />
<attr name="lockScreenWeight" format="integer" />
<attr name="chargeAnimationDelay" format="integer" />
</declare-styleable>
</resources>

View File

@@ -23,11 +23,5 @@
<!-- Skeleton string format for displaying the date shorter. -->
<string name="abbrev_month_day_no_year">MMMd</string>
<!-- Skeleton string format for displaying the time in 12-hour format. -->
<string name="clock_12hr_format">hm</string>
<!-- Skeleton string format for displaying the time in 24-hour format. -->
<string name="clock_24hr_format">Hm</string>
<string name="num_pad_key_ratio">1</string>
</resources>

View File

@@ -47,6 +47,7 @@ android_library {
],
static_libs: [
"PluginCoreLib",
"SystemUIAnimationLib",
"SystemUIUnfoldLib",
"androidx.dynamicanimation_dynamicanimation",
"androidx.concurrent_concurrent-futures",

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Formatting note: terminate all comments with a period, to avoid breaking
the documentation output. To suppress comment lines from the documentation
output, insert an eat-comment element after the comment lines.
-->
<resources>
<declare-styleable name="AnimatableClockView">
<attr name="dozeWeight" format="integer" />
<attr name="lockScreenWeight" format="integer" />
<attr name="chargeAnimationDelay" format="integer" />
</declare-styleable>
</resources>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Skeleton string format for displaying the time in 12-hour format. -->
<string name="clock_12hr_format">hm</string>
<!-- Skeleton string format for displaying the time in 24-hour format. -->
<string name="clock_24hr_format">Hm</string>
</resources>

View File

@@ -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

View File

@@ -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<AnimatableClockVie
reset();
}
}
@Override
public void onTimeFormatChanged(String timeFormat) {
mView.refreshFormat();
}
@Override
public void onTimeZoneChanged(TimeZone timeZone) {
mView.onTimeZoneChanged(timeZone);
}
@Override
public void onUserSwitchComplete(int userId) {
mView.refreshFormat();
}
};
@Override
@@ -186,7 +202,7 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
/** Animate the clock appearance when a foldable device goes from fully-open/half-open state to
* fully folded state and it goes to sleep (always on display screen) */
public void animateFoldAppear() {
mView.animateFoldAppear();
mView.animateFoldAppear(true);
}
/**
@@ -196,20 +212,6 @@ public class AnimatableClockController extends ViewController<AnimatableClockVie
mView.refreshTime();
}
/**
* Updates the timezone for the view.
*/
public void onTimeZoneChanged(TimeZone timeZone) {
mView.onTimeZoneChanged(timeZone);
}
/**
* Trigger a time format update
*/
public void refreshFormat() {
mView.refreshFormat();
}
/**
* Return locallly stored dozing state.
*/

View File

@@ -22,6 +22,7 @@ import com.android.keyguard.dagger.KeyguardStatusViewScope;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.plugins.ClockPlugin;
import com.android.systemui.shared.clocks.AnimatableClockView;
import java.io.PrintWriter;
import java.lang.annotation.Retention;

View File

@@ -398,17 +398,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
void updateTimeZone(TimeZone timeZone) {
mView.onTimeZoneChanged(timeZone);
if (mClockViewController != null) {
mClockViewController.onTimeZoneChanged(timeZone);
mLargeClockViewController.onTimeZoneChanged(timeZone);
}
}
void refreshFormat() {
if (mClockViewController != null) {
mClockViewController.refreshFormat();
mLargeClockViewController.refreshFormat();
}
}
/**

View File

@@ -239,11 +239,6 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
refreshTime();
}
@Override
public void onTimeFormatChanged(String timeFormat) {
mKeyguardClockSwitchController.refreshFormat();
}
@Override
public void onTimeZoneChanged(TimeZone timeZone) {
mKeyguardClockSwitchController.updateTimeZone(timeZone);
@@ -256,11 +251,6 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
refreshTime();
}
}
@Override
public void onUserSwitchComplete(int userId) {
mKeyguardClockSwitchController.refreshFormat();
}
};
/**

View File

@@ -25,6 +25,7 @@ import android.view.View;
import com.android.keyguard.KeyguardSliceView;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.shared.clocks.AnimatableClockView;
import com.android.systemui.statusbar.NotificationShelf;
import com.android.systemui.statusbar.StatusBarIconView;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -52,7 +53,8 @@ public class StackStateAnimator {
public static final int ANIMATION_DURATION_CLOSE_REMOTE_INPUT = 150;
public static final int ANIMATION_DURATION_HEADS_UP_APPEAR = 400;
public static final int ANIMATION_DURATION_HEADS_UP_DISAPPEAR = 400;
public static final int ANIMATION_DURATION_FOLD_TO_AOD = 600;
public static final int ANIMATION_DURATION_FOLD_TO_AOD =
AnimatableClockView.ANIMATION_DURATION_FOLD_TO_AOD;
public static final int ANIMATION_DURATION_PULSE_APPEAR =
KeyguardSliceView.DEFAULT_ANIM_DURATION;
public static final int ANIMATION_DURATION_BLOCKING_HELPER_FADE = 240;

View File

@@ -51,6 +51,7 @@ import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
import com.android.systemui.plugins.ClockPlugin;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.shared.clocks.AnimatableClockView;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController;
import com.android.systemui.statusbar.phone.KeyguardBypassController;

View File

@@ -43,6 +43,7 @@ import android.widget.TextClock;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.ClockPlugin;
import com.android.systemui.shared.clocks.AnimatableClockView;
import com.android.systemui.statusbar.StatusBarState;
import org.junit.Before;

View File

@@ -88,28 +88,6 @@ public class KeyguardStatusViewControllerTest extends SysuiTestCase {
verify(mKeyguardClockSwitchController).refresh();
}
@Test
public void timeFormatUpdateNotifiesClockSwitchController() {
mController.onViewAttached();
verify(mKeyguardUpdateMonitor).registerCallback(
mKeyguardUpdateMonitorCallbackCaptor.capture());
mKeyguardUpdateMonitorCallbackCaptor.getValue().onTimeFormatChanged("");
verify(mKeyguardClockSwitchController).refreshFormat();
}
@Test
public void userChangeNotifiesClockSwitchController() {
mController.onViewAttached();
verify(mKeyguardUpdateMonitor).registerCallback(
mKeyguardUpdateMonitorCallbackCaptor.capture());
mKeyguardUpdateMonitorCallbackCaptor.getValue().onUserSwitchComplete(0);
verify(mKeyguardClockSwitchController).refreshFormat();
}
@Test
public void setTranslationYExcludingMedia_forwardsCallToView() {
float translationY = 123f;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.keyguard
package com.android.systemui.animation
import android.graphics.Paint
import android.graphics.fonts.Font

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.keyguard
package com.android.systemui.animation
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
@@ -26,18 +26,17 @@ import android.text.TextPaint
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import kotlin.math.ceil
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.Mockito.`when`
import org.mockito.Mockito.eq
import org.mockito.Mockito.inOrder
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import kotlin.math.ceil
import org.mockito.Mockito.`when`
private val PAINT = TextPaint().apply {
textSize = 32f

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.keyguard
package com.android.systemui.animation
import android.graphics.Bitmap
import android.graphics.Canvas
@@ -31,10 +31,10 @@ import android.text.TextPaint
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File
import kotlin.math.ceil
import org.junit.Test
import org.junit.runner.RunWith
private const val TEXT = "Hello, World."
private const val BIDI_TEXT = "abc\u05D0\u05D1\u05D2"
@@ -323,4 +323,4 @@ private fun Layout.toBitmap(width: Int, height: Int) =
Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).also { draw(Canvas(it)) }!!
private fun TextInterpolator.toBitmap(width: Int, height: Int) =
Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).also { draw(Canvas(it)) }
Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).also { draw(Canvas(it)) }

View File

@@ -34,12 +34,12 @@ import android.view.View;
import androidx.test.filters.SmallTest;
import com.android.keyguard.AnimatableClockController;
import com.android.keyguard.AnimatableClockView;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.settingslib.Utils;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.shared.clocks.AnimatableClockView;
import com.android.systemui.statusbar.policy.BatteryController;
import org.junit.After;