private boolean drop(float x, float y) {
    invalidate();

    final int[] coordinates = mDropCoordinates;
    DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);

    if (mTagPopup != null) {
      // don't perform dismiss action when the popup closes
      ((QuickActionWindow) mTagPopup).setOnDismissListener(null);
    }
    if (dropTarget != null) {
      dropTarget.onDragExit(
          mDragSource,
          coordinates[0],
          coordinates[1],
          (int) mTouchOffsetX,
          (int) mTouchOffsetY,
          mDragInfo);
      if (dropTarget.acceptDrop(
          mDragSource,
          coordinates[0],
          coordinates[1],
          (int) mTouchOffsetX,
          (int) mTouchOffsetY,
          mDragInfo)) {
        boolean success = false;
        if (mTagPopup == null || !(dropTarget instanceof Workspace)) {
          mTagPopup = null;
          dropTarget.onDrop(
              mDragSource,
              coordinates[0],
              coordinates[1],
              (int) mTouchOffsetX,
              (int) mTouchOffsetY,
              mDragInfo);
          success = true;
        }
        mDragSource.onDropCompleted((View) dropTarget, success);
        return true;
      } else {
        mDragSource.onDropCompleted((View) dropTarget, false);
        return true;
      }
    }
    return false;
  }
예제 #2
0
  private boolean drop(float x, float y) {

    final int[] coordinates = mCoordinatesTemp;
    DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);

    if (dropTarget != null) {
      dropTarget.onDragExit(
          mDragSource,
          coordinates[0],
          coordinates[1],
          (int) mTouchOffsetX,
          (int) mTouchOffsetY,
          mDragView,
          mDragInfo);
      if (dropTarget.acceptDrop(
          mDragSource,
          coordinates[0],
          coordinates[1],
          (int) mTouchOffsetX,
          (int) mTouchOffsetY,
          mDragView,
          mDragInfo)) {
        dropTarget.onDrop(
            mDragSource,
            coordinates[0],
            coordinates[1],
            (int) mTouchOffsetX,
            (int) mTouchOffsetY,
            mDragView,
            mDragInfo);
        mDragSource.onDropCompleted((View) dropTarget, true);
        return true;
      } else {
        mDragSource.onDropCompleted((View) dropTarget, false);
        return true;
      }
    }
    return false;
  }
예제 #3
0
 /** Stop dragging without dropping. */
 public void cancelDrag() {
   if (mDragging) {
     final int[] coordinates = mCoordinatesTemp;
     if (mLastDropTarget != null) {
       mLastDropTarget.onDragExit(
           mDragSource,
           coordinates[0],
           coordinates[1],
           (int) mTouchOffsetX,
           (int) mTouchOffsetY,
           mDragView,
           mDragInfo);
     }
     mDragSource.onDropCompleted((View) mLastDropTarget, false);
   }
   endDrag();
 }
예제 #4
0
  private boolean drop(float x, float y) {

    final int[] coordinates = mCoordinatesTemp;

    DropTarget dropTarget2 = findDropTarget((int) x, (int) y, coordinates);
    DropTarget dropTarget;
    if (usingFixedDropTarget) {
      dropTarget = fixedDropTarget;
    } else {
      dropTarget = dropTarget2;
    }

    if (dropTarget != null && dropTarget2 != null) {

      dropTarget.onDragExit(
          mDragSource,
          coordinates[0],
          coordinates[1],
          (int) mTouchOffsetX,
          (int) mTouchOffsetY,
          mDragView,
          mDragInfo);
      dropTarget2.onDragExit(
          mDragSource,
          coordinates[0],
          coordinates[1],
          (int) mTouchOffsetX,
          (int) mTouchOffsetY,
          mDragView,
          mDragInfo);

      // Condicion para no caer en la barra de arriba en Create
      if (createMode && y - mTouchOffsetY < 50) return false;

      if (dropTarget.acceptDrop(
          mDragSource,
          coordinates[0],
          coordinates[1],
          (int) mTouchOffsetX,
          (int) mTouchOffsetY,
          mDragView,
          mDragInfo)) {

        if (powerPointMode) {
          // este es el dropPanel
          ((DropPanel) dropTarget)
              .updateObject(
                  mDragSource,
                  coordinates[0],
                  coordinates[1],
                  (int) mTouchOffsetX,
                  (int) mTouchOffsetY,
                  mDragView,
                  mDragInfo);
          // este es el dragLayer
          dropTarget2.onDrop(
              mDragSource,
              coordinates[0],
              coordinates[1],
              (int) mTouchOffsetX,
              (int) mTouchOffsetY,
              mDragView,
              mDragInfo);

        } else {
          dropTarget.onDrop(
              mDragSource,
              (int) x,
              (int) y,
              (int) mTouchOffsetX,
              (int) mTouchOffsetY,
              mDragView,
              mDragInfo);

          if (!(dropTarget2
              instanceof Mochila)) { // No queremos meter 2 veces los objetos en la mochila
            dropTarget2.onDrop(
                mDragSource,
                (int) x,
                (int) y,
                (int) mTouchOffsetX,
                (int) mTouchOffsetY,
                mDragView,
                mDragInfo);
          }
        }
        mDragSource.onDropCompleted((View) dropTarget, true);

        return true;
      } else {
        mDragSource.onDropCompleted((View) dropTarget, false);
        return true;
      }
    }
    return false;
  }