focusTransitionScaleAndDimOut should always go from 1f to 0f

- Also updated AnimatedFloat to accept a Consumer<Float>, so a lambda can be used as updateCallback with refernce to udpated value
- Also updated PendingAnimation to accept Animator with TimedInterpolator without specifying SpringProperty

Fix: 352195519
Test: manual
Flag: EXEMPT bugfix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c378e64b757dbb83b6024be462a6752bc6a2c5f2)
Merged-In: Ifb78c1bcd3ca215a5d214f986a107d0988bff13b
Change-Id: Ifb78c1bcd3ca215a5d214f986a107d0988bff13b
This commit is contained in:
Alex Chau
2024-07-10 12:45:17 +01:00
committed by Android Build Coastguard Worker
parent 6bcaf3df98
commit 912edc94a1
5 changed files with 34 additions and 24 deletions

View File

@@ -50,7 +50,7 @@ private constructor(
private val disappearanceDurationMs: Long,
private val interpolator: Interpolator,
) {
private val borderAnimationProgress = AnimatedFloat { updateOutline() }
private val borderAnimationProgress = AnimatedFloat { _ -> updateOutline() }
private val borderPaint =
Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = borderColor
@@ -224,6 +224,7 @@ private constructor(
val borderWidth: Float
get() = borderWidthPx * animationProgress
val alignmentAdjustment: Float
// Outset the border by half the width to create an outwards-growth animation
get() = -borderWidth / 2f + alignmentAdjustmentInset

View File

@@ -3805,7 +3805,7 @@ public abstract class RecentsView<CONTAINER_TYPE extends Context & RecentsViewCo
anim.setFloat(taskView, taskView.getSecondaryDismissTranslationProperty(),
secondaryTranslation, clampToProgress(LINEAR, animationStartProgress,
dismissTranslationInterpolationEnd));
anim.setFloat(taskView, TaskView.SCALE_AND_DIM_OUT, 0f,
anim.add(taskView.getFocusTransitionScaleAndDimOutAnimator(),
clampToProgress(LINEAR, 0f, ANIMATION_DISMISS_PROGRESS_MIDPOINT));
} else {
float primaryTranslation =

View File

@@ -54,6 +54,7 @@ import com.android.launcher3.Flags.privateSpaceRestrictAccessibilityDrag
import com.android.launcher3.LauncherSettings
import com.android.launcher3.R
import com.android.launcher3.Utilities
import com.android.launcher3.anim.AnimatedFloat
import com.android.launcher3.config.FeatureFlags.ENABLE_KEYBOARD_QUICK_SWITCH
import com.android.launcher3.logging.StatsLogManager.LauncherEvent
import com.android.launcher3.model.data.ItemInfo
@@ -438,17 +439,17 @@ constructor(
focusTransitionPropertyFactory.get(FOCUS_TRANSITION_INDEX_FULLSCREEN)
private val focusTransitionScaleAndDim =
focusTransitionPropertyFactory.get(FOCUS_TRANSITION_INDEX_SCALE_AND_DIM)
/**
* Variant of [focusTransitionScaleAndDim] that has a built-in interpolator, to be used with
* [com.android.launcher3.anim.PendingAnimation] via [SCALE_AND_DIM_OUT] only. PendingAnimation
* doesn't support interpolator per animation, so we'll have to interpolate inside the property.
* Returns an animator of [focusTransitionScaleAndDim] that transition out with a built-in
* interpolator.
*/
private var focusTransitionScaleAndDimOut = focusTransitionScaleAndDim.value
set(value) {
field = value
focusTransitionScaleAndDim.value =
FOCUS_TRANSITION_FAST_OUT_INTERPOLATOR.getInterpolation(field)
}
fun getFocusTransitionScaleAndDimOutAnimator(): ObjectAnimator =
AnimatedFloat { v ->
focusTransitionScaleAndDim.value =
FOCUS_TRANSITION_FAST_OUT_INTERPOLATOR.getInterpolation(v)
}
.animateToValue(1f, 0f)
private var iconAndDimAnimator: ObjectAnimator? = null
// The current background requests to load the task thumbnail and icon
@@ -1700,16 +1701,6 @@ constructor(
override fun get(taskView: TaskView) = taskView.focusTransitionProgress
}
@JvmField
val SCALE_AND_DIM_OUT: FloatProperty<TaskView> =
object : FloatProperty<TaskView>("scaleAndDimFastOut") {
override fun setValue(taskView: TaskView, v: Float) {
taskView.focusTransitionScaleAndDimOut = v
}
override fun get(taskView: TaskView) = taskView.focusTransitionScaleAndDimOut
}
private val SPLIT_SELECT_TRANSLATION_X: FloatProperty<TaskView> =
object : FloatProperty<TaskView>("splitSelectTranslationX") {
override fun setValue(taskView: TaskView, v: Float) {

View File

@@ -20,6 +20,8 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.util.FloatProperty;
import java.util.function.Consumer;
/**
* A mutable float which allows animating the value
*/
@@ -38,9 +40,9 @@ public class AnimatedFloat {
}
};
private static final Runnable NO_OP = () -> { };
private static final Consumer<Float> NO_OP = t -> { };
private final Runnable mUpdateCallback;
private final Consumer<Float> mUpdateCallback;
private ObjectAnimator mValueAnimator;
// Only non-null when an animation is playing to this value.
private Float mEndValue;
@@ -52,6 +54,10 @@ public class AnimatedFloat {
}
public AnimatedFloat(Runnable updateCallback) {
this(v -> updateCallback.run());
}
public AnimatedFloat(Consumer<Float> updateCallback) {
mUpdateCallback = updateCallback;
}
@@ -60,6 +66,11 @@ public class AnimatedFloat {
value = initialValue;
}
public AnimatedFloat(Consumer<Float> updateCallback, float initialValue) {
this(updateCallback);
value = initialValue;
}
/**
* Returns an animation from the current value to the given value.
*/
@@ -99,7 +110,7 @@ public class AnimatedFloat {
public void updateValue(float v) {
if (Float.compare(v, value) != 0) {
value = v;
mUpdateCallback.run();
mUpdateCallback.accept(value);
}
}

View File

@@ -59,6 +59,13 @@ public class PendingAnimation extends AnimatedPropertySetter {
add(anim, springProperty);
}
/**
* Utility method to sent an interpolator on an animation and add it to the list
*/
public void add(Animator anim, TimeInterpolator interpolator) {
add(anim, interpolator, SpringProperty.DEFAULT);
}
@Override
public void add(Animator anim) {
add(anim, SpringProperty.DEFAULT);