Ejemplo n.º 1
0
  public void doClick(boolean selectedInActionMode) {
    if (selectedInActionMode && mDragInfo != null && mDragInfo.parentView instanceof AbsListView) {
      Log.i(TAG, "Do click in action mode.");
      if (mDragReady) {
        if (mDragProgressDelegate != null) {
          mDragProgressDelegate.revertDragPreparation(this);
        }
        mDragReady = false;
      } else {
        // Due to the interactive ability of this widget
        AbsListView parentListView = (AbsListView) mDragInfo.parentView;
        int position = mDragInfo.positionAsChild;
        if (parentListView != null && position >= 0) {
          boolean lastChecked = parentListView.isItemChecked(position);

          parentListView.setItemChecked(position, !lastChecked);
          parentListView.invalidate();
        }
      }
    } else {
      Log.i(TAG, "Do click in non action mode .");
      if (mDragInfo.parentView instanceof AbsListView && mDragInfo.positionAsChild >= 0) {
        AbsListView parentListView = (AbsListView) mDragInfo.parentView;
        int position = mDragInfo.positionAsChild;
        OnItemClickListener clickListener = parentListView.getOnItemClickListener();
        if (clickListener != null) {
          clickListener.onItemClick(parentListView, this, position, this.getId());
        }
      }
    }
  }
Ejemplo n.º 2
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.º 3
0
  private void prepareDrag() {
    if (!mDragReady) {
      if (mDragProgressDelegate != null) {
        Log.i(TAG, "Prepare for ADDView, hashCode: " + this.hashCode());
        mDragProgressDelegate.prepareDrag(this);
      }
    } else {
      Log.i(TAG, "Drag is already prepared.");
    }

    mIsNewDragOp = false;
  }
Ejemplo n.º 4
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);
    }
  }