From b6b4069aa4789a4475563e9ee0c63395fd2ea635 Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Thu, 24 Mar 2022 17:44:50 -0700 Subject: [PATCH] Fix widget drop animation in 4x5 grid For the 4x5 grid we add insets to the widget and the animation wasn't accounting for it. I'm using this shell function to quickly change the animation speed ``` function anim-speed() { adb shell settings put global window_animation_scale $1 adb shell settings put global transition_animation_scale $1 adb shell settings put global animator_duration_scale $1 } ``` anim-speed 1 # for regular speed anim-speed 10 # for really slow speed Fix: 194227752 Test: Put down a widget in 4x5 and the animation should match, sometimes is to fast but you can slow the animations with adb and see the difference Change-Id: I182729de39c0d0b12231d07e337dddca6fccf5c0 --- src/com/android/launcher3/Workspace.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index a7fc2f52ba..6ec789a003 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -113,6 +113,7 @@ import com.android.launcher3.util.WallpaperOffsetInterpolator; import com.android.launcher3.widget.LauncherAppWidgetHost; import com.android.launcher3.widget.LauncherAppWidgetHost.ProviderChangedListener; import com.android.launcher3.widget.LauncherAppWidgetHostView; +import com.android.launcher3.widget.NavigableAppWidgetHostView; import com.android.launcher3.widget.PendingAddShortcutInfo; import com.android.launcher3.widget.PendingAddWidgetInfo; import com.android.launcher3.widget.PendingAppWidgetHostView; @@ -2831,7 +2832,8 @@ public class Workspace extends PagedView } private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY, - DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, boolean scale) { + DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, boolean scale, + final View finalView) { // Now we animate the dragView, (ie. the widget or shortcut preview) into its final // location and size on the home screen. int spanX = info.spanX; @@ -2840,6 +2842,14 @@ public class Workspace extends PagedView Rect r = estimateItemPosition(layout, targetCell[0], targetCell[1], spanX, spanY); if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) { DeviceProfile profile = mLauncher.getDeviceProfile(); + if (profile.shouldInsetWidgets() && finalView instanceof NavigableAppWidgetHostView) { + Rect widgetPadding = new Rect(); + ((NavigableAppWidgetHostView) finalView).getWidgetInset(profile, widgetPadding); + r.left -= widgetPadding.left; + r.right += widgetPadding.right; + r.top -= widgetPadding.top; + r.bottom += widgetPadding.bottom; + } Utilities.shrinkRect(r, profile.appWidgetScale.x, profile.appWidgetScale.y); } @@ -2886,7 +2896,7 @@ public class Workspace extends PagedView float scaleXY[] = new float[2]; boolean scalePreview = !(info instanceof PendingAddShortcutInfo); getFinalPositionForDropAnimation(finalPos, scaleXY, dragView, cellLayout, info, mTargetCell, - scalePreview); + scalePreview, finalView); Resources res = mLauncher.getResources(); final int duration = res.getInteger(R.integer.config_dropAnimMaxDuration) - 200;