mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-02 00:36:49 +00:00
Add shortcut drag/drop support to the taskbar.
- Added support for shortcut drag/drop - Added support for popup menu shortcut drag/drop Test: long pressed taskbar and launcher icons. long pressed taskbar and launcher shortcuts and popup menu shortcuts. Fixes: 204453506 Bug: 198438631 Change-Id: I09cab335dcbb3a2bfa3020b21f4bcffff9c53e61
This commit is contained in:
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package com.android.launcher3.taskbar;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
@@ -30,6 +34,7 @@ import com.android.launcher3.popup.PopupContainerWithArrow;
|
||||
import com.android.launcher3.popup.PopupDataProvider;
|
||||
import com.android.launcher3.popup.PopupLiveUpdateHandler;
|
||||
import com.android.launcher3.popup.SystemShortcut;
|
||||
import com.android.launcher3.shortcuts.DeepShortcutView;
|
||||
import com.android.launcher3.util.ComponentKey;
|
||||
import com.android.launcher3.util.LauncherBindableItemsContainer;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
@@ -131,8 +136,14 @@ public class TaskbarPopupController {
|
||||
(PopupContainerWithArrow) context.getLayoutInflater().inflate(
|
||||
R.layout.popup_container, context.getDragLayer(), false);
|
||||
container.addOnAttachStateChangeListener(
|
||||
new PopupLiveUpdateHandler<>(mContext, container));
|
||||
new PopupLiveUpdateHandler<TaskbarActivityContext>(mContext, container) {
|
||||
@Override
|
||||
protected void showPopupContainerForIcon(BubbleTextView originalIcon) {
|
||||
showForIcon(originalIcon);
|
||||
}
|
||||
});
|
||||
// TODO (b/198438631): configure for taskbar/context
|
||||
container.setPopupItemDragHandler(new TaskbarPopupItemDragHandler());
|
||||
|
||||
container.populateAndShow(icon,
|
||||
mPopupDataProvider.getShortcutCountForItem(item),
|
||||
@@ -145,4 +156,43 @@ public class TaskbarPopupController {
|
||||
container.requestFocus();
|
||||
return container;
|
||||
}
|
||||
|
||||
private class TaskbarPopupItemDragHandler implements
|
||||
PopupContainerWithArrow.PopupItemDragHandler {
|
||||
|
||||
protected final Point mIconLastTouchPos = new Point();
|
||||
|
||||
TaskbarPopupItemDragHandler() {}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent ev) {
|
||||
// Touched a shortcut, update where it was touched so we can drag from there on
|
||||
// long click.
|
||||
switch (ev.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
mIconLastTouchPos.set((int) ev.getX(), (int) ev.getY());
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
// Return early if not the correct view
|
||||
if (!(v.getParent() instanceof DeepShortcutView)) return false;
|
||||
|
||||
DeepShortcutView sv = (DeepShortcutView) v.getParent();
|
||||
sv.setWillDrawIcon(false);
|
||||
|
||||
// Move the icon to align with the center-top of the touch point
|
||||
Point iconShift = new Point();
|
||||
iconShift.x = mIconLastTouchPos.x - sv.getIconCenter().x;
|
||||
iconShift.y = mIconLastTouchPos.y - mContext.getDeviceProfile().iconSizePx;
|
||||
|
||||
mControllers.taskbarDragController.startDragOnLongClick(sv, iconShift);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user