From 312b68fde4799597a021476e96f54b75269acbcb Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Thu, 20 Jan 2022 12:46:21 -0800 Subject: [PATCH] Fix taskbar icon dragging issues - Fixed icons disappearing when initiating dragging - Fixed incorrect icon location when initiating dragging after rotating the screen to an orientation other than what launcher started in Fixes: 215418478 Fixes: 214025075 Test: dragged icons from the workspace and taskbar Change-Id: I848138af28802f7d806708c77c25b8de307c70d8 --- .../taskbar/TaskbarActivityContext.java | 21 ++++++++++++++----- .../taskbar/TaskbarDragController.java | 2 +- .../launcher3/taskbar/TaskbarManager.java | 7 +++++++ src/com/android/launcher3/Workspace.java | 2 +- .../launcher3/config/FeatureFlags.java | 2 +- .../popup/PopupContainerWithArrow.java | 8 ++++++- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 81ff26e970..1f79450a69 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -96,11 +96,12 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ private static final String WINDOW_TITLE = "Taskbar"; - private final DeviceProfile mDeviceProfile; private final LayoutInflater mLayoutInflater; private final TaskbarDragLayer mDragLayer; private final TaskbarControllers mControllers; + private DeviceProfile mDeviceProfile; + private final WindowManager mWindowManager; private final @Nullable RoundedCorner mLeftCorner, mRightCorner; private final int mTaskbarHeightForIme; @@ -136,10 +137,7 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ Settings.Secure.getUriFor(Settings.Secure.NAV_BAR_KIDS_MODE), 0); final Resources resources = getResources(); - float taskbarIconSize = resources.getDimension(R.dimen.taskbar_icon_size); - mDeviceProfile.updateIconSize(1, resources); - float iconScale = taskbarIconSize / mDeviceProfile.iconSizePx; - mDeviceProfile.updateIconSize(iconScale, resources); + updateIconSize(resources); mTaskbarHeightForIme = resources.getDimensionPixelSize(R.dimen.taskbar_ime_size); @@ -214,6 +212,19 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ mWindowManager.addView(mDragLayer, mWindowLayoutParams); } + /** Updates the Device profile instance to the latest representation of the screen. */ + public void updateDeviceProfile(DeviceProfile dp) { + mDeviceProfile = dp; + updateIconSize(getResources()); + } + + private void updateIconSize(Resources resources) { + float taskbarIconSize = resources.getDimension(R.dimen.taskbar_icon_size); + mDeviceProfile.updateIconSize(1, resources); + float iconScale = taskbarIconSize / mDeviceProfile.iconSizePx; + mDeviceProfile.updateIconSize(iconScale, resources); + } + /** Creates LayoutParams for adding a view directly to WindowManager as a new window */ public WindowManager.LayoutParams createDefaultWindowLayoutParams() { WindowManager.LayoutParams windowLayoutParams = new WindowManager.LayoutParams( diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java index 3315f8cad2..15726a43dc 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java @@ -167,7 +167,7 @@ public class TaskbarDragController extends DragController popupContainer = mControllers.taskbarPopupController.showForIcon(btv); if (popupContainer != null) { - dragOptions.preDragCondition = popupContainer.createPreDragCondition(); + dragOptions.preDragCondition = popupContainer.createPreDragCondition(false); } } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java index a2626749f4..75ace04de4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java @@ -116,6 +116,13 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen } else { // Config change might be handled without re-creating the taskbar if (mTaskbarActivityContext != null) { + DeviceProfile dp = mUserUnlocked + ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) + : null; + + if (dp != null && dp.isTaskbarPresent) { + mTaskbarActivityContext.updateDeviceProfile(dp.copy(mContext)); + } mTaskbarActivityContext.onConfigurationChanged(configDiff); } } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 65006ff87f..ec3f2bb368 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1686,7 +1686,7 @@ public class Workspace extends PagedView PopupContainerWithArrow popupContainer = PopupContainerWithArrow .showForIcon((BubbleTextView) child); if (popupContainer != null) { - dragOptions.preDragCondition = popupContainer.createPreDragCondition(); + dragOptions.preDragCondition = popupContainer.createPreDragCondition(true); } } diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index c4421c32a6..27c7491620 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -203,7 +203,7 @@ public final class FeatureFlags { "Enables showing taskbar education the first time an app is opened."); public static final BooleanFlag ENABLE_TASKBAR_POPUP_MENU = getDebugFlag( - "ENABLE_TASKBAR_POPUP_MENU", false, "Enables long pressing taskbar icons to show the" + "ENABLE_TASKBAR_POPUP_MENU", true, "Enables long pressing taskbar icons to show the" + " popup menu."); public static final BooleanFlag ENABLE_OVERVIEW_GRID = getDebugFlag( diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 00977059a5..198397a5e1 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -418,7 +418,7 @@ public class PopupContainerWithArrow * Current behavior: * - Start the drag if the touch passes a certain distance from the original touch down. */ - public DragOptions.PreDragCondition createPreDragCondition() { + public DragOptions.PreDragCondition createPreDragCondition(boolean updateIconUi) { return new DragOptions.PreDragCondition() { @Override @@ -428,6 +428,9 @@ public class PopupContainerWithArrow @Override public void onPreDragStart(DropTarget.DragObject dragObject) { + if (!updateIconUi) { + return; + } if (mIsAboveIcon) { // Hide only the icon, keep the text visible. mOriginalIcon.setIconVisible(false); @@ -440,6 +443,9 @@ public class PopupContainerWithArrow @Override public void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted) { + if (!updateIconUi) { + return; + } mOriginalIcon.setIconVisible(true); if (dragStarted) { // Make sure we keep the original icon hidden while it is being dragged.