Merge "Fix jump in animation for hotseat while re-arranging icons" into tm-dev am: 49cb99a420

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/16967985

Change-Id: I05ccfa5901e84dd103348ae16dad28cb1edb2408
This commit is contained in:
TreeHugger Robot
2022-02-23 18:14:14 +00:00
committed by Automerger Merge Worker
7 changed files with 81 additions and 43 deletions
@@ -67,18 +67,16 @@ public class LauncherAnimUtils {
};
/**
* Property to set the scale of workspace and hotseat. The value is based on a combination
* Property to set the scale of workspace. The value is based on a combination
* of all the ones set, to have a smooth experience even in the case of overlapping scaling
* animation.
*/
public static final MultiScalePropertyFactory<View> SCALE_PROPERTY_FACTORY =
new MultiScalePropertyFactory<View>("scale_property") {
@Override
protected void apply(View view, float scale) {
view.setScaleX(scale);
view.setScaleY(scale);
}
};
public static final MultiScalePropertyFactory<Workspace> WORKSPACE_SCALE_PROPERTY_FACTORY =
new MultiScalePropertyFactory<Workspace>("workspace_scale_property");
/** Property to set the scale of hotseat. */
public static final MultiScalePropertyFactory<Hotseat> HOTSEAT_SCALE_PROPERTY_FACTORY =
new MultiScalePropertyFactory<Hotseat>("hotseat_scale_property");
public static final int SCALE_INDEX_UNFOLD_ANIMATION = 1;
public static final int SCALE_INDEX_UNLOCK_ANIMATION = 2;
@@ -18,11 +18,12 @@ package com.android.launcher3;
import static androidx.dynamicanimation.animation.DynamicAnimation.MIN_VISIBLE_CHANGE_SCALE;
import static com.android.launcher3.LauncherAnimUtils.HOTSEAT_SCALE_PROPERTY_FACTORY;
import static com.android.launcher3.LauncherAnimUtils.SCALE_INDEX_WORKSPACE_STATE;
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY_FACTORY;
import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
import static com.android.launcher3.LauncherAnimUtils.WORKSPACE_SCALE_PROPERTY_FACTORY;
import static com.android.launcher3.LauncherState.FLAG_HAS_SYS_UI_SCRIM;
import static com.android.launcher3.LauncherState.HINT_STATE;
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
@@ -64,8 +65,11 @@ import com.android.systemui.plugins.ResourceProvider;
*/
public class WorkspaceStateTransitionAnimation {
private static final FloatProperty<View> WORKSPACE_STATE_SCALE_PROPERTY =
SCALE_PROPERTY_FACTORY.get(SCALE_INDEX_WORKSPACE_STATE);
private static final FloatProperty<Workspace> WORKSPACE_SCALE_PROPERTY =
WORKSPACE_SCALE_PROPERTY_FACTORY.get(SCALE_INDEX_WORKSPACE_STATE);
private static final FloatProperty<Hotseat> HOTSEAT_SCALE_PROPERTY =
HOTSEAT_SCALE_PROPERTY_FACTORY.get(SCALE_INDEX_WORKSPACE_STATE);
private final Launcher mLauncher;
private final Workspace mWorkspace;
@@ -120,9 +124,9 @@ public class WorkspaceStateTransitionAnimation {
&& fromState == HINT_STATE && state == NORMAL;
if (shouldSpring) {
((PendingAnimation) propertySetter).add(getSpringScaleAnimator(mLauncher,
mWorkspace, mNewScale));
mWorkspace, mNewScale, WORKSPACE_SCALE_PROPERTY));
} else {
propertySetter.setFloat(mWorkspace, WORKSPACE_STATE_SCALE_PROPERTY, mNewScale,
propertySetter.setFloat(mWorkspace, WORKSPACE_SCALE_PROPERTY, mNewScale,
scaleInterpolator);
}
@@ -130,11 +134,12 @@ public class WorkspaceStateTransitionAnimation {
float hotseatScale = hotseatScaleAndTranslation.scale;
if (shouldSpring) {
PendingAnimation pa = (PendingAnimation) propertySetter;
pa.add(getSpringScaleAnimator(mLauncher, hotseat, hotseatScale));
pa.add(getSpringScaleAnimator(mLauncher, hotseat, hotseatScale,
HOTSEAT_SCALE_PROPERTY));
} else {
Interpolator hotseatScaleInterpolator = config.getInterpolator(ANIM_HOTSEAT_SCALE,
scaleInterpolator);
propertySetter.setFloat(hotseat, WORKSPACE_STATE_SCALE_PROPERTY, hotseatScale,
propertySetter.setFloat(hotseat, HOTSEAT_SCALE_PROPERTY, hotseatScale,
hotseatScaleInterpolator);
}
@@ -197,10 +202,19 @@ public class WorkspaceStateTransitionAnimation {
pageAlpha, fadeInterpolator);
}
/**
* Returns a spring based animator for the scale property of {@param workspace}.
*/
public static ValueAnimator getWorkspaceSpringScaleAnimator(Launcher launcher,
Workspace workspace, float scale) {
return getSpringScaleAnimator(launcher, workspace, scale, WORKSPACE_SCALE_PROPERTY);
}
/**
* Returns a spring based animator for the scale property of {@param v}.
*/
public static ValueAnimator getSpringScaleAnimator(Launcher launcher, View v, float scale) {
public static <T extends View> ValueAnimator getSpringScaleAnimator(Launcher launcher, T v,
float scale, FloatProperty<T> property) {
ResourceProvider rp = DynamicResource.provider(launcher);
float damping = rp.getFloat(R.dimen.hint_scale_damping_ratio);
float stiffness = rp.getFloat(R.dimen.hint_scale_stiffness);
@@ -211,9 +225,9 @@ public class WorkspaceStateTransitionAnimation {
.setDampingRatio(damping)
.setMinimumVisibleChange(MIN_VISIBLE_CHANGE_SCALE)
.setEndValue(scale)
.setStartValue(WORKSPACE_STATE_SCALE_PROPERTY.get(v))
.setStartValue(property.get(v))
.setStartVelocity(velocityPxPerS)
.build(v, WORKSPACE_STATE_SCALE_PROPERTY);
.build(v, property);
}
}
@@ -18,6 +18,8 @@ package com.android.launcher3.util;
import android.util.ArrayMap;
import android.util.FloatProperty;
import android.util.Log;
import android.view.View;
import com.android.launcher3.Utilities;
@@ -33,8 +35,10 @@ import com.android.launcher3.Utilities;
*
* @param <T> Type where to apply the property.
*/
public abstract class MultiScalePropertyFactory<T> {
public class MultiScalePropertyFactory<T extends View> {
private static final boolean DEBUG = false;
private static final String TAG = "MultiScaleProperty";
private final String mName;
private final ArrayMap<Integer, MultiScaleProperty> mProperties =
new ArrayMap<Integer, MultiScaleProperty>();
@@ -56,7 +60,6 @@ public abstract class MultiScalePropertyFactory<T> {
(k) -> new MultiScaleProperty(index, mName + "_" + index));
}
/**
* Each [setValue] will be aggregated with the other properties values created by the
* corresponding factory.
@@ -91,11 +94,22 @@ public abstract class MultiScalePropertyFactory<T> {
mLastAggregatedValue = Utilities.boundToRange(multValue, minValue, maxValue);
mValue = newValue;
apply(obj, mLastAggregatedValue);
if (DEBUG) {
Log.d(TAG, "name=" + mName
+ " newValue=" + newValue + " mInx=" + mInx
+ " aggregated=" + mLastAggregatedValue + " others= " + mProperties);
}
}
@Override
public Float get(T t) {
return mLastAggregatedValue;
public Float get(T view) {
// The scale of the view should match mLastAggregatedValue. Still, if it has been
// changed without using this property, it can differ. As this get method is usually
// used to set the starting point on an animation, this would result in some jumps
// when the view scale is different than the last aggregated value. To stay on the
// safe side, let's return the real view scale.
return view.getScaleX();
}
@Override
@@ -104,6 +118,8 @@ public abstract class MultiScalePropertyFactory<T> {
}
}
/** Applies value to object after setValue method is called. */
protected abstract void apply(T obj, float value);
protected void apply(View view, float value) {
view.setScaleX(value);
view.setScaleY(value);
}
}