From d3755f46cc992635a7928376f748e65b5fad0aa3 Mon Sep 17 00:00:00 2001 From: Brandon Dayauon Date: Mon, 29 Aug 2022 11:48:27 -0700 Subject: [PATCH] Scale icons from search to make app icons big like AA -> workspace when dragging from search. To scale the icon during dragging (instead of long press) I created a scale variable within DragOptions so that right before dragStart gets called in DragController.java (in callOnDragStart()) the dragview scales before dragging.. * note: the scale from search is 1.687 and the scale from allApps is 1.107 - included searchResult and smallSearchResult - Added animation for scaling icon (used Interpolators.EMPHASIZED 500ms as suggested by motion designer) - Cancel animation when drag finishes bug: 222666176 test: Manual - after: https://drive.google.com/file/d/1ZZHnXlzdTxlM-RUIdJ6EOYkPPg6tCUxC/view?usp=sharing before: https://drive.google.com/file/d/1NpBz3kT_slHXtpXObr_G8K6SZYG9_bLX/view?usp=sharing Change-Id: I01309a3be928987ba00422ad947b80a3df865973 --- src/com/android/launcher3/BubbleTextView.java | 5 +++++ src/com/android/launcher3/Workspace.java | 15 ++++++++++++--- .../launcher3/dragndrop/DragController.java | 14 +++++++++++++- .../android/launcher3/dragndrop/DragOptions.java | 6 ++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 5fb892554a..c0a00c2784 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -942,6 +942,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, return mIconSize; } + public boolean isDisplaySearchResult() { + return mDisplay == DISPLAY_SEARCH_RESULT || + mDisplay == DISPLAY_SEARCH_RESULT_SMALL; + } + private void updateTranslation() { super.setTranslationX(mTranslationForReorderBounce.x + mTranslationForReorderPreview.x + mTranslationForMoveFromCenterAnimation.x diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index b49d64625b..a5eb9e05b8 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -106,6 +106,7 @@ import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.util.RunnableList; import com.android.launcher3.util.Thunk; import com.android.launcher3.util.WallpaperOffsetInterpolator; +import com.android.launcher3.views.ActivityContext; import com.android.launcher3.widget.LauncherAppWidgetHost; import com.android.launcher3.widget.LauncherAppWidgetHost.ProviderChangedListener; import com.android.launcher3.widget.LauncherAppWidgetHostView; @@ -152,6 +153,8 @@ public class Workspace extends PagedView public static final int DEFAULT_PAGE = 0; + private final int mAllAppsIconSize; + private LayoutTransition mLayoutTransition; @Thunk final WallpaperManager mWallpaperManager; @@ -286,7 +289,7 @@ public class Workspace extends PagedView mLauncher = Launcher.getLauncher(context); mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this); mWallpaperManager = WallpaperManager.getInstance(context); - + mAllAppsIconSize = mLauncher.getDeviceProfile().allAppsIconSizePx; mWallpaperOffset = new WallpaperOffsetInterpolator(this); setHapticFeedbackEnabled(false); @@ -1671,8 +1674,14 @@ public class Workspace extends PagedView mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } - if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) { - dragOptions.preDragCondition = ((BubbleTextView) child).startLongPressAction(); + if (child instanceof BubbleTextView) { + BubbleTextView btv = (BubbleTextView) child; + if (!dragOptions.isAccessibleDrag) { + dragOptions.preDragCondition = btv.startLongPressAction(); + } + if (btv.isDisplaySearchResult()) { + dragOptions.preDragEndScale = (float) mAllAppsIconSize / btv.getIconSize(); + } } final DragView dv; diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index 8616f35011..5368397c6d 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -31,6 +31,7 @@ import androidx.annotation.Nullable; import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget; +import com.android.launcher3.anim.Interpolators; import com.android.launcher3.logging.InstanceId; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; @@ -90,6 +91,8 @@ public abstract class DragController protected boolean mIsInPreDrag; + private final int DRAG_VIEW_SCALE_DURATION_MS = 500; + /** * Interface to receive notifications when a drag starts or stops */ @@ -214,6 +217,15 @@ public abstract class DragController mOptions.preDragCondition.onPreDragEnd(mDragObject, true /* dragStarted*/); } mIsInPreDrag = false; + if (mOptions.preDragEndScale != 0) { + mDragObject.dragView + .animate() + .scaleX(mOptions.preDragEndScale) + .scaleY(mOptions.preDragEndScale) + .setInterpolator(Interpolators.EMPHASIZED) + .setDuration(DRAG_VIEW_SCALE_DURATION_MS) + .start(); + } mDragObject.dragView.onDragStart(); for (DragListener listener : new ArrayList<>(mListeners)) { listener.onDragStart(mDragObject, mOptions); @@ -295,9 +307,9 @@ public abstract class DragController } else if (mIsInPreDrag) { animateDragViewToOriginalPosition(null, null, -1); } + mDragObject.dragView.clearAnimation(); mDragObject.dragView = null; } - // Only end the drag if we are not deferred if (!isDeferred) { callOnDragEnd(); diff --git a/src/com/android/launcher3/dragndrop/DragOptions.java b/src/com/android/launcher3/dragndrop/DragOptions.java index e8ff8da058..1ff433541e 100644 --- a/src/com/android/launcher3/dragndrop/DragOptions.java +++ b/src/com/android/launcher3/dragndrop/DragOptions.java @@ -40,6 +40,12 @@ public class DragOptions { /** Determines when a pre-drag should transition to a drag. By default, this is immediate. */ public PreDragCondition preDragCondition = null; + /** + * A drag scale that scales the original drag view size when the preDragCondition is met (or + * is ignored if preDragEndScale is 0). + */ + public float preDragEndScale; + /** Scale of the icons over the workspace icon size. */ public float intrinsicIconScaleFactor = 1f;