Ejemplo n.º 1
0
 public void setDragProgressDelegate(DragProgressDelegate delegate) {
   mDragProgressDelegate = delegate;
   if (mDragProgressDelegate != null) {
     if (!mDragProgressDelegate.progressInActionMode() && mUseAsAdapterViewChild) {
       // Set a non null on long click listener to make sure
       // ACTION_MOVE and ACTION_UP could be dispatched for the view
       // even its parent view is a AdapterView with OnItemClickListener set
       if (!mHasExtraLongClickListener) {
         setDefaultOnLongClickListener(mDefaultOnLongClickListener);
       }
     } else if (mDragProgressDelegate.progressInActionMode()) {
       // Long click gesture is used for drag detection in onTouchEvent procedure
       setLongClickable(false);
       // If drag progress in action mode, this view must be used as adapter view child
       // Set the value in case that the maintainer of this view forget to call the setter
       mUseAsAdapterViewChild = true;
     }
   }
 }
Ejemplo n.º 2
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (KLOG) Log.i(TAG, "onTouchEvent");
    if (!mDragable || mDragProgressDelegate == null) {
      return super.onTouchEvent(event);
    }

    if (mSelectedInActionMode) {
      if (KLOG) Log.i(TAG, "Drag detection procedure in action mode");
    }

    boolean result = super.onTouchEvent(event);
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        if (KLOG) Log.i(TAG, "ACTION down");
        mIsNewDragOp = true;
        mDragging = false;
        mDragCanceled = false;
        if (mSelectedInActionMode || !mDragProgressDelegate.progressInActionMode()) {
          mSavedDownTime = System.currentTimeMillis();
          result = true;
        }
        break;
      case MotionEvent.ACTION_MOVE:
        if (KLOG)
          Log.i(
              TAG,
              "ACTION MOVE"
                  + " parent-width: "
                  + this.getWidth()
                  + " parent-height: "
                  + this.getHeight()
                  + " touch x: "
                  + event.getX()
                  + " touch y: "
                  + event.getY());
        if (mSelectedInActionMode || !mDragProgressDelegate.progressInActionMode()) {
          long interval = System.currentTimeMillis() - mSavedDownTime;
          if (KLOG) Log.i(TAG, "Interval is: " + interval);
          if (interval > DRAG_DECISION_INTERVAL) {
            if (mIsNewDragOp) {
              prepareDrag();
            } else {
              if (mDragProgressDelegate != null) {
                if (!mDragProgressDelegate.isDragOpDelegated(this)) {
                  if (KLOG) Log.i(TAG, "Drag is not delegated.");
                  if (mDragProgressDelegate.isDragPrepared(this) && !mDragging) {
                    if (KLOG) Log.i(TAG, "Drag is prepared, do drag!");
                    doDrag(mDragProgressDelegate.generateDragShadow(this));
                    mDragProgressDelegate.notifyAutoDragStarted(this);
                  }
                } else {
                  if (KLOG) Log.i(TAG, "Drag is delegated.");
                }
              } else {
                if (!mDragging) {
                  doDrag(new DragShadowBuilder(this));
                }
              }
            }
          }
          result = true;
        }
        break;
      case MotionEvent.ACTION_UP:
        if (KLOG) Log.i(TAG, "ACTION up");
        mIsNewDragOp = true;
        if (mSelectedInActionMode || !mDragProgressDelegate.progressInActionMode()) {
          long interval = System.currentTimeMillis() - mSavedDownTime;
          if (KLOG) Log.i(TAG, "Interval is: " + interval);
          if (interval > DRAG_DECISION_INTERVAL) {
            if (mDragProgressDelegate != null) {
              if (!mDragProgressDelegate.isDragPrepared(this)) {
                mDragProgressDelegate.interruptDragPreparation(this);
              }

              mDragReady = false;
              if (KLOG) Log.i(TAG, "revert drag prepartion for action up.");
              mDragProgressDelegate.revertDragPreparation(this);
            }
          } else {
            doClick(mSelectedInActionMode);
          }
        } else {
          doClick(mSelectedInActionMode);
        }

        result = true;
        break;
    }

    if (mSelectedInActionMode) {
      return result;
    } else {
      return super.onTouchEvent(event);
    }
  }