private int[] mDirectionVector = new int[2];
int[] mPreviousReorderDirection = new int[2];
private static final int INVALID_DIRECTION = -100;
- private DropTarget.DragEnforcer mDragEnforcer;
private final Rect mTempRect = new Rect();
public CellLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- mDragEnforcer = new DropTarget.DragEnforcer(context);
// A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
// the user where a dragged item will land when dropped.
* or it may have begun on another layout.
*/
void onDragEnter() {
- mDragEnforcer.onDragEnter();
mDragging = true;
}
* Called when drag has left this CellLayout or has been completed (successfully or not)
*/
void onDragExit() {
- mDragEnforcer.onDragExit();
// This can actually be called when we aren't in a drag, e.g. when adding a new
// item to this layout via the customize drawer.
// Guard against that case.
package com.android.launcher3;
-import android.content.Context;
import android.graphics.PointF;
import android.graphics.Rect;
-import android.util.Log;
/**
* Interface defining an object that can receive a drag.
}
}
- public static class DragEnforcer implements DragController.DragListener {
- int dragParity = 0;
-
- public DragEnforcer(Context context) {
- Launcher launcher = (Launcher) context;
- launcher.getDragController().addDragListener(this);
- }
-
- void onDragEnter() {
- dragParity++;
- if (dragParity != 1) {
- Log.e(TAG, "onDragEnter: Drag contract violated: " + dragParity);
- }
- }
-
- void onDragExit() {
- dragParity--;
- if (dragParity != 0) {
- Log.e(TAG, "onDragExit: Drag contract violated: " + dragParity);
- }
- }
-
- @Override
- public void onDragStart(DragSource source, Object info, int dragAction) {
- if (dragParity != 0) {
- Log.e(TAG, "onDragEnter: Drag contract violated: " + dragParity);
- }
- }
-
- @Override
- public void onDragEnd() {
- if (dragParity != 0) {
- Log.e(TAG, "onDragExit: Drag contract violated: " + dragParity);
- }
- }
- }
-
/**
* Used to temporarily disable certain drop targets
*
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.UninstallDropTarget.UninstallSource;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
-import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource;
+import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.Thunk;
Insettable, UninstallSource, AccessibilityDragSource {
private static final String TAG = "Launcher.Workspace";
+ private static boolean ENFORCE_DRAG_EVENT_ORDER = false;
+
protected static final int SNAP_OFF_EMPTY_SCREEN_DURATION = 400;
protected static final int FADE_EMPTY_SCREEN_DURATION = 150;
private FolderIcon mDragOverFolderIcon = null;
private boolean mCreateUserFolderOnDrop = false;
private boolean mAddToExistingFolderOnDrop = false;
- private DropTarget.DragEnforcer mDragEnforcer;
private float mMaxDistanceForFolderCreation;
private final Canvas mCanvas = new Canvas();
mOutlineHelper = HolographicOutlineHelper.obtain(context);
- mDragEnforcer = new DropTarget.DragEnforcer(context);
- // With workspace, data is available straight from the get-go
-
mLauncher = (Launcher) context;
mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
final Resources res = getResources();
return r;
}
+ @Override
public void onDragStart(final DragSource source, Object info, int dragAction) {
+ if (ENFORCE_DRAG_EVENT_ORDER) {
+ enfoceDragParity("onDragStart", 0, 0);
+ }
+
mIsDragOccuring = true;
updateChildrenLayersEnabled(false);
mLauncher.lockScreenOrientation();
mLauncher.onInteractionBegin();
// Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
InstallShortcutReceiver.enableInstallQueue();
- post(new Runnable() {
- @Override
- public void run() {
- if (mIsDragOccuring && mAddNewPageOnDrag) {
- mDeferRemoveExtraEmptyScreen = false;
- addExtraEmptyScreenOnDrag();
- }
- }
- });
+
+ if (mAddNewPageOnDrag) {
+ mDeferRemoveExtraEmptyScreen = false;
+ addExtraEmptyScreenOnDrag();
+ }
}
public void setAddNewPageOnDrag(boolean addPage) {
mDeferRemoveExtraEmptyScreen = true;
}
+ @Override
public void onDragEnd() {
+ if (ENFORCE_DRAG_EVENT_ORDER) {
+ enfoceDragParity("onDragEnd", 0, 0);
+ }
+
if (!mDeferRemoveExtraEmptyScreen) {
removeExtraEmptyScreen(true, mDragSourceInternal != null);
}
location[1] = vY - y;
}
+ @Override
public void onDragEnter(DragObject d) {
- mDragEnforcer.onDragEnter();
+ if (ENFORCE_DRAG_EVENT_ORDER) {
+ enfoceDragParity("onDragEnter", 1, 1);
+ }
+
mCreateUserFolderOnDrop = false;
mAddToExistingFolderOnDrop = false;
return null;
}
+ @Override
public void onDragExit(DragObject d) {
- mDragEnforcer.onDragExit();
+ if (ENFORCE_DRAG_EVENT_ORDER) {
+ enfoceDragParity("onDragExit", -1, 0);
+ }
// Here we store the final page that will be dropped to, if the workspace in fact
// receives the drop
mLauncher.getDragLayer().hidePageHints();
}
+ private void enfoceDragParity(String event, int update, int expectedValue) {
+ enfoceDragParity(this, event, update, expectedValue);
+ for (int i = 0; i < getChildCount(); i++) {
+ enfoceDragParity(getChildAt(i), event, update, expectedValue);
+ }
+ }
+
+ private void enfoceDragParity(View v, String event, int update, int expectedValue) {
+ Object tag = v.getTag(R.id.drag_event_parity);
+ int value = tag == null ? 0 : (Integer) tag;
+ value += update;
+ v.setTag(R.id.drag_event_parity, value);
+
+ if (value != expectedValue) {
+ Log.e(TAG, event + ": Drag contract violated: " + value);
+ }
+ }
+
void setCurrentDropLayout(CellLayout layout) {
if (mDragTargetLayout != null) {
mDragTargetLayout.revertTempState();
import com.android.launcher3.DragController;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget.DragObject;
-import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.Folder;
import com.android.launcher3.IconCache;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.WidgetPreviewLoader;
import com.android.launcher3.Workspace;
+import com.android.launcher3.model.WidgetsModel;
/**
* The widgets list view container.
private static final String TAG = "WidgetsContainerView";
private static final boolean DEBUG = false;
- private static final int SPRING_MODE_DELAY_MS = 150;
-
/* Coefficient multiplied to the screen height for preloading widgets. */
private static final int PRELOAD_SCREEN_HEIGHT_MULTIPLE = 1;
Log.e(TAG, "Unexpected dragging view: " + v);
}
- // We delay entering spring-loaded mode slightly to make sure the UI
- // thread is free of any work.
- postDelayed(new Runnable() {
- @Override
- public void run() {
- // We don't enter spring-loaded mode if the drag has been cancelled
- if (mLauncher.getDragController().isDragging()) {
- // Go into spring loaded mode (must happen before we startDrag())
- mLauncher.enterSpringLoadedDragMode();
- }
- }
- }, SPRING_MODE_DELAY_MS);
+ // We don't enter spring-loaded mode if the drag has been cancelled
+ if (mLauncher.getDragController().isDragging()) {
+ // Go into spring loaded mode (must happen before we startDrag())
+ mLauncher.enterSpringLoadedDragMode();
+ }
return true;
}