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()); } } } }
@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); } }