コード例 #1
0
  /** Start dragging a view. */
  private boolean startDrag(View v) {
    // Let the DragController initiate a drag-drop sequence.
    // I use the dragInfo to pass along the object being dragged.
    // I'm not sure how the Launcher designers do this.

    mDragging = true;
    Object dragInfo = v;
    mDragController.startDrag(v, mSelectionDragLayer, dragInfo, DragController.DRAG_ACTION_MOVE);
    return true;
  }
コード例 #2
0
  /**
   * Creates the selection layer.
   *
   * @param context
   */
  protected void createSelectionLayer(Context context) {

    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mSelectionDragLayer = (DragLayer) inflater.inflate(R.layout.selection_drag_layer, null);

    // Make sure it's filling parent
    mDragController = new DragController(context);
    mDragController.setDragListener(this);
    mDragController.addDropTarget(mSelectionDragLayer);
    mSelectionDragLayer.setDragController(mDragController);

    mStartSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.startHandle);
    mStartSelectionHandle.setTag(new Integer(SELECTION_START_HANDLE));
    mEndSelectionHandle = (ImageView) mSelectionDragLayer.findViewById(R.id.endHandle);
    mEndSelectionHandle.setTag(new Integer(SELECTION_END_HANDLE));

    OnTouchListener handleTouchListener =
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {

            boolean handledHere = false;

            final int action = event.getAction();

            // Down event starts drag for handle.
            if (action == MotionEvent.ACTION_DOWN) {
              handledHere = startDrag(v);
              mLastTouchedSelectionHandle = (Integer) v.getTag();
            }

            return handledHere;
          }
        };

    mStartSelectionHandle.setOnTouchListener(handleTouchListener);
    mEndSelectionHandle.setOnTouchListener(handleTouchListener);
  }