Ejemplo n.º 1
0
  /** This only gets called as a result of drag view cleanup being deferred in endDrag(); */
  void onDeferredEndDrag(DragView dragView) {
    dragView.remove();

    if (mDragObject.deferDragViewCleanupPostAnimation) {
      // If we skipped calling onDragEnd() before, do it now
      for (DragListener listener : mListeners) {
        listener.onDragEnd();
      }
    }
  }
Ejemplo n.º 2
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);
  }