Ejemplo n.º 1
0
  private void dropOnFlingToDeleteTarget(float x, float y, PointF vel) {
    final int[] coordinates = mCoordinatesTemp;

    mDragObject.x = coordinates[0];
    mDragObject.y = coordinates[1];

    // Clean up dragging on the target if it's not the current fling delete
    // target otherwise,
    // start dragging to it.
    if (mLastDropTarget != null && mFlingToDeleteDropTarget != mLastDropTarget) {
      mLastDropTarget.onDragExit(mDragObject);
    }

    // Drop onto the fling-to-delete target
    boolean accepted = false;
    mFlingToDeleteDropTarget.onDragEnter(mDragObject);
    // We must set dragComplete to true _only_ after we "enter" the
    // fling-to-delete target for
    // "drop"
    mDragObject.dragComplete = true;
    mFlingToDeleteDropTarget.onDragExit(mDragObject);
    if (mFlingToDeleteDropTarget.acceptDrop(mDragObject)) {
      mFlingToDeleteDropTarget.onFlingToDelete(mDragObject, mDragObject.x, mDragObject.y, vel);
      accepted = true;
    }
    mDragObject.dragSource.onDropCompleted(
        (View) mFlingToDeleteDropTarget, mDragObject, true, accepted);
  }
Ejemplo n.º 2
0
 public void forceTouchMove() {
   int[] dummyCoordinates = mCoordinatesTemp;
   DropTarget dropTarget = findDropTarget(mLastTouch[0], mLastTouch[1], dummyCoordinates);
   mDragObject.x = dummyCoordinates[0];
   mDragObject.y = dummyCoordinates[1];
   checkTouchMove(dropTarget);
 }
Ejemplo n.º 3
0
 /** Stop dragging without dropping. */
 public void cancelDrag() {
   if (mDragging) {
     if (mLastDropTarget != null) {
       mLastDropTarget.onDragExit(mDragObject);
     }
     mDragObject.deferDragViewCleanupPostAnimation = false;
     mDragObject.cancelled = true;
     mDragObject.dragComplete = true;
     mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false);
   }
   endDrag();
 }
Ejemplo n.º 4
0
  private void drop(float x, float y) {
    final int[] coordinates = mCoordinatesTemp;
    final DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);

    mDragObject.x = coordinates[0];
    mDragObject.y = coordinates[1];
    boolean accepted = false;
    if (dropTarget != null) {
      mDragObject.dragComplete = true;
      dropTarget.onDragExit(mDragObject);
      if (dropTarget.acceptDrop(mDragObject)) {
        dropTarget.onDrop(mDragObject);
        accepted = true;
      }
    }
    mDragObject.dragSource.onDropCompleted((View) dropTarget, mDragObject, false, accepted);
  }
Ejemplo n.º 5
0
  private void handleMoveEvent(int x, int y) {
    mDragObject.dragView.move(x, y);

    // Drop on someone?
    final int[] coordinates = mCoordinatesTemp;
    DropTarget dropTarget = findDropTarget(x, y, coordinates);
    mDragObject.x = coordinates[0];
    mDragObject.y = coordinates[1];
    checkTouchMove(dropTarget);

    // Check if we are hovering over the scroll areas
    mDistanceSinceScroll +=
        Math.sqrt(Math.pow(mLastTouch[0] - x, 2) + Math.pow(mLastTouch[1] - y, 2));
    mLastTouch[0] = x;
    mLastTouch[1] = y;
    checkScrollState(x, y);
  }
Ejemplo n.º 6
0
  private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
    final Rect r = mRectTemp;

    final ArrayList<DropTarget> dropTargets = mDropTargets;
    final int count = dropTargets.size();
    for (int i = count - 1; i >= 0; i--) {
      DropTarget target = dropTargets.get(i);
      if (!target.isDropEnabled()) continue;

      target.getHitRectRelativeToDragLayer(r);

      mDragObject.x = x;
      mDragObject.y = y;
      if (r.contains(x, y)) {

        dropCoordinates[0] = x;
        dropCoordinates[1] = y;
        mLauncher.getDragLayer().mapCoordInSelfToDescendent((View) target, dropCoordinates);

        return target;
      }
    }
    return null;
  }
Ejemplo n.º 7
0
  private void endDrag() {
    if (mDragging) {
      mDragging = false;
      clearScrollRunnable();
      boolean isDeferred = false;
      if (mDragObject.dragView != null) {
        isDeferred = mDragObject.deferDragViewCleanupPostAnimation;
        if (!isDeferred) {
          mDragObject.dragView.remove();
        }
        mDragObject.dragView = null;
      }

      // Only end the drag if we are not deferred
      if (!isDeferred) {
        for (DragListener listener : mListeners) {
          listener.onDragEnd();
        }
      }
    }

    releaseVelocityTracker();
  }
Ejemplo n.º 8
0
  /**
   * Starts a drag.
   *
   * @param b The bitmap to display as the drag image. It will be re-scaled to the enlarged size.
   * @param dragLayerX The x position in the DragLayer of the left-top of the bitmap.
   * @param dragLayerY The y position in the DragLayer of the left-top of the bitmap.
   * @param source An object representing where the drag originated
   * @param dragInfo The data associated with the object that is being dragged
   * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or {@link
   *     #DRAG_ACTION_COPY}
   * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. Makes
   *     dragging feel more precise, e.g. you can clip out a transparent border
   */
  public void startDrag(
      Bitmap b,
      int dragLayerX,
      int dragLayerY,
      DragSource source,
      Object dragInfo,
      int dragAction,
      Point dragOffset,
      Rect dragRegion,
      float initialDragViewScale) {
    if (PROFILE_DRAWING_DURING_DRAG) {
      android.os.Debug.startMethodTracing("Launcher");
    }

    // Hide soft keyboard, if visible
    if (mInputMethodManager == null) {
      mInputMethodManager =
          (InputMethodManager) mLauncher.getSystemService(Context.INPUT_METHOD_SERVICE);
    }
    mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0);

    for (DragListener listener : mListeners) {
      listener.onDragStart(source, dragInfo, dragAction);
    }

    final int registrationX = mMotionDownX - dragLayerX;
    final int registrationY = mMotionDownY - dragLayerY;

    final int dragRegionLeft = dragRegion == null ? 0 : dragRegion.left;
    final int dragRegionTop = dragRegion == null ? 0 : dragRegion.top;

    mDragging = true;

    mDragObject = new DropTarget.DragObject();

    mDragObject.dragComplete = false;
    mDragObject.xOffset = mMotionDownX - (dragLayerX + dragRegionLeft);
    mDragObject.yOffset = mMotionDownY - (dragLayerY + dragRegionTop);
    mDragObject.dragSource = source;
    mDragObject.dragInfo = dragInfo;

    final DragView dragView =
        mDragObject.dragView =
            new DragView(
                mLauncher,
                b,
                registrationX,
                registrationY,
                0,
                0,
                b.getWidth(),
                b.getHeight(),
                initialDragViewScale);

    if (dragOffset != null) {
      dragView.setDragVisualizeOffset(new Point(dragOffset));
    }
    if (dragRegion != null) {
      dragView.setDragRegion(new Rect(dragRegion));
    }

    mLauncher.getDragLayer().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    dragView.show(mMotionDownX, mMotionDownY);
    handleMoveEvent(mMotionDownX, mMotionDownY);
  }