Initial Taskbar drag-n-drop support for search results.

- Includes initial support for obtaining PendingIntent for ITEM_TYPE_SEARCH_ACTION.
- Custom pre-drag conditions for search results can be provided through TaskbarSearchSessionController.
- Added detection for telling when DragView shift animation ends for
  pre-drag condition usage.

Test: Manual
Bug: 289261756
Flag: ENABLE_ALL_APPS_SEARCH_IN_TASKBAR
Change-Id: I52510a6f3ee49968134ecb591ef7c4df711b9d3d
This commit is contained in:
Brian Isganitis
2023-07-10 16:51:48 -04:00
parent 19c22c20b2
commit 3346e19b3b
5 changed files with 99 additions and 23 deletions
@@ -20,11 +20,13 @@ import static com.android.launcher3.AbstractFloatingView.TYPE_TASKBAR_ALL_APPS;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PREDICTION;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SEARCH_ACTION;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.NonNull;
import android.app.PendingIntent;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Intent;
@@ -73,6 +75,7 @@ import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.IntSet;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.views.BubbleTextHolder;
import com.android.quickstep.util.LogUtils;
import com.android.quickstep.util.MultiValueUpdateListener;
import com.android.systemui.shared.recents.model.Task;
@@ -149,6 +152,9 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
View view,
@Nullable DragPreviewProvider dragPreviewProvider,
@Nullable Point iconShift) {
if (view instanceof BubbleTextHolder) {
view = ((BubbleTextHolder) view).getBubbleText();
}
if (!(view instanceof BubbleTextView) || mDisallowLongClick) {
return false;
}
@@ -193,13 +199,21 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
dragLayerY += dragRect.top;
DragOptions dragOptions = new DragOptions();
dragOptions.preDragCondition = null;
PopupContainerWithArrow<BaseTaskbarContext> popupContainer =
mControllers.taskbarPopupController.showForIcon(btv);
if (popupContainer != null) {
dragOptions.preDragCondition = popupContainer.createPreDragCondition(false);
}
// First, see if view is a search result that needs custom pre-drag conditions.
dragOptions.preDragCondition =
mControllers.taskbarAllAppsController.createPreDragConditionForSearch(btv);
if (dragOptions.preDragCondition == null) {
// See if view supports a popup container.
PopupContainerWithArrow<BaseTaskbarContext> popupContainer =
mControllers.taskbarPopupController.showForIcon(btv);
if (popupContainer != null) {
dragOptions.preDragCondition = popupContainer.createPreDragCondition(false);
}
}
if (dragOptions.preDragCondition == null) {
// Fallback pre-drag condition.
dragOptions.preDragCondition = new DragOptions.PreDragCondition() {
private DragView mDragView;
@@ -213,13 +227,8 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
mDragView = dragObject.dragView;
if (!shouldStartDrag(0)) {
mDragView.setOnAnimationEndCallback(() -> {
// Drag might be cancelled during the DragView animation, so check
// mIsPreDrag again.
if (mIsInPreDrag) {
callOnDragStart();
}
});
mDragView.setOnScaleAnimEndCallback(
TaskbarDragController.this::onPreDragAnimationEnd);
}
}
@@ -230,12 +239,13 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
};
}
Point dragOffset = dragOptions.preDragCondition.getDragOffset();
return startDrag(
drawable,
/* view = */ null,
/* originalView = */ btv,
dragLayerX,
dragLayerY,
dragLayerX + dragOffset.x,
dragLayerY + dragOffset.y,
(View target, DropTarget.DragObject d, boolean success) -> {} /* DragSource */,
(ItemInfo) btv.getTag(),
dragRect,
@@ -290,6 +300,11 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
mDragObject.dragInfo = dragInfo;
mDragObject.originalDragInfo = mDragObject.dragInfo.makeShallowCopy();
if (mOptions.preDragCondition != null) {
dragView.setHasDragOffset(mOptions.preDragCondition.getDragOffset().x != 0
|| mOptions.preDragCondition.getDragOffset().y != 0);
}
if (dragRegion != null) {
dragView.setDragRegion(new Rect(dragRegion));
}
@@ -308,6 +323,14 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
return dragView;
}
/** Invoked when an animation running as part of pre-drag finishes. */
public void onPreDragAnimationEnd() {
// Drag might be cancelled during the DragView animation, so check mIsPreDrag again.
if (mIsInPreDrag) {
callOnDragStart();
}
}
@Override
protected void callOnDragStart() {
super.callOnDragStart();
@@ -383,6 +406,17 @@ public class TaskbarDragController extends DragController<BaseTaskbarContext> im
item.user));
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, item.getIntent().getPackage());
intent.putExtra(Intent.EXTRA_SHORTCUT_ID, deepShortcutId);
} else if (item.itemType == ITEM_TYPE_SEARCH_ACTION) {
// TODO(b/289261756): Buggy behavior when split opposite to an existing search pane.
intent.putExtra(
ClipDescription.EXTRA_PENDING_INTENT,
PendingIntent.getActivityAsUser(
mActivity,
/* requestCode= */ 0,
item.getIntent(),
PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT,
/* options= */ null,
item.user));
} else {
intent.putExtra(ClipDescription.EXTRA_PENDING_INTENT,
launcherApps.getMainActivityLaunchIntent(item.getIntent().getComponent(),