Update taskbar drag and drop treatment

- Disable the FastBitmapDrawable icon instead of setting it to invisible
- Suspend auto hide during drag and drop (moved to new TaskbarAutoHideSuspendController)

Test: Drag and drop from taskbar and ensure the original icon stays in place but desaturated
Test: Open immersive app, drag and drop from taskbar and ensure taskbar doesn't hide before drop
Fixes: 200816442
Change-Id: I4b895efd043be75e7e7034bd75e751ffdd2cfdd7
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
index 370496a..5e60b4a 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java
@@ -69,7 +69,6 @@
 import com.android.launcher3.views.ActivityContext;
 import com.android.quickstep.SysUINavigationMode;
 import com.android.quickstep.SysUINavigationMode.Mode;
-import com.android.quickstep.SystemUiProxy;
 import com.android.systemui.shared.recents.model.Task;
 import com.android.systemui.shared.system.ActivityManagerWrapper;
 import com.android.systemui.shared.system.WindowManagerWrapper;
@@ -157,7 +156,8 @@
                 new TaskbarKeyguardController(this),
                 new StashedHandleViewController(this, stashedHandleView),
                 new TaskbarStashController(this),
-                new TaskbarEduController(this));
+                new TaskbarEduController(this),
+                new TaskbarAutohideSuspendController(this));
     }
 
     public void init(TaskbarSharedState sharedState) {
@@ -360,7 +360,8 @@
      * Updates the TaskbarContainer to MATCH_PARENT vs original Taskbar size.
      */
     public void setTaskbarWindowFullscreen(boolean fullscreen) {
-        SystemUiProxy.INSTANCE.getNoCreate().notifyTaskbarAutohideSuspend(fullscreen);
+        mControllers.taskbarAutohideSuspendController.updateFlag(
+                TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_FULLSCREEN, fullscreen);
         mIsFullscreen = fullscreen;
         setTaskbarWindowHeight(fullscreen ? MATCH_PARENT : mLastRequestedNonFullscreenHeight);
     }
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarAutohideSuspendController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarAutohideSuspendController.java
new file mode 100644
index 0000000..e42f83d
--- /dev/null
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarAutohideSuspendController.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.taskbar;
+
+import androidx.annotation.IntDef;
+
+import com.android.quickstep.SystemUiProxy;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Normally Taskbar will auto-hide when entering immersive (fullscreen) apps. This controller allows
+ * us to suspend that behavior in certain cases (e.g. opening a Folder or dragging an icon).
+ */
+public class TaskbarAutohideSuspendController {
+
+    public static final int FLAG_AUTOHIDE_SUSPEND_FULLSCREEN = 1 << 0;
+    public static final int FLAG_AUTOHIDE_SUSPEND_DRAGGING = 1 << 1;
+    @IntDef(flag = true, value = {
+            FLAG_AUTOHIDE_SUSPEND_FULLSCREEN,
+            FLAG_AUTOHIDE_SUSPEND_DRAGGING,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface AutohideSuspendFlag {}
+
+    private final SystemUiProxy mSystemUiProxy;
+
+    private @AutohideSuspendFlag int mAutohideSuspendFlags = 0;
+
+    public TaskbarAutohideSuspendController(TaskbarActivityContext activity) {
+        mSystemUiProxy = SystemUiProxy.INSTANCE.get(activity);
+    }
+
+    public void onDestroy() {
+        mSystemUiProxy.notifyTaskbarAutohideSuspend(false);
+    }
+
+    /**
+     * Adds or removes the given flag, then notifies system UI proxy whether to suspend auto-hide.
+     */
+    public void updateFlag(@AutohideSuspendFlag int flag, boolean enabled) {
+        if (enabled) {
+            mAutohideSuspendFlags |= flag;
+        } else {
+            mAutohideSuspendFlags &= ~flag;
+        }
+        mSystemUiProxy.notifyTaskbarAutohideSuspend(mAutohideSuspendFlags != 0);
+    }
+}
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java
index 8684c29..7b0053e 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java
@@ -37,6 +37,7 @@
     public final StashedHandleViewController stashedHandleViewController;
     public final TaskbarStashController taskbarStashController;
     public final TaskbarEduController taskbarEduController;
+    public final TaskbarAutohideSuspendController taskbarAutohideSuspendController;
 
     /** Do not store this controller, as it may change at runtime. */
     @NonNull public TaskbarUIController uiController = TaskbarUIController.DEFAULT;
@@ -53,7 +54,8 @@
             TaskbarKeyguardController taskbarKeyguardController,
             StashedHandleViewController stashedHandleViewController,
             TaskbarStashController taskbarStashController,
-            TaskbarEduController taskbarEduController) {
+            TaskbarEduController taskbarEduController,
+            TaskbarAutohideSuspendController taskbarAutoHideSuspendController) {
         this.taskbarActivityContext = taskbarActivityContext;
         this.taskbarDragController = taskbarDragController;
         this.navButtonController = navButtonController;
@@ -67,6 +69,7 @@
         this.stashedHandleViewController = stashedHandleViewController;
         this.taskbarStashController = taskbarStashController;
         this.taskbarEduController = taskbarEduController;
+        this.taskbarAutohideSuspendController = taskbarAutoHideSuspendController;
     }
 
     /**
@@ -75,6 +78,7 @@
      * in constructors for now, as some controllers may still be waiting for init().
      */
     public void init(TaskbarSharedState sharedState) {
+        taskbarDragController.init(this);
         navbarButtonsViewController.init(this, sharedState);
         if (taskbarActivityContext.isThreeButtonNav()) {
             rotationButtonController.init();
@@ -101,5 +105,6 @@
         taskbarUnfoldAnimationController.onDestroy();
         taskbarViewController.onDestroy();
         stashedHandleViewController.onDestroy();
+        taskbarAutohideSuspendController.onDestroy();
     }
 }
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java
index 1afbd17..3bcacb6 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java
@@ -15,9 +15,6 @@
  */
 package com.android.launcher3.taskbar;
 
-import static android.view.View.INVISIBLE;
-import static android.view.View.VISIBLE;
-
 import android.content.ClipData;
 import android.content.ClipDescription;
 import android.content.Intent;
@@ -49,7 +46,6 @@
 import com.android.launcher3.dragndrop.DragView;
 import com.android.launcher3.dragndrop.DraggableView;
 import com.android.launcher3.graphics.DragPreviewProvider;
-import com.android.launcher3.icons.FastBitmapDrawable;
 import com.android.launcher3.logging.StatsLogManager;
 import com.android.launcher3.model.data.ItemInfo;
 import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -65,6 +61,9 @@
     private final int mDragIconSize;
     private final int[] mTempXY = new int[2];
 
+    // Initialized in init.
+    TaskbarControllers mControllers;
+
     // Where the initial touch was relative to the dragged icon.
     private int mRegistrationX;
     private int mRegistrationY;
@@ -77,6 +76,10 @@
         mDragIconSize = resources.getDimensionPixelSize(R.dimen.taskbar_icon_drag_icon_size);
     }
 
+    public void init(TaskbarControllers controllers) {
+        mControllers = controllers;
+    }
+
     /**
      * Attempts to start a system drag and drop operation for the given View, using its tag to
      * generate the ClipDescription and Intent.
@@ -90,19 +93,17 @@
         BubbleTextView btv = (BubbleTextView) view;
 
         mActivity.setTaskbarWindowFullscreen(true);
-        view.post(() -> {
+        btv.post(() -> {
             startInternalDrag(btv);
-            btv.setVisibility(INVISIBLE);
+            btv.getIcon().setIsDisabled(true);
+            mControllers.taskbarAutohideSuspendController.updateFlag(
+                    TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_DRAGGING, true);
         });
         return true;
     }
 
     private void startInternalDrag(BubbleTextView btv) {
-        float iconScale = 1f;
-        Drawable icon = btv.getIcon();
-        if (icon instanceof FastBitmapDrawable) {
-            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
-        }
+        float iconScale = btv.getIcon().getAnimatedScale();
 
         // Clear the pressed state if necessary
         btv.clearFocus();
@@ -239,16 +240,17 @@
                 shadowSize.set(mDragIconSize, mDragIconSize);
                 // The registration point was taken before the icon scaled to mDragIconSize, so
                 // offset the registration to where the touch is on the new size.
-                int offset = (mDragIconSize - btv.getIconSize()) / 2;
-                shadowTouchPoint.set(mRegistrationX + offset, mRegistrationY + offset);
+                int offsetX = (mDragIconSize - mDragObject.dragView.getDragRegionWidth()) / 2;
+                int offsetY = (mDragIconSize - mDragObject.dragView.getDragRegionHeight()) / 2;
+                shadowTouchPoint.set(mRegistrationX + offsetX, mRegistrationY + offsetY);
             }
 
             @Override
             public void onDrawShadow(Canvas canvas) {
                 canvas.save();
-                float scale = (float) mDragIconSize / btv.getIconSize();
+                float scale = mDragObject.dragView.getScaleX();
                 canvas.scale(scale, scale);
-                btv.getIcon().draw(canvas);
+                mDragObject.dragView.draw(canvas);
                 canvas.restore();
             }
         };
@@ -330,7 +332,9 @@
 
     private void maybeOnDragEnd() {
         if (!isDragging()) {
-            ((View) mDragObject.originalView).setVisibility(VISIBLE);
+            ((BubbleTextView) mDragObject.originalView).getIcon().setIsDisabled(false);
+            mControllers.taskbarAutohideSuspendController.updateFlag(
+                    TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_DRAGGING, false);
         }
     }