Simplifying code around multiple translation components

Bug: 270759683
Test: Verified on device
Change-Id: I6c758c715828ae25e0e3c60b793cf85d70cb2487
This commit is contained in:
Sunny Goyal
2023-02-24 16:50:09 -08:00
parent c6c33dd115
commit 82dfc15037
11 changed files with 201 additions and 454 deletions

View File

@@ -17,6 +17,7 @@ package com.android.launcher3.taskbar;
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
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.Utilities.squaredHypot;
import static com.android.launcher3.anim.AnimatedFloat.VALUE;
@@ -27,13 +28,15 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.taskbar.TaskbarManager.isPhoneMode;
import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_NEGATIVE;
import static com.android.launcher3.touch.SingleAxisSwipeDetector.VERTICAL;
import static com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_TASKBAR_ALIGNMENT_ANIM;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_TASKBAR_REVEAL_ANIM;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.NonNull;
import android.graphics.Rect;
import android.util.FloatProperty;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
@@ -43,10 +46,10 @@ import androidx.annotation.Nullable;
import androidx.core.graphics.ColorUtils;
import androidx.core.view.OneShotPreDrawListener;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.Reorderable;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AlphaUpdateListener;
import com.android.launcher3.anim.AnimatedFloat;
@@ -56,7 +59,6 @@ import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.anim.RevealOutlineAnimation;
import com.android.launcher3.anim.RoundedRectRevealOutlineProvider;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.icons.ThemedIconDrawable;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.touch.SingleAxisSwipeDetector;
@@ -65,6 +67,7 @@ import com.android.launcher3.util.HorizontalInsettableView;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.LauncherBindableItemsContainer;
import com.android.launcher3.util.MultiPropertyFactory;
import com.android.launcher3.util.MultiTranslateDelegate;
import com.android.launcher3.util.MultiValueAlpha;
import java.io.PrintWriter;
@@ -338,18 +341,34 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
croppedTransX = newLeft - iconLeft;
}
as.play(ObjectAnimator.ofFloat(child, ICON_REVEAL_TRANSLATE_X, isStashed
? new float[] {croppedTransX}
: new float[] {croppedTransX, 0}));
float croppedTransY = child.getHeight() - stashedBounds.height();
as.play(ObjectAnimator.ofFloat(child, ICON_REVEAL_TRANSLATE_Y, isStashed
? new float[] {croppedTransY}
: new float[] {croppedTransY, 0}));
as.addListener(forEndCallback(() -> {
ICON_REVEAL_TRANSLATE_X.set(child, 0f);
ICON_REVEAL_TRANSLATE_Y.set(child, 0f);
}));
if (child instanceof Reorderable) {
MultiTranslateDelegate mtd = ((Reorderable) child).getTranslateDelegate();
as.play(ObjectAnimator.ofFloat(mtd.getTranslationX(INDEX_TASKBAR_REVEAL_ANIM),
MULTI_PROPERTY_VALUE, isStashed
? new float[] {croppedTransX}
: new float[] {croppedTransX, 0}));
as.play(ObjectAnimator.ofFloat(mtd.getTranslationX(INDEX_TASKBAR_REVEAL_ANIM),
MULTI_PROPERTY_VALUE, isStashed
? new float[] {croppedTransY}
: new float[] {croppedTransY, 0}));
as.addListener(forEndCallback(() ->
mtd.setTranslation(INDEX_TASKBAR_REVEAL_ANIM, 0, 0)));
} else {
as.play(ObjectAnimator.ofFloat(child,
VIEW_TRANSLATE_X, isStashed
? new float[] {croppedTransX}
: new float[] {croppedTransX, 0}));
as.play(ObjectAnimator.ofFloat(child,
VIEW_TRANSLATE_Y, isStashed
? new float[] {croppedTransY}
: new float[] {croppedTransY, 0}));
as.addListener(forEndCallback(() -> {
child.setTranslationX(0);
child.setTranslationY(0);
}));
}
}
return as;
}
@@ -435,7 +454,7 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
float childCenter = (child.getLeft() + child.getRight()) / 2f;
float halfQsbIconWidthDiff =
(launcherDp.hotseatQsbWidth - taskbarDp.iconSizePx) / 2f;
setter.addFloat(child, ICON_TRANSLATE_X,
setter.addFloat(child, VIEW_TRANSLATE_X,
isRtl ? -halfQsbIconWidthDiff : halfQsbIconWidthDiff,
hotseatIconCenter - childCenter, interpolator);
@@ -479,10 +498,18 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
+ hotseatCellSize / 2f;
float childCenter = (child.getLeft() + child.getRight()) / 2f;
setter.setFloat(child, ICON_TRANSLATE_X, hotseatIconCenter - childCenter, interpolator);
setter.setFloat(child, ICON_TRANSLATE_Y, mTaskbarBottomMargin, interpolator);
if (child instanceof Reorderable) {
MultiTranslateDelegate mtd = ((Reorderable) child).getTranslateDelegate();
setter.setFloat(mtd.getTranslationX(INDEX_TASKBAR_ALIGNMENT_ANIM),
MULTI_PROPERTY_VALUE, hotseatIconCenter - childCenter, interpolator);
setter.setFloat(mtd.getTranslationX(INDEX_TASKBAR_ALIGNMENT_ANIM),
MULTI_PROPERTY_VALUE, mTaskbarBottomMargin, interpolator);
} else {
setter.setFloat(child, VIEW_TRANSLATE_X,
hotseatIconCenter - childCenter, interpolator);
setter.setFloat(child, VIEW_TRANSLATE_Y, mTaskbarBottomMargin, interpolator);
}
setter.setFloat(child, SCALE_PROPERTY, scaleUp, interpolator);
}
@@ -667,107 +694,4 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
mControllers.uiController.onIconLayoutBoundsChanged();
}
}
public static final FloatProperty<View> ICON_TRANSLATE_X =
new FloatProperty<View>("taskbarAlignmentTranslateX") {
@Override
public void setValue(View view, float v) {
if (view instanceof BubbleTextView) {
((BubbleTextView) view).setTranslationXForTaskbarAlignmentAnimation(v);
} else if (view instanceof FolderIcon) {
((FolderIcon) view).setTranslationXForTaskbarAlignmentAnimation(v);
} else {
view.setTranslationX(v);
}
}
@Override
public Float get(View view) {
if (view instanceof BubbleTextView) {
return ((BubbleTextView) view)
.getTranslationXForTaskbarAlignmentAnimation();
} else if (view instanceof FolderIcon) {
return ((FolderIcon) view).getTranslationXForTaskbarAlignmentAnimation();
}
return view.getTranslationX();
}
};
public static final FloatProperty<View> ICON_TRANSLATE_Y =
new FloatProperty<View>("taskbarAlignmentTranslateY") {
@Override
public void setValue(View view, float v) {
if (view instanceof BubbleTextView) {
((BubbleTextView) view).setTranslationYForTaskbarAlignmentAnimation(v);
} else if (view instanceof FolderIcon) {
((FolderIcon) view).setTranslationYForTaskbarAlignmentAnimation(v);
} else {
view.setTranslationY(v);
}
}
@Override
public Float get(View view) {
if (view instanceof BubbleTextView) {
return ((BubbleTextView) view)
.getTranslationYForTaskbarAlignmentAnimation();
} else if (view instanceof FolderIcon) {
return ((FolderIcon) view).getTranslationYForTaskbarAlignmentAnimation();
}
return view.getTranslationY();
}
};
public static final FloatProperty<View> ICON_REVEAL_TRANSLATE_X =
new FloatProperty<View>("taskbarRevealTranslateX") {
@Override
public void setValue(View view, float v) {
if (view instanceof BubbleTextView) {
((BubbleTextView) view).setTranslationXForTaskbarRevealAnimation(v);
} else if (view instanceof FolderIcon) {
((FolderIcon) view).setTranslationXForTaskbarRevealAnimation(v);
} else {
view.setTranslationX(v);
}
}
@Override
public Float get(View view) {
if (view instanceof BubbleTextView) {
return ((BubbleTextView) view).getTranslationXForTaskbarRevealAnimation();
} else if (view instanceof FolderIcon) {
return ((FolderIcon) view).getTranslationXForTaskbarRevealAnimation();
}
return view.getTranslationX();
}
};
public static final FloatProperty<View> ICON_REVEAL_TRANSLATE_Y =
new FloatProperty<View>("taskbarRevealTranslateY") {
@Override
public void setValue(View view, float v) {
if (view instanceof BubbleTextView) {
((BubbleTextView) view).setTranslationYForTaskbarRevealAnimation(v);
} else if (view instanceof FolderIcon) {
((FolderIcon) view).setTranslationYForTaskbarRevealAnimation(v);
} else {
view.setTranslationY(v);
}
}
@Override
public Float get(View view) {
if (view instanceof BubbleTextView) {
return ((BubbleTextView) view).getTranslationYForTaskbarRevealAnimation();
} else if (view instanceof FolderIcon) {
return ((FolderIcon) view).getTranslationYForTaskbarRevealAnimation();
}
return view.getTranslationY();
}
};
}