diff options
7 files changed, 128 insertions, 89 deletions
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 4cda8c7b5328..6d88e512eddb 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -773,15 +773,11 @@ <integer name="complicationFadeOutDelayMs">200</integer> <!-- Duration in milliseconds of the dream in un-blur animation. --> - <integer name="config_dreamOverlayInBlurDurationMs">249</integer> - <!-- Delay in milliseconds of the dream in un-blur animation. --> - <integer name="config_dreamOverlayInBlurDelayMs">133</integer> + <integer name="config_dreamOverlayInBlurDurationMs">250</integer> <!-- Duration in milliseconds of the dream in complications fade-in animation. --> - <integer name="config_dreamOverlayInComplicationsDurationMs">282</integer> - <!-- Delay in milliseconds of the dream in top complications fade-in animation. --> - <integer name="config_dreamOverlayInTopComplicationsDelayMs">216</integer> - <!-- Delay in milliseconds of the dream in bottom complications fade-in animation. --> - <integer name="config_dreamOverlayInBottomComplicationsDelayMs">299</integer> + <integer name="config_dreamOverlayInComplicationsDurationMs">250</integer> + <!-- Duration in milliseconds of the y-translation animation when entering a dream --> + <integer name="config_dreamOverlayInTranslationYDurationMs">917</integer> <!-- Icons that don't show in a collapsed non-keyguard statusbar --> <string-array name="config_collapsed_statusbar_icon_blocklist" translatable="false"> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 35ada47d9586..e8a8534581d2 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1507,6 +1507,8 @@ <dimen name="dream_overlay_status_bar_extra_margin">8dp</dimen> <!-- Dream overlay complications related dimensions --> + <!-- The blur radius applied to the dream overlay when entering and exiting dreams --> + <dimen name="dream_overlay_anim_blur_radius">50dp</dimen> <dimen name="dream_overlay_complication_clock_time_text_size">86dp</dimen> <dimen name="dream_overlay_complication_clock_time_translation_y">28dp</dimen> <dimen name="dream_overlay_complication_home_controls_padding">28dp</dimen> @@ -1560,6 +1562,7 @@ <dimen name="dream_overlay_complication_margin">0dp</dimen> <dimen name="dream_overlay_y_offset">80dp</dimen> + <dimen name="dream_overlay_entry_y_offset">40dp</dimen> <dimen name="dream_overlay_exit_y_offset">40dp</dimen> <dimen name="status_view_margin_horizontal">0dp</dimen> diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt index 0087c8439370..9b8ef71882e9 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt @@ -21,11 +21,12 @@ import android.animation.AnimatorSet import android.animation.ValueAnimator import android.view.View import android.view.animation.Interpolator -import androidx.annotation.FloatRange import androidx.core.animation.doOnEnd import com.android.systemui.animation.Interpolators import com.android.systemui.dreams.complication.ComplicationHostViewController import com.android.systemui.dreams.complication.ComplicationLayoutParams +import com.android.systemui.dreams.complication.ComplicationLayoutParams.POSITION_BOTTOM +import com.android.systemui.dreams.complication.ComplicationLayoutParams.POSITION_TOP import com.android.systemui.dreams.complication.ComplicationLayoutParams.Position import com.android.systemui.dreams.dagger.DreamOverlayModule import com.android.systemui.statusbar.BlurUtils @@ -41,16 +42,15 @@ constructor( private val mComplicationHostViewController: ComplicationHostViewController, private val mStatusBarViewController: DreamOverlayStatusBarViewController, private val mOverlayStateController: DreamOverlayStateController, + @Named(DreamOverlayModule.DREAM_BLUR_RADIUS) private val mDreamBlurRadius: Int, @Named(DreamOverlayModule.DREAM_IN_BLUR_ANIMATION_DURATION) private val mDreamInBlurAnimDurationMs: Long, - @Named(DreamOverlayModule.DREAM_IN_BLUR_ANIMATION_DELAY) - private val mDreamInBlurAnimDelayMs: Long, @Named(DreamOverlayModule.DREAM_IN_COMPLICATIONS_ANIMATION_DURATION) private val mDreamInComplicationsAnimDurationMs: Long, - @Named(DreamOverlayModule.DREAM_IN_TOP_COMPLICATIONS_ANIMATION_DELAY) - private val mDreamInTopComplicationsAnimDelayMs: Long, - @Named(DreamOverlayModule.DREAM_IN_BOTTOM_COMPLICATIONS_ANIMATION_DELAY) - private val mDreamInBottomComplicationsAnimDelayMs: Long, + @Named(DreamOverlayModule.DREAM_IN_TRANSLATION_Y_DISTANCE) + private val mDreamInTranslationYDistance: Int, + @Named(DreamOverlayModule.DREAM_IN_TRANSLATION_Y_DURATION) + private val mDreamInTranslationYDurationMs: Long, @Named(DreamOverlayModule.DREAM_OUT_TRANSLATION_Y_DISTANCE) private val mDreamOutTranslationYDistance: Int, @Named(DreamOverlayModule.DREAM_OUT_TRANSLATION_Y_DURATION) @@ -74,7 +74,7 @@ constructor( */ private var mCurrentAlphaAtPosition = mutableMapOf<Int, Float>() - @FloatRange(from = 0.0, to = 1.0) private var mBlurProgress: Float = 0f + private var mCurrentBlurRadius: Float = 0f /** Starts the dream content and dream overlay entry animations. */ @JvmOverloads @@ -86,25 +86,23 @@ constructor( playTogether( blurAnimator( view = view, - from = 1f, - to = 0f, + fromBlurRadius = mDreamBlurRadius.toFloat(), + toBlurRadius = 0f, durationMs = mDreamInBlurAnimDurationMs, - delayMs = mDreamInBlurAnimDelayMs + interpolator = Interpolators.EMPHASIZED_DECELERATE ), alphaAnimator( from = 0f, to = 1f, durationMs = mDreamInComplicationsAnimDurationMs, - delayMs = mDreamInTopComplicationsAnimDelayMs, - position = ComplicationLayoutParams.POSITION_TOP + interpolator = Interpolators.LINEAR + ), + translationYAnimator( + from = mDreamInTranslationYDistance.toFloat(), + to = 0f, + durationMs = mDreamInTranslationYDurationMs, + interpolator = Interpolators.EMPHASIZED_DECELERATE ), - alphaAnimator( - from = 0f, - to = 1f, - durationMs = mDreamInComplicationsAnimDurationMs, - delayMs = mDreamInBottomComplicationsAnimDelayMs, - position = ComplicationLayoutParams.POSITION_BOTTOM - ) ) doOnEnd { mAnimator = null @@ -130,47 +128,48 @@ constructor( view = view, // Start the blurring wherever the entry animation ended, in // case it was cancelled early. - from = mBlurProgress, - to = 1f, - durationMs = mDreamOutBlurDurationMs + fromBlurRadius = mCurrentBlurRadius, + toBlurRadius = mDreamBlurRadius.toFloat(), + durationMs = mDreamOutBlurDurationMs, + interpolator = Interpolators.EMPHASIZED_ACCELERATE ), translationYAnimator( from = 0f, to = mDreamOutTranslationYDistance.toFloat(), durationMs = mDreamOutTranslationYDurationMs, delayMs = mDreamOutTranslationYDelayBottomMs, - position = ComplicationLayoutParams.POSITION_BOTTOM, - animInterpolator = Interpolators.EMPHASIZED_ACCELERATE + positions = POSITION_BOTTOM, + interpolator = Interpolators.EMPHASIZED_ACCELERATE ), translationYAnimator( from = 0f, to = mDreamOutTranslationYDistance.toFloat(), durationMs = mDreamOutTranslationYDurationMs, delayMs = mDreamOutTranslationYDelayTopMs, - position = ComplicationLayoutParams.POSITION_TOP, - animInterpolator = Interpolators.EMPHASIZED_ACCELERATE + positions = POSITION_TOP, + interpolator = Interpolators.EMPHASIZED_ACCELERATE ), alphaAnimator( from = mCurrentAlphaAtPosition.getOrDefault( - key = ComplicationLayoutParams.POSITION_BOTTOM, + key = POSITION_BOTTOM, defaultValue = 1f ), to = 0f, durationMs = mDreamOutAlphaDurationMs, delayMs = mDreamOutAlphaDelayBottomMs, - position = ComplicationLayoutParams.POSITION_BOTTOM + positions = POSITION_BOTTOM ), alphaAnimator( from = mCurrentAlphaAtPosition.getOrDefault( - key = ComplicationLayoutParams.POSITION_TOP, + key = POSITION_TOP, defaultValue = 1f ), to = 0f, durationMs = mDreamOutAlphaDurationMs, delayMs = mDreamOutAlphaDelayTopMs, - position = ComplicationLayoutParams.POSITION_TOP + positions = POSITION_TOP ) ) doOnEnd { @@ -194,20 +193,21 @@ constructor( private fun blurAnimator( view: View, - from: Float, - to: Float, + fromBlurRadius: Float, + toBlurRadius: Float, durationMs: Long, - delayMs: Long = 0 + delayMs: Long = 0, + interpolator: Interpolator = Interpolators.LINEAR ): Animator { - return ValueAnimator.ofFloat(from, to).apply { + return ValueAnimator.ofFloat(fromBlurRadius, toBlurRadius).apply { duration = durationMs startDelay = delayMs - interpolator = Interpolators.LINEAR + this.interpolator = interpolator addUpdateListener { animator: ValueAnimator -> - mBlurProgress = animator.animatedValue as Float + mCurrentBlurRadius = animator.animatedValue as Float mBlurUtils.applyBlur( viewRootImpl = view.viewRootImpl, - radius = mBlurUtils.blurRadiusOfRatio(mBlurProgress).toInt(), + radius = mCurrentBlurRadius.toInt(), opaque = false ) } @@ -218,18 +218,24 @@ constructor( from: Float, to: Float, durationMs: Long, - delayMs: Long, - @Position position: Int + delayMs: Long = 0, + @Position positions: Int = POSITION_TOP or POSITION_BOTTOM, + interpolator: Interpolator = Interpolators.LINEAR ): Animator { return ValueAnimator.ofFloat(from, to).apply { duration = durationMs startDelay = delayMs - interpolator = Interpolators.LINEAR + this.interpolator = interpolator addUpdateListener { va: ValueAnimator -> - setElementsAlphaAtPosition( - alpha = va.animatedValue as Float, - position = position, - fadingOut = to < from + ComplicationLayoutParams.iteratePositions( + { position: Int -> + setElementsAlphaAtPosition( + alpha = va.animatedValue as Float, + position = position, + fadingOut = to < from + ) + }, + positions ) } } @@ -239,16 +245,21 @@ constructor( from: Float, to: Float, durationMs: Long, - delayMs: Long, - @Position position: Int, - animInterpolator: Interpolator + delayMs: Long = 0, + @Position positions: Int = POSITION_TOP or POSITION_BOTTOM, + interpolator: Interpolator = Interpolators.LINEAR ): Animator { return ValueAnimator.ofFloat(from, to).apply { duration = durationMs startDelay = delayMs - interpolator = animInterpolator + this.interpolator = interpolator addUpdateListener { va: ValueAnimator -> - setElementsTranslationYAtPosition(va.animatedValue as Float, position) + ComplicationLayoutParams.iteratePositions( + { position: Int -> + setElementsTranslationYAtPosition(va.animatedValue as Float, position) + }, + positions + ) } } } @@ -263,7 +274,7 @@ constructor( CrossFadeHelper.fadeIn(view, alpha, /* remap= */ false) } } - if (position == ComplicationLayoutParams.POSITION_TOP) { + if (position == POSITION_TOP) { mStatusBarViewController.setFadeAmount(alpha, fadingOut) } } @@ -273,7 +284,7 @@ constructor( mComplicationHostViewController.getViewsAtPosition(position).forEach { v -> v.translationY = translationY } - if (position == ComplicationLayoutParams.POSITION_TOP) { + if (position == POSITION_TOP) { mStatusBarViewController.setTranslationY(translationY) } } diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java index 1755cb92da70..99e19fc96d8f 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java @@ -251,9 +251,17 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { * position specified for this {@link ComplicationLayoutParams}. */ public void iteratePositions(Consumer<Integer> consumer) { + iteratePositions(consumer, mPosition); + } + + /** + * Iterates over the defined positions and invokes the specified {@link Consumer} for each + * position specified by the given {@code position}. + */ + public static void iteratePositions(Consumer<Integer> consumer, @Position int position) { for (int currentPosition = FIRST_POSITION; currentPosition <= LAST_POSITION; currentPosition <<= 1) { - if ((mPosition & currentPosition) == currentPosition) { + if ((position & currentPosition) == currentPosition) { consumer.accept(currentPosition); } } diff --git a/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayModule.java b/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayModule.java index ed0e1d97e40a..4f1ac1a8abd5 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayModule.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/dagger/DreamOverlayModule.java @@ -47,14 +47,14 @@ public abstract class DreamOverlayModule { public static final String BURN_IN_PROTECTION_UPDATE_INTERVAL = "burn_in_protection_update_interval"; public static final String MILLIS_UNTIL_FULL_JITTER = "millis_until_full_jitter"; + public static final String DREAM_BLUR_RADIUS = "DREAM_BLUR_RADIUS"; public static final String DREAM_IN_BLUR_ANIMATION_DURATION = "dream_in_blur_anim_duration"; - public static final String DREAM_IN_BLUR_ANIMATION_DELAY = "dream_in_blur_anim_delay"; public static final String DREAM_IN_COMPLICATIONS_ANIMATION_DURATION = "dream_in_complications_anim_duration"; - public static final String DREAM_IN_TOP_COMPLICATIONS_ANIMATION_DELAY = - "dream_in_top_complications_anim_delay"; - public static final String DREAM_IN_BOTTOM_COMPLICATIONS_ANIMATION_DELAY = - "dream_in_bottom_complications_anim_delay"; + public static final String DREAM_IN_TRANSLATION_Y_DISTANCE = + "dream_in_complications_translation_y"; + public static final String DREAM_IN_TRANSLATION_Y_DURATION = + "dream_in_complications_translation_y_duration"; public static final String DREAM_OUT_TRANSLATION_Y_DISTANCE = "dream_out_complications_translation_y"; public static final String DREAM_OUT_TRANSLATION_Y_DURATION = @@ -139,21 +139,21 @@ public abstract class DreamOverlayModule { } /** - * Duration in milliseconds of the dream in un-blur animation. + * The blur radius applied to the dream overlay at dream entry and exit. */ @Provides - @Named(DREAM_IN_BLUR_ANIMATION_DURATION) - static long providesDreamInBlurAnimationDuration(@Main Resources resources) { - return (long) resources.getInteger(R.integer.config_dreamOverlayInBlurDurationMs); + @Named(DREAM_BLUR_RADIUS) + static int providesDreamBlurRadius(@Main Resources resources) { + return resources.getDimensionPixelSize(R.dimen.dream_overlay_anim_blur_radius); } /** - * Delay in milliseconds of the dream in un-blur animation. + * Duration in milliseconds of the dream in un-blur animation. */ @Provides - @Named(DREAM_IN_BLUR_ANIMATION_DELAY) - static long providesDreamInBlurAnimationDelay(@Main Resources resources) { - return (long) resources.getInteger(R.integer.config_dreamOverlayInBlurDelayMs); + @Named(DREAM_IN_BLUR_ANIMATION_DURATION) + static long providesDreamInBlurAnimationDuration(@Main Resources resources) { + return (long) resources.getInteger(R.integer.config_dreamOverlayInBlurDurationMs); } /** @@ -166,22 +166,23 @@ public abstract class DreamOverlayModule { } /** - * Delay in milliseconds of the dream in top complications fade-in animation. + * Provides the number of pixels to translate complications when entering a dream. */ @Provides - @Named(DREAM_IN_TOP_COMPLICATIONS_ANIMATION_DELAY) - static long providesDreamInTopComplicationsAnimationDelay(@Main Resources resources) { - return (long) resources.getInteger(R.integer.config_dreamOverlayInTopComplicationsDelayMs); + @Named(DREAM_IN_TRANSLATION_Y_DISTANCE) + @DreamOverlayComponent.DreamOverlayScope + static int providesDreamInComplicationsTranslationY(@Main Resources resources) { + return resources.getDimensionPixelSize(R.dimen.dream_overlay_entry_y_offset); } /** - * Delay in milliseconds of the dream in bottom complications fade-in animation. + * Provides the duration in ms of the y-translation when dream enters. */ @Provides - @Named(DREAM_IN_BOTTOM_COMPLICATIONS_ANIMATION_DELAY) - static long providesDreamInBottomComplicationsAnimationDelay(@Main Resources resources) { - return (long) resources.getInteger( - R.integer.config_dreamOverlayInBottomComplicationsDelayMs); + @Named(DREAM_IN_TRANSLATION_Y_DURATION) + @DreamOverlayComponent.DreamOverlayScope + static long providesDreamInComplicationsTranslationYDuration(@Main Resources resources) { + return (long) resources.getInteger(R.integer.config_dreamOverlayInTranslationYDurationMs); } /** diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayAnimationsControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayAnimationsControllerTest.kt index 99406ed44606..8e689cf8f17e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayAnimationsControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayAnimationsControllerTest.kt @@ -23,11 +23,11 @@ import org.mockito.MockitoAnnotations class DreamOverlayAnimationsControllerTest : SysuiTestCase() { companion object { + private const val DREAM_BLUR_RADIUS = 50 private const val DREAM_IN_BLUR_ANIMATION_DURATION = 1L - private const val DREAM_IN_BLUR_ANIMATION_DELAY = 2L private const val DREAM_IN_COMPLICATIONS_ANIMATION_DURATION = 3L - private const val DREAM_IN_TOP_COMPLICATIONS_ANIMATION_DELAY = 4L - private const val DREAM_IN_BOTTOM_COMPLICATIONS_ANIMATION_DELAY = 5L + private const val DREAM_IN_TRANSLATION_Y_DISTANCE = 6 + private const val DREAM_IN_TRANSLATION_Y_DURATION = 7L private const val DREAM_OUT_TRANSLATION_Y_DISTANCE = 6 private const val DREAM_OUT_TRANSLATION_Y_DURATION = 7L private const val DREAM_OUT_TRANSLATION_Y_DELAY_BOTTOM = 8L @@ -54,11 +54,11 @@ class DreamOverlayAnimationsControllerTest : SysuiTestCase() { hostViewController, statusBarViewController, stateController, + DREAM_BLUR_RADIUS, DREAM_IN_BLUR_ANIMATION_DURATION, - DREAM_IN_BLUR_ANIMATION_DELAY, DREAM_IN_COMPLICATIONS_ANIMATION_DURATION, - DREAM_IN_TOP_COMPLICATIONS_ANIMATION_DELAY, - DREAM_IN_BOTTOM_COMPLICATIONS_ANIMATION_DELAY, + DREAM_IN_TRANSLATION_Y_DISTANCE, + DREAM_IN_TRANSLATION_Y_DURATION, DREAM_OUT_TRANSLATION_Y_DISTANCE, DREAM_OUT_TRANSLATION_Y_DURATION, DREAM_OUT_TRANSLATION_Y_DELAY_BOTTOM, diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutParamsTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutParamsTest.java index fdb4cc4480da..e414942afb56 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutParamsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutParamsTest.java @@ -17,6 +17,10 @@ package com.android.systemui.dreams.complication; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + import android.testing.AndroidTestingRunner; import androidx.test.filters.SmallTest; @@ -29,6 +33,7 @@ import org.junit.runner.RunWith; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.function.Consumer; @SmallTest @RunWith(AndroidTestingRunner.class) @@ -197,4 +202,19 @@ public class ComplicationLayoutParamsTest extends SysuiTestCase { assertThat(paramsWithConstraint.constraintSpecified()).isTrue(); assertThat(paramsWithConstraint.getConstraint()).isEqualTo(constraint); } + + @Test + public void testIteratePositions() { + final int positions = ComplicationLayoutParams.POSITION_TOP + | ComplicationLayoutParams.POSITION_START + | ComplicationLayoutParams.POSITION_END; + final Consumer<Integer> consumer = mock(Consumer.class); + + ComplicationLayoutParams.iteratePositions(consumer, positions); + + verify(consumer).accept(ComplicationLayoutParams.POSITION_TOP); + verify(consumer).accept(ComplicationLayoutParams.POSITION_START); + verify(consumer).accept(ComplicationLayoutParams.POSITION_END); + verify(consumer, never()).accept(ComplicationLayoutParams.POSITION_BOTTOM); + } } |