mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.3'
+ classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
}
}
<dimen name="bg_pill_height">48dp</dimen>
<dimen name="bg_pill_radius">24dp</dimen>
<dimen name="deep_shortcuts_spacing">4dp</dimen>
- <dimen name="deferred_drag_view_scale">6dp</dimen>
+ <dimen name="pre_drag_view_scale">6dp</dimen>
<!-- an icon with shortcuts must be dragged this far before the container is removed. -->
<dimen name="deep_shortcuts_start_drag_threshold">16dp</dimen>
<dimen name="deep_shortcut_icon_size">36dp</dimen>
longClickCellInfo.cellX, longClickCellInfo.cellY));
if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
// User long pressed on an item
- DragOptions dragOptions = new DragOptions();
- if (itemUnderLongClick instanceof BubbleTextView) {
- BubbleTextView icon = (BubbleTextView) itemUnderLongClick;
- if (icon.hasDeepShortcuts()) {
- DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon(icon);
- if (dsc != null) {
- dragOptions.deferDragCondition = dsc.createDeferDragCondition(null);
- }
- }
- }
- mWorkspace.startDrag(longClickCellInfo, dragOptions);
+ mWorkspace.startDrag(longClickCellInfo, new DragOptions());
}
}
}
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.graphics.DragPreviewProvider;
+import com.android.launcher3.shortcuts.DeepShortcutsContainer;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ItemInfoMatcher;
mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
}
+ if (child instanceof BubbleTextView) {
+ DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon((BubbleTextView) child);
+ if (dsc != null) {
+ dragOptions.preDragCondition = dsc.createPreDragCondition();
+ }
+ }
+
DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source,
dragObject, dragVisualizeOffset, dragRect, scale, dragOptions);
dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor());
import com.android.launcher3.AppInfo;
import com.android.launcher3.BaseContainerView;
-import com.android.launcher3.BubbleTextView;
import com.android.launcher3.CellLayout;
import com.android.launcher3.DeleteDropTarget;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.graphics.TintedDrawableSpan;
import com.android.launcher3.keyboard.FocusedItemDecorator;
-import com.android.launcher3.shortcuts.DeepShortcutsContainer;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ComponentKey;
}
@Override
- public boolean onLongClick(View v) {
+ public boolean onLongClick(final View v) {
// Return early if this is not initiated from a touch
if (!v.isInTouchMode()) return false;
// When we have exited all apps or are in transition, disregard long clicks
if (mLauncher.getDragController().isDragging()) return false;
// Start the drag
- DragOptions dragOptions = new DragOptions();
- if (v instanceof BubbleTextView) {
- final BubbleTextView icon = (BubbleTextView) v;
- if (icon.hasDeepShortcuts()) {
- DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon(icon);
- if (dsc != null) {
- dragOptions.deferDragCondition = dsc.createDeferDragCondition(new Runnable() {
- @Override
- public void run() {
- icon.setVisibility(VISIBLE);
- }
- });
- }
+ final DragController dragController = mLauncher.getDragController();
+ dragController.addDragListener(new DragController.DragListener() {
+ @Override
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
+ v.setVisibility(INVISIBLE);
}
- }
- mLauncher.getWorkspace().beginDragShared(v, this, dragOptions);
+
+ @Override
+ public void onDragEnd() {
+ v.setVisibility(VISIBLE);
+ dragController.removeDragListener(this);
+ }
+ });
+ mLauncher.getWorkspace().beginDragShared(v, this, new DragOptions());
if (FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
// Enter spring loaded mode (the new workspace does this in
// onDragStart(), so we don't want to do it here)
// target layout we were dropping on.
if (!success) {
boolean showOutOfSpaceMessage = false;
- if (target instanceof Workspace && !mLauncher.getDragController().isDeferringDrag()) {
+ if (target instanceof Workspace) {
int currentScreen = mLauncher.getCurrentWorkspaceScreen();
Workspace workspace = (Workspace) target;
CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen);
protected final int mFlingToDeleteThresholdVelocity;
private VelocityTracker mVelocityTracker;
- private boolean mIsDragDeferred;
+ private boolean mIsInPreDrag;
/**
* Interface to receive notifications when a drag starts or stops
mDragObject = new DropTarget.DragObject();
- mIsDragDeferred = !mOptions.deferDragCondition.shouldStartDeferredDrag(0);
+ mIsInPreDrag = mOptions.preDragCondition != null
+ && !mOptions.preDragCondition.shouldStartDrag(0);
final Resources res = mLauncher.getResources();
final float scaleDps = FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND
? res.getDimensionPixelSize(R.dimen.dragViewScale)
- : mIsDragDeferred
- ? res.getDimensionPixelSize(R.dimen.deferred_drag_view_scale)
+ : mIsInPreDrag
+ ? res.getDimensionPixelSize(R.dimen.pre_drag_view_scale)
: 0f;
final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX,
registrationY, initialDragViewScale, scaleDps);
dragView.show(mMotionDownX, mMotionDownY);
mDistanceSinceScroll = 0;
- if (!mIsDragDeferred) {
- startDeferredDrag();
- } else {
- mOptions.deferDragCondition.onDeferredDragStart();
+ if (!mIsInPreDrag) {
+ callOnDragStart();
+ } else if (mOptions.preDragCondition != null) {
+ mOptions.preDragCondition.onPreDragStart();
}
mLastTouch[0] = mMotionDownX;
return dragView;
}
- public boolean isDeferringDrag() {
- return mIsDragDeferred;
- }
-
- public void startDeferredDrag() {
+ private void callOnDragStart() {
for (DragListener listener : new ArrayList<>(mListeners)) {
listener.onDragStart(mDragObject, mOptions);
}
- mOptions.deferDragCondition.onDragStart();
- mIsDragDeferred = false;
+ if (mOptions.preDragCondition != null) {
+ mOptions.preDragCondition.onPreDragEnd(true /* dragStarted*/);
+ }
+ mIsInPreDrag = false;
+ }
+
+ public boolean isInPreDrag() {
+ return mIsInPreDrag;
}
/**
mDragObject.deferDragViewCleanupPostAnimation = false;
mDragObject.cancelled = true;
mDragObject.dragComplete = true;
- mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false);
+ if (!mIsInPreDrag) {
+ mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false);
+ }
}
endDrag();
}
private void endDrag() {
if (isDragging()) {
mDragDriver = null;
- mOptions = null;
clearScrollRunnable();
boolean isDeferred = false;
if (mDragObject.dragView != null) {
// Only end the drag if we are not deferred
if (!isDeferred) {
- for (DragListener listener : new ArrayList<>(mListeners)) {
- listener.onDragEnd();
- }
+ callOnDragEnd();
}
}
releaseVelocityTracker();
}
+ private void callOnDragEnd() {
+ if (mIsInPreDrag && mOptions.preDragCondition != null) {
+ mOptions.preDragCondition.onPreDragEnd(false /* dragStarted*/);
+ }
+ mIsInPreDrag = false;
+ mOptions = null;
+ for (DragListener listener : new ArrayList<>(mListeners)) {
+ listener.onDragEnd();
+ }
+ }
+
/**
* This only gets called as a result of drag view cleanup being deferred in endDrag();
*/
if (mDragObject.deferDragViewCleanupPostAnimation) {
// If we skipped calling onDragEnd() before, do it now
- for (DragListener listener : new ArrayList<>(mListeners)) {
- listener.onDragEnd();
- }
+ callOnDragEnd();
}
}
mLastTouch[1] = y;
checkScrollState(x, y);
- if (mIsDragDeferred && mOptions.deferDragCondition.shouldStartDeferredDrag(
- Math.hypot(x - mMotionDownX, y - mMotionDownY))) {
- startDeferredDrag();
+ if (mIsInPreDrag && mOptions.preDragCondition != null
+ && mOptions.preDragCondition.shouldStartDrag(mDistanceSinceScroll)) {
+ callOnDragStart();
}
}
(vec1.length() * vec2.length()));
}
- void drop(DropTarget dropTarget, float x, float y, PointF flingVel) {
+ private void drop(DropTarget dropTarget, float x, float y, PointF flingVel) {
final int[] coordinates = mCoordinatesTemp;
mDragObject.x = coordinates[0];
}
}
final View dropTargetAsView = dropTarget instanceof View ? (View) dropTarget : null;
- mDragObject.dragSource.onDropCompleted(
- dropTargetAsView, mDragObject, flingVel != null, accepted);
mLauncher.getUserEventDispatcher().logDragNDrop(mDragObject, dropTargetAsView);
- if (mIsDragDeferred) {
- mOptions.deferDragCondition.onDropBeforeDeferredDrag();
+ if (!mIsInPreDrag) {
+ mDragObject.dragSource.onDropCompleted(
+ dropTargetAsView, mDragObject, flingVel != null, accepted);
+ } else {
+ // Only defer the drag view cleanup if the drag source handles the drop.
+ if (!(mDragObject.dragSource instanceof DropTarget)) {
+ mDragObject.deferDragViewCleanupPostAnimation = false;
+ }
}
}
mLauncher.closeShortcutsContainer();
// We let touches on the original icon go through so that users can launch
// the app with one tap if they don't find a shortcut they want.
- return !isEventOverView(deepShortcutsContainer.getDeferredDragIcon(), ev);
+ return !isEventOverView(deepShortcutsContainer.getOriginalIcon(), ev);
}
}
}
package com.android.launcher3.dragndrop;
import android.graphics.Point;
+import android.support.annotation.CallSuper;
+import android.view.View;
/**
* Set of options to control the drag and drop behavior.
/** Specifies the start location for the system DnD, null when using internal DnD */
public Point systemDndStartPoint = null;
- /** Determines when a deferred drag should start. By default, drags aren't deferred at all. */
- public DeferDragCondition deferDragCondition = new DeferDragCondition();
+ /** Determines when a pre-drag should transition to a drag. By default, this is immediate. */
+ public PreDragCondition preDragCondition = null;
/**
* Specifies a condition that must be met before DragListener#onDragStart() is called.
* DragController#startDrag().
*
* This condition can be overridden, and callbacks are provided for the following cases:
- * - The drag starts, but onDragStart() is deferred (onDeferredDragStart()).
- * - The drag ends before the condition is met (onDropBeforeDeferredDrag()).
- * - The condition is met (onDragStart()).
+ * - The pre-drag starts, but onDragStart() is deferred (onPreDragStart()).
+ * - The pre-drag ends before the condition is met (onPreDragEnd(false)).
+ * - The actual drag starts when the condition is met (onPreDragEnd(true)).
*/
- public static class DeferDragCondition {
- public boolean shouldStartDeferredDrag(double distanceDragged) {
- return true;
- }
+ public interface PreDragCondition {
+
+ public boolean shouldStartDrag(double distanceDragged);
/**
- * The drag has started, but onDragStart() is deferred.
- * This happens when shouldStartDeferredDrag() returns true.
+ * The pre-drag has started, but onDragStart() is
+ * deferred until shouldStartDrag() returns true.
*/
- public void onDeferredDragStart() {
- // Do nothing.
- }
+ void onPreDragStart();
/**
- * User dropped before the deferred condition was met,
- * i.e. before shouldStartDeferredDrag() returned true.
+ * The pre-drag has ended. This gets called at the same time as onDragStart()
+ * if the condition is met, otherwise at the same time as onDragEnd().
+ * @param dragStarted Whether the pre-drag ended because the actual drag started.
+ * This will be true if the condition was met, otherwise false.
*/
- public void onDropBeforeDeferredDrag() {
- // Do nothing
- }
-
- /** onDragStart() has been called, now we are in a normal drag. */
- public void onDragStart() {
- // Do nothing
- }
+ void onPreDragEnd(boolean dragStarted);
}
}
public boolean onLongClick(View v) {
// Return if global dragging is not enabled
if (!mLauncher.isDraggingEnabled()) return true;
- DragOptions dragOptions = new DragOptions();
- if (v instanceof BubbleTextView) {
- BubbleTextView icon = (BubbleTextView) v;
- if (icon.hasDeepShortcuts()) {
- DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon(icon);
- if (dsc != null) {
- dragOptions.deferDragCondition = dsc.createDeferDragCondition(null);
- }
- }
- }
- return startDrag(v, dragOptions);
+ return startDrag(v, new DragOptions());
}
public boolean startDrag(View v, DragOptions options) {
if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target != this) {
replaceFolderWithFinalItem();
}
- } else if (!mDragController.isDeferringDrag()) {
+ } else {
// The drag failed, we need to return the item to the folder
ShortcutInfo info = (ShortcutInfo) d.dragInfo;
View icon = (mCurrentDragView != null && mCurrentDragView.getTag() == info)
mIsExternalDrag = false;
} else {
currentDragView = mCurrentDragView;
- if (!mDragController.isDeferringDrag()) {
+ // The view was never removed from this folder if we are still in the pre-drag.
+ if (!mDragController.isInPreDrag()) {
mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
}
}
mItemsInvalidated = true;
rearrangeChildren();
- if (!mDragController.isDeferringDrag()) {
+ // The ShortcutInfo was never removed if we are still in the pre-drag.
+ if (!mDragController.isInPreDrag()) {
// Temporarily suppress the listener, as we did all the work already here.
try (SuppressInfoChanges s = new SuppressInfoChanges()) {
mInfo.add(si, false);
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
-import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.graphics.TriangleShape;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
private final ShortcutMenuAccessibilityDelegate mAccessibilityDelegate;
private final boolean mIsRtl;
- private BubbleTextView mDeferredDragIcon;
+ private BubbleTextView mOriginalIcon;
private final Rect mTempRect = new Rect();
private Point mIconLastTouchPos = new Point();
private boolean mIsLeftAligned;
animateOpen();
- deferDrag(originalIcon);
+ mOriginalIcon = originalIcon;
+ mLauncher.getDragController().addDragListener(this);
// Load the shortcuts on a background thread and update the container as it animates.
final Looper workerLooper = LauncherModel.getWorkerLooper();
return arrowView;
}
- private void deferDrag(BubbleTextView originalIcon) {
- mDeferredDragIcon = originalIcon;
- mLauncher.getDragController().addDragListener(this);
- }
-
- public BubbleTextView getDeferredDragIcon() {
- return mDeferredDragIcon;
+ public BubbleTextView getOriginalIcon() {
+ return mOriginalIcon;
}
/**
* Current behavior:
* - Start the drag if the touch passes a certain distance from the original touch down.
*/
- public DragOptions.DeferDragCondition createDeferDragCondition(final Runnable onDragStart) {
- return new DragOptions.DeferDragCondition() {
+ public DragOptions.PreDragCondition createPreDragCondition() {
+ return new DragOptions.PreDragCondition() {
@Override
- public boolean shouldStartDeferredDrag(double distanceDragged) {
+ public boolean shouldStartDrag(double distanceDragged) {
return distanceDragged > mStartDragThreshold;
}
@Override
- public void onDeferredDragStart() {
- mDeferredDragIcon.setVisibility(INVISIBLE);
- }
-
- @Override
- public void onDropBeforeDeferredDrag() {
- mLauncher.getUserEventDispatcher().logDeepShortcutsOpen(mDeferredDragIcon);
- if (!mIsAboveIcon) {
- mDeferredDragIcon.setTextVisibility(false);
- }
+ public void onPreDragStart() {
+ mOriginalIcon.setVisibility(INVISIBLE);
}
@Override
- public void onDragStart() {
- if (onDragStart != null) {
- onDragStart.run();
+ public void onPreDragEnd(boolean dragStarted) {
+ if (!dragStarted) {
+ mOriginalIcon.setVisibility(VISIBLE);
+ mLauncher.getUserEventDispatcher().logDeepShortcutsOpen(mOriginalIcon);
+ if (!mIsAboveIcon) {
+ mOriginalIcon.setTextVisibility(false);
+ }
}
}
};
}
}
}
- mDeferredDragIcon.setVisibility(VISIBLE);
}
@Override
}
mIsOpen = false;
mDeferContainerRemoval = false;
- boolean isInHotseat = ((ItemInfo) mDeferredDragIcon.getTag()).container
+ boolean isInHotseat = ((ItemInfo) mOriginalIcon.getTag()).container
== LauncherSettings.Favorites.CONTAINER_HOTSEAT;
- mDeferredDragIcon.setTextVisibility(!isInHotseat);
+ mOriginalIcon.setTextVisibility(!isInHotseat);
mLauncher.getDragController().removeDragListener(this);
mLauncher.getDragLayer().removeView(this);
}
}
List<String> ids = launcher.getShortcutIdsForItem((ItemInfo) icon.getTag());
if (!ids.isEmpty()) {
- // There are shortcuts associated with the app, so defer its drag.
final DeepShortcutsContainer container =
(DeepShortcutsContainer) launcher.getLayoutInflater().inflate(
R.layout.deep_shortcuts_container, launcher.getDragLayer(), false);