Example usage for android.view ViewConfiguration getPressedStateDuration

List of usage examples for android.view ViewConfiguration getPressedStateDuration

Introduction

In this page you can find the example usage for android.view ViewConfiguration getPressedStateDuration.

Prototype

public static int getPressedStateDuration() 

Source Link

Usage

From source file:com.app.afteryou.ui.staggered.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!isEnabled()) {
        // A disabled view that is clickable still consumes the touch
        // events, it just doesn't respond to them.
        return isClickable() || isLongClickable();
    }//from   w  w w . j  ava2  s . co  m
    mVelocityTracker.addMovement(ev);
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY());

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mVelocityTracker.clear();
        mScroller.abortAnimation();
        mLastTouchY = ev.getY();
        mLastTouchX = ev.getX();
        motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderY = 0;

        if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0
                && getAdapter().isEnabled(motionPosition)) {
            mTouchMode = TOUCH_MODE_DOWN;

            mBeginClick = true;

            if (mPendingCheckForTap == null) {
                mPendingCheckForTap = new CheckForTap();
            }

            postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
        }

        mMotionPosition = motionPosition;
        invalidate();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, index);
        final float dy = y - mLastTouchY + mTouchRemainderY;
        final int deltaY = (int) dy;
        mTouchRemainderY = dy - deltaY;

        if (Math.abs(dy) > mTouchSlop) {
            setTouchMode(TOUCH_MODE_DRAGGING);
        }

        if (mTouchMode == TOUCH_MODE_DRAGGING) {
            mLastTouchY = y;

            if (!trackMotionScroll(deltaY, true)) {
                // Break fling velocity if we impacted an edge.
                mVelocityTracker.clear();
            }
        }

        updateSelectorState();
    }
        break;

    case MotionEvent.ACTION_CANCEL:
        updateSelectorState();
        setPressed(false);
        View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
        if (motionView != null) {
            motionView.setPressed(false);
        }
        final Handler handler = getHandler();
        if (handler != null) {
            handler.removeCallbacks(mPendingCheckForLongPress);
        }

        if (mTopEdge != null) {
            mTopEdge.onRelease();
            mBottomEdge.onRelease();
        }

        setTouchMode(TOUCH_MODE_IDLE);
        break;

    case MotionEvent.ACTION_UP: {
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
        final int prevTouchMode = mTouchMode;
        if (Math.abs(velocity) > mFlingVelocity) { // TODO
            setTouchMode(TOUCH_MODE_FLINGING);
            mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
            mLastTouchY = 0;
            ViewCompat.postInvalidateOnAnimation(this);
        } else {
            setTouchMode(TOUCH_MODE_IDLE);
        }

        if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
            // TODO : handle
            mTouchMode = TOUCH_MODE_TAP;
        } else {
            mTouchMode = TOUCH_MODE_REST;
        }

        switch (prevTouchMode) {
        case TOUCH_MODE_DOWN:
        case TOUCH_MODE_TAP:
        case TOUCH_MODE_DONE_WAITING:
            final View child = getChildAt(motionPosition - mFirstPosition);
            final float x = ev.getX();
            final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight();
            if (child != null && !child.hasFocusable() && inList) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }

                if (mPerformClick == null) {
                    invalidate();
                    mPerformClick = new PerformClick();
                }

                final PerformClick performClick = mPerformClick;
                performClick.mClickMotionPosition = motionPosition;
                performClick.rememberWindowAttachCount();

                if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                    final Handler handlerTouch = getHandler();
                    if (handlerTouch != null) {
                        handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap
                                : mPendingCheckForLongPress);
                    }

                    if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        mTouchMode = TOUCH_MODE_TAP;

                        layoutChildren(mDataChanged);
                        child.setPressed(true);
                        positionSelector(mMotionPosition, child);
                        setPressed(true);
                        if (mSelector != null) {
                            Drawable d = mSelector.getCurrent();
                            if (d != null && d instanceof TransitionDrawable) {
                                ((TransitionDrawable) d).resetTransition();
                            }
                        }
                        if (mTouchModeReset != null) {
                            removeCallbacks(mTouchModeReset);
                        }
                        mTouchModeReset = new Runnable() {
                            @Override
                            public void run() {
                                mTouchMode = TOUCH_MODE_REST;
                                child.setPressed(false);
                                setPressed(false);
                                if (!mDataChanged) {
                                    performClick.run();
                                }
                            }
                        };
                        postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());

                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                    }
                    return true;
                } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                    performClick.run();
                }
            }

            mTouchMode = TOUCH_MODE_REST;
        }
        mBeginClick = false;
        updateSelectorState();
    }
        break;
    }
    return true;
}

From source file:mrfu.blurstaggered.lib.view.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);/*from  w  w w.j  a va  2  s .  co  m*/
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY());

    switch (action) {
    case MotionEvent.ACTION_DOWN:

        mVelocityTracker.clear();
        mScroller.abortAnimation();
        mLastTouchY = ev.getY();
        mLastTouchX = ev.getX();
        motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderY = 0;

        if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0
                && getAdapter().isEnabled(motionPosition)) {
            mTouchMode = TOUCH_MODE_DOWN;

            mBeginClick = true;

            if (mPendingCheckForTap == null) {
                mPendingCheckForTap = new CheckForTap();
            }

            postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
        }

        mMotionPosition = motionPosition;
        invalidate();
        break;

    case MotionEvent.ACTION_MOVE:

        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, index);
        final float dy = y - mLastTouchY + mTouchRemainderY;
        final int deltaY = (int) dy;
        mTouchRemainderY = dy - deltaY;

        if (Math.abs(dy) > mTouchSlop) {
            mTouchMode = TOUCH_MODE_DRAGGING;
            //TODO MrFu
            setTouchMode(TOUCH_MODE_DRAGGING);
        }

        if (mTouchMode == TOUCH_MODE_DRAGGING) {
            mLastTouchY = y;

            if (!trackMotionScroll(deltaY, true)) {
                // Break fling velocity if we impacted an edge.
                mVelocityTracker.clear();
            }
        }

        updateSelectorState();
        break;

    case MotionEvent.ACTION_CANCEL:
        mTouchMode = TOUCH_MODE_IDLE;
        updateSelectorState();
        setPressed(false);
        View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
        if (motionView != null) {
            motionView.setPressed(false);
        }
        final Handler handler = getHandler();
        if (handler != null) {
            handler.removeCallbacks(mPendingCheckForLongPress);
        }

        if (mTopEdge != null) {
            mTopEdge.onRelease();
            mBottomEdge.onRelease();
        }

        mTouchMode = TOUCH_MODE_IDLE;
        setTouchMode(TOUCH_MODE_IDLE);
        break;

    case MotionEvent.ACTION_UP: {
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
        final int prevTouchMode = mTouchMode;

        if (Math.abs(velocity) > mFlingVelocity) { // TODO
            setTouchMode(TOUCH_MODE_FLINGING);
            mTouchMode = TOUCH_MODE_FLINGING;
            mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
            mLastTouchY = 0;
            invalidate();
        } else {
            mTouchMode = TOUCH_MODE_IDLE;
            setTouchMode(TOUCH_MODE_IDLE);
        }

        if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
            // TODO : handle
            mTouchMode = TOUCH_MODE_TAP;
        } else {
            mTouchMode = TOUCH_MODE_REST;
        }

        switch (prevTouchMode) {
        case TOUCH_MODE_DOWN:
        case TOUCH_MODE_TAP:
        case TOUCH_MODE_DONE_WAITING:
            final View child = getChildAt(motionPosition - mFirstPosition);
            final float x = ev.getX();
            final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight();
            if (child != null && !child.hasFocusable() && inList) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }

                if (mPerformClick == null) {
                    invalidate();
                    mPerformClick = new PerformClick();
                }

                final PerformClick performClick = mPerformClick;
                performClick.mClickMotionPosition = motionPosition;
                performClick.rememberWindowAttachCount();

                if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                    final Handler handlerTouch = getHandler();
                    if (handlerTouch != null) {
                        handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap
                                : mPendingCheckForLongPress);
                    }

                    if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        mTouchMode = TOUCH_MODE_TAP;

                        layoutChildren(mDataChanged);
                        child.setPressed(true);
                        positionSelector(mMotionPosition, child);
                        setPressed(true);
                        if (mSelector != null) {
                            Drawable d = mSelector.getCurrent();
                            if (d != null && d instanceof TransitionDrawable) {
                                ((TransitionDrawable) d).resetTransition();
                            }
                        }
                        if (mTouchModeReset != null) {
                            removeCallbacks(mTouchModeReset);
                        }
                        mTouchModeReset = new Runnable() {
                            @Override
                            public void run() {
                                mTouchMode = TOUCH_MODE_REST;
                                child.setPressed(false);
                                setPressed(false);
                                if (!mDataChanged) {
                                    performClick.run();
                                }
                            }
                        };
                        postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());

                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                    }
                    return true;
                } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                    performClick.run();
                }
            }

            mTouchMode = TOUCH_MODE_REST;
        }

        mBeginClick = false;

        updateSelectorState();
    }
        break;
    }
    return true;
}

From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);/*from   w w  w. jav a2  s  . co  m*/
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY());

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        LogUtil.d("----------onTouch ACTION_DOWN-------------");
        isOnTouch = true;

        mVelocityTracker.clear();
        mScroller.abortAnimation();
        mLastTouchY = ev.getY();
        mLastTouchX = ev.getX();
        motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderY = 0;

        if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0
                && getAdapter().isEnabled(motionPosition)) {
            mTouchMode = TOUCH_MODE_DOWN;

            mBeginClick = true;

            if (mPendingCheckForTap == null) {
                mPendingCheckForTap = new CheckForTap();
            }

            postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
        }

        mMotionPosition = motionPosition;
        invalidate();
        break;

    case MotionEvent.ACTION_MOVE:
        //LogUtil.d("----------onTouch ACTION_MOVE-------------");
        float currentY = ev.getRawY();
        if (mMoveTouchListener != null) {
            if (currentY - mFirstDownY >= 30) {
                mMoveTouchListener.onMoveDown();
            } else if (mFirstDownY - currentY >= 30) {
                mMoveTouchListener.onMoveUp();
            }
        }

        mFirstDownY = currentY;

        isOnTouch = true;
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, index);
        final float dy = y - mLastTouchY + mTouchRemainderY;
        final int deltaY = (int) dy;
        mTouchRemainderY = dy - deltaY;

        if (Math.abs(dy) > mTouchSlop) {
            mTouchMode = TOUCH_MODE_DRAGGING;
        }

        if (mTouchMode == TOUCH_MODE_DRAGGING) {
            mLastTouchY = y;

            if (!trackMotionScroll(deltaY, true)) {
                // Break fling velocity if we impacted an edge.
                mVelocityTracker.clear();
            }
            reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL, getFirstVisiblePosition(),
                    getLastPosition());
        }

        updateSelectorState();

        if (mFlingListener != null) {
            mFlingListener.onTouchFling();
        }
        break;

    case MotionEvent.ACTION_CANCEL:
        // LogUtil.d("----------onTouch ACTION_CANCEL-------------");
        isOnTouch = false;

        mTouchMode = TOUCH_MODE_IDLE;
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(),
                getLastPosition());
        updateSelectorState();
        setPressed(false);
        View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
        if (motionView != null) {
            motionView.setPressed(false);
        }
        final Handler handler = getHandler();
        if (handler != null) {
            handler.removeCallbacks(mPendingCheckForLongPress);
        }

        if (mTopEdge != null) {
            mTopEdge.onRelease();
            mBottomEdge.onRelease();
        }

        mTouchMode = TOUCH_MODE_IDLE;
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(),
                getLastPosition());

        break;

    case MotionEvent.ACTION_UP: {

        //LogUtil.d("----------onTouch ACTION_UP-------------");
        // LogUtil.d("TAG---------------onTouch ACTION_UP finish-----------" + mScroller.isFinished());
        isOnTouch = false;
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
        final int prevTouchMode = mTouchMode;

        if (Math.abs(velocity) > mFlingVelocity) { // TODO
            mTouchMode = TOUCH_MODE_FLINGING;
            mIsFling = true;
            mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
            mLastTouchY = 0;
            reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING, getFirstVisiblePosition(),
                    getLastPosition());
            invalidate();
        } else {
            mIsFling = true;
            mTouchMode = TOUCH_MODE_IDLE;
            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(),
                    getLastPosition());
        }

        if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
            // TODO : handle
            mTouchMode = TOUCH_MODE_TAP;
        } else {
            mTouchMode = TOUCH_MODE_REST;
            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(),
                    getLastPosition());
        }

        switch (prevTouchMode) {
        case TOUCH_MODE_DOWN:
        case TOUCH_MODE_TAP:
        case TOUCH_MODE_DONE_WAITING:
            final View child = getChildAt(motionPosition - mFirstPosition);
            final float x = ev.getX();
            final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight();
            if (child != null && !child.hasFocusable() && inList) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }

                if (mPerformClick == null) {
                    invalidate();
                    mPerformClick = new PerformClick();
                }

                final PerformClick performClick = mPerformClick;
                performClick.mClickMotionPosition = motionPosition;
                performClick.rememberWindowAttachCount();

                if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                    final Handler handlerTouch = getHandler();
                    if (handlerTouch != null) {
                        handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap
                                : mPendingCheckForLongPress);
                    }

                    if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        mTouchMode = TOUCH_MODE_TAP;

                        layoutChildren(mDataChanged);
                        child.setPressed(true);
                        positionSelector(mMotionPosition, child);
                        setPressed(true);
                        if (mSelector != null) {
                            Drawable d = mSelector.getCurrent();
                            if (d != null && d instanceof TransitionDrawable) {
                                ((TransitionDrawable) d).resetTransition();
                            }
                        }
                        if (mTouchModeReset != null) {
                            removeCallbacks(mTouchModeReset);
                        }
                        mTouchModeReset = new Runnable() {
                            @Override
                            public void run() {
                                mTouchMode = TOUCH_MODE_REST;
                                reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE,
                                        getFirstVisiblePosition(), getLastPosition());
                                child.setPressed(false);
                                setPressed(false);
                                if (!mDataChanged) {
                                    performClick.run();
                                }
                            }
                        };
                        postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());

                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(),
                                getLastPosition());
                    }
                    return true;
                } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                    performClick.run();
                }
            }

            mTouchMode = TOUCH_MODE_REST;
            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(),
                    getLastPosition());
        }

        mBeginClick = false;

        updateSelectorState();
    }
        break;
    }

    return true;
}

From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView3.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!isEnabled()) {
        // A disabled view that is clickable still consumes the touch
        // events, it just doesn't respond to them.
        return isClickable() || isLongClickable();
    }//from w w w  .  java  2s  . c om

    final int action = ev.getAction();

    View v;
    int deltaY;

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        mActivePointerId = ev.getPointerId(0);
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        int motionPosition = pointToPosition(x, y);
        if (!mDataChanged) {
            if ((mTouchMode != TOUCH_MODE_FLINGING) && (motionPosition >= 0)
                    && (getAdapter().isEnabled(motionPosition))) {
                // User clicked on an actual view (and was not stopping a fling). It might be a
                // click or a scroll. Assume it is a click until proven otherwise
                mTouchMode = TOUCH_MODE_DOWN;
                // FIXME Debounce
                if (mPendingCheckForTap == null) {
                    mPendingCheckForTap = new CheckForTap();
                }
                postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
            } else {
                if (ev.getEdgeFlags() != 0 && motionPosition < 0) {
                    // If we couldn't find a view to click on, but the down event was touching
                    // the edge, we will bail out and try again. This allows the edge correcting
                    // code in ViewRoot to try to find a nearby view to select
                    return false;
                }

                if (mTouchMode == TOUCH_MODE_FLINGING) {
                    // Stopped a fling. It is a scroll.
                    //createScrollingCache();
                    mTouchMode = TOUCH_MODE_DRAGGING;
                    mMotionCorrection = 0;
                    motionPosition = findMotionRow(y);
                    reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
                }
            }
        }

        if (motionPosition >= 0) {
            // Remember where the motion event started
            v = getChildAt(motionPosition - mFirstPosition);
            //mMotionViewOriginalTop=v.getTop();
        }
        mLastTouchX = x;
        mLastTouchY = y;
        mMotionPosition = motionPosition;
        mTouchRemainderY = Integer.MIN_VALUE;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = ev.findPointerIndex(mActivePointerId);
        final int y = (int) ev.getY(pointerIndex);
        deltaY = (int) (y - mLastTouchY);
        switch (mTouchMode) {
        case TOUCH_MODE_DOWN:
        case TOUCH_MODE_TAP:
        case TOUCH_MODE_DONE_WAITING:
            // Check if we have moved far enough that it looks more like a
            // scroll than a tap
            startScrollIfNeeded(deltaY);
            break;
        case TOUCH_MODE_DRAGGING:
            /*if (PROFILE_SCROLLING) {
                if (!mScrollProfilingStarted) {
                    Debug.startMethodTracing("AbsListViewScroll");
                    mScrollProfilingStarted=true;
                }
            }*/

            if (y != mTouchRemainderY) {
                deltaY -= mMotionCorrection;
                int incrementalDeltaY = mTouchRemainderY != Integer.MIN_VALUE ? (int) (y - mTouchRemainderY)
                        : deltaY;

                // No need to do all this work if we're not going to move anyway
                boolean atEdge = false;
                if (incrementalDeltaY != 0) {
                    atEdge = trackMotionScroll(deltaY, true);
                }

                // Check to see if we have bumped into the scroll limit
                if (atEdge && getChildCount() > 0) {
                    // Treat this like we're starting a new scroll from the current
                    // position. This will let the user start scrolling back into
                    // content immediately rather than needing to scroll back to the
                    // point where they hit the limit first.
                    int motionPosition = findMotionRow(y);
                    if (motionPosition >= 0) {
                        final View motionView = getChildAt(motionPosition - mFirstPosition);
                        //mMotionViewOriginalTop=motionView.getTop();
                    }
                    mLastTouchY = y;
                    mMotionPosition = motionPosition;
                    invalidate();
                }
                mTouchRemainderY = y;
            }
            break;
        }

        break;
    }

    case MotionEvent.ACTION_UP: {
        switch (mTouchMode) {
        case TOUCH_MODE_DOWN:
        case TOUCH_MODE_TAP:
        case TOUCH_MODE_DONE_WAITING:
            final int motionPosition = mMotionPosition;
            final View child = getChildAt(motionPosition - mFirstPosition);
            System.out.println("child:" + child + " motionPosition:" + motionPosition);
            if (child != null && !child.hasFocusable()) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }

                if (mPerformClick == null) {
                    mPerformClick = new PerformClick();
                }

                final PerformClick performClick = mPerformClick;
                //performClick.mChild=child;
                performClick.mClickMotionPosition = motionPosition;
                performClick.rememberWindowAttachCount();

                //mResurrectToPosition=motionPosition;

                if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                    //mLayoutMode=LAYOUT_NORMAL;
                    if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        mTouchMode = TOUCH_MODE_TAP;
                        layoutChildren(mDataChanged);
                        child.setPressed(true);
                        positionSelector(mMotionPosition, child);
                        setPressed(true);
                        if (mSelector != null) {
                            Drawable d = mSelector.getCurrent();
                            if (d != null && d instanceof TransitionDrawable) {
                                ((TransitionDrawable) d).resetTransition();
                            }
                        }
                        postDelayed(new Runnable() {
                            public void run() {
                                child.setPressed(false);
                                setPressed(false);
                                if (!mDataChanged) {
                                    post(performClick);
                                }
                                mTouchMode = TOUCH_MODE_REST;
                            }
                        }, ViewConfiguration.getPressedStateDuration());
                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                    }
                    return true;
                } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                    post(performClick);
                }
            }
            mTouchMode = TOUCH_MODE_REST;
            break;
        case TOUCH_MODE_DRAGGING:
            final int childCount = getChildCount();
            if (childCount > 0) {
                /*int top=getFillChildTop();
                int bottom=getFillChildBottom();
                if (mFirstPosition==0&&top>=mListPadding.top&&
                    mFirstPosition+childCount<mItemCount&&
                    bottom<=getHeight()-getPaddingBottom()mListPadding.bottom) {
                    mTouchMode=TOUCH_MODE_REST;
                    reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                } else*/ {
                    final VelocityTracker velocityTracker = mVelocityTracker;
                    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                    final int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId);

                    if (Math.abs(initialVelocity) > mMinimumVelocity) {
                        if (mFlingRunnable == null) {
                            mFlingRunnable = new FlingRunnable();
                        }
                        reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);

                        mFlingRunnable.start(-initialVelocity);
                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
                    }
                }
            } else {
                mTouchMode = TOUCH_MODE_REST;
                reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            }
            break;
        }

        setPressed(false);

        // Need to redraw since we probably aren't drawing the selector anymore
        invalidate();

        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }

        mActivePointerId = INVALID_POINTER;

        /*if (PROFILE_SCROLLING) {
            if (mScrollProfilingStarted) {
                Debug.stopMethodTracing();
                mScrollProfilingStarted=false;
            }
        }*/
        break;
    }

    case MotionEvent.ACTION_CANCEL: {
        mTouchMode = TOUCH_MODE_REST;
        setPressed(false);
        View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
        if (motionView != null) {
            motionView.setPressed(false);
        }
        clearScrollingCache();

        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }

        mActivePointerId = INVALID_POINTER;
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        final int x = (int) mLastTouchX;
        final int y = (int) mLastTouchY;
        final int motionPosition = pointToPosition(x, y);
        if (motionPosition >= 0) {
            // Remember where the motion event started
            v = getChildAt(motionPosition - mFirstPosition);
            //mMotionViewOriginalTop=v.getTop();
            mMotionPosition = motionPosition;
        }
        mTouchRemainderY = y;
        break;
    }
    }

    return true;
}

From source file:com.comcast.freeflow.core.FreeFlowContainer.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    super.onTouchEvent(event);
    if (layout == null)
        return false;

    boolean canScroll = false;

    if (layout.horizontalScrollEnabled() && this.layout.getContentWidth() > getWidth()) {
        canScroll = true;//w  w w .j  a va 2s  .co m
    }
    if (layout.verticalScrollEnabled() && layout.getContentHeight() > getHeight()) {
        canScroll = true;
    }

    if (mVelocityTracker == null && canScroll) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    if (mVelocityTracker != null) {
        mVelocityTracker.addMovement(event);
    }

    if (event.getAction() == MotionEvent.ACTION_DOWN) {

        if (mTouchMode == TOUCH_MODE_FLING) {
            // Wait for some time to see if the user is just trying
            // to speed up the scroll
            postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (mTouchMode == TOUCH_MODE_DOWN) {
                        if (mTouchMode == TOUCH_MODE_DOWN) {
                            scroller.forceFinished(true);
                        }
                    }
                }
            }, FLYWHEEL_TIMEOUT);
        }

        beginTouchAt = ViewUtils.getItemAt(frames, (int) (viewPortX + event.getX()),
                (int) (viewPortY + event.getY()));

        if (canScroll) {
            deltaX = event.getX();
            deltaY = event.getY();
        }
        mTouchMode = TOUCH_MODE_DOWN;

        if (mPendingCheckForTap != null) {
            removeCallbacks(mPendingCheckForTap);
            mPendingCheckForLongPress = null;
        }

        if (beginTouchAt != null) {
            mPendingCheckForTap = new CheckForTap();
        }
        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());

        return true;

    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {

        if (canScroll) {
            float xDiff = event.getX() - deltaX;
            float yDiff = event.getY() - deltaY;

            double distance = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
            if ((mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_REST) && distance > touchSlop) {
                mTouchMode = TOUCH_MODE_SCROLL;

                if (mPendingCheckForTap != null) {
                    removeCallbacks(mPendingCheckForTap);
                    mPendingCheckForTap = null;
                }

            }

            if (mTouchMode == TOUCH_MODE_SCROLL) {
                moveViewportBy(event.getX() - deltaX, event.getY() - deltaY, false);
                invokeOnItemScrollListeners();
                deltaX = event.getX();
                deltaY = event.getY();
            }
        }

        return true;

    } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
        mTouchMode = TOUCH_MODE_REST;

        if (canScroll) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }

        // requestLayout();

        return true;

    } else if (event.getAction() == MotionEvent.ACTION_UP) {

        if (mTouchMode == TOUCH_MODE_SCROLL) {
            mVelocityTracker.computeCurrentVelocity(1000, maxFlingVelocity);
            if (Math.abs(mVelocityTracker.getXVelocity()) > minFlingVelocity
                    || Math.abs(mVelocityTracker.getYVelocity()) > minFlingVelocity) {

                int maxX = layout.getContentWidth() - getWidth();
                int maxY = layout.getContentHeight() - getHeight();

                scroller.fling(viewPortX, viewPortY, -(int) mVelocityTracker.getXVelocity(),
                        -(int) mVelocityTracker.getYVelocity(), 0, maxX, 0, maxY, overflingDistance,
                        overflingDistance);

                mTouchMode = TOUCH_MODE_FLING;
                post(flingRunnable);

            } else {
                mTouchMode = TOUCH_MODE_REST;
            }

        } else if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_DONE_WAITING) {
            if (mTouchModeReset != null) {
                removeCallbacks(mTouchModeReset);
            }
            if (beginTouchAt != null && beginTouchAt.view != null) {
                beginTouchAt.view.setPressed(true);

                mTouchModeReset = new Runnable() {
                    @Override
                    public void run() {
                        mTouchModeReset = null;
                        mTouchMode = TOUCH_MODE_REST;
                        if (beginTouchAt != null && beginTouchAt.view != null) {
                            beginTouchAt.view.setPressed(false);
                        }
                        if (mChoiceActionMode == null && mOnItemSelectedListener != null) {
                            mOnItemSelectedListener.onItemSelected(FreeFlowContainer.this,
                                    selectedFreeFlowItem);
                        }

                        // setPressed(false);
                        // if (!mDataChanged) {
                        mPerformClick = new PerformClick();
                        mPerformClick.run();
                        // }
                    }
                };
                selectedFreeFlowItem = beginTouchAt;
                postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());

                mTouchMode = TOUCH_MODE_TAP;
            } else {
                mTouchMode = TOUCH_MODE_REST;
            }

        }

        return true;
    }

    return false;

}

From source file:com.hippo.widget.recyclerview.EasyRecyclerView.java

private void onTouchUp(MotionEvent ev) {
    if (isLayoutFrozen() || mTouchFromScrolling) {
        return;//from   www.  ja v a2s  . c  om
    }

    View motionView = mMotionView;
    int motionPosition = mMotionPosition;

    if (motionView != null && motionPosition >= 0) {
        final float x = ev.getX();
        final float y = ev.getY();

        if (motionView.isPressed() || mPrePressed) {
            // The button is being released before we actually
            // showed it as pressed.  Make it show the pressed
            // state now (before scheduling the click) to ensure
            // the user sees it.
            final float[] point = mTmpPoint;
            point[0] = x;
            point[1] = y;
            ViewUtils.transformPointToViewLocal(point, EasyRecyclerView.this, motionView);
            setPressed(motionView, true, point[0], point[1]);
            setPressed(true);
            positionSelector(mMotionPosition, motionView);
            if (mSelector != null) {
                Drawable d = mSelector.getCurrent();
                if (d instanceof TransitionDrawable) {
                    ((TransitionDrawable) d).resetTransition();
                }
                DrawableUtils.setHotspot(mSelector, x, y);
            }

            if (!mHasPerformedLongPress) {
                // This is a tap, so remove the longpress check
                removeLongPressCallback();

                // Use a Runnable and post this rather than calling
                // performClick directly. This lets other visual state
                // of the view update before click actions start.
                if (mPerformClick == null) {
                    mPerformClick = new PerformClick();
                }
                mPerformClick.v = motionView;
                mPerformClick.p = motionPosition;
                mPerformClick.rememberWindowAttachCount();
                if (!post(mPerformClick)) {
                    mPerformClick.run();
                }
            }

            if (mUnsetPressedState == null) {
                mUnsetPressedState = new UnsetPressedState();
            }

            mUnsetPressedState.v = motionView;
            if (mPrePressed) {
                postDelayed(mUnsetPressedState, ViewConfiguration.getPressedStateDuration());
            } else if (!post(mUnsetPressedState)) {
                // If the post failed, unpress right now
                mUnsetPressedState.run();
            }

            removeTapCallback();
        }

        updateSelectorState();

        // Release
        mMotionView = null;
    }
}

From source file:com.dishes.views.stageredggridview.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (mFastScroller != null) {
        boolean intercepted = mFastScroller.onTouchEvent(ev);
        if (intercepted) {
            return true;
        }/*  w  w w  .  j a v a2 s.  c  o m*/
    }
    mVelocityTracker.addMovement(ev);
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY());

    switch (action) {
    case MotionEvent.ACTION_DOWN:

        mVelocityTracker.clear();
        mScroller.abortAnimation();
        mLastTouchY = ev.getY();
        mLastTouchX = ev.getX();
        motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderY = 0;

        if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0
                && getAdapter().isEnabled(motionPosition)) {
            mTouchMode = TOUCH_MODE_DOWN;

            mBeginClick = true;

            if (mPendingCheckForTap == null) {
                mPendingCheckForTap = new CheckForTap();
            }

            postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
        }

        mMotionPosition = motionPosition;
        invalidate();
        break;

    case MotionEvent.ACTION_MOVE: {

        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, index);
        final float dy = y - mLastTouchY + mTouchRemainderY;
        final int deltaY = (int) dy;
        mTouchRemainderY = dy - deltaY;

        if (Math.abs(dy) > mTouchSlop) {
            mTouchMode = TOUCH_MODE_DRAGGING;
        }

        if (mTouchMode == TOUCH_MODE_DRAGGING) {
            mLastTouchY = y;

            if (!trackMotionScroll(deltaY, true)) {
                // Break fling velocity if we impacted an edge.
                mVelocityTracker.clear();
            }
        }

        updateSelectorState();
    }
        break;

    case MotionEvent.ACTION_CANCEL:
        mTouchMode = TOUCH_MODE_IDLE;
        updateSelectorState();
        setPressed(false);
        View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
        if (motionView != null) {
            motionView.setPressed(false);
        }
        final Handler handler = getHandler();
        if (handler != null) {
            handler.removeCallbacks(mPendingCheckForLongPress);
        }

        if (mTopEdge != null) {
            mTopEdge.onRelease();
            mBottomEdge.onRelease();
        }

        mTouchMode = TOUCH_MODE_IDLE;
        break;

    case MotionEvent.ACTION_UP: {
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
        final int prevTouchMode = mTouchMode;

        if (Math.abs(velocity) > mFlingVelocity) { // TODO
            mTouchMode = TOUCH_MODE_FLINGING;
            mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
            mLastTouchY = 0;
            invalidate();
        } else {
            mTouchMode = TOUCH_MODE_IDLE;
        }

        if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
            // TODO : handle
            mTouchMode = TOUCH_MODE_TAP;
        } else {
            mTouchMode = TOUCH_MODE_REST;
        }

        switch (prevTouchMode) {
        case TOUCH_MODE_DOWN:
        case TOUCH_MODE_TAP:
        case TOUCH_MODE_DONE_WAITING:
            final View child = getChildAt(motionPosition - mFirstPosition);
            final float x = ev.getX();
            final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight();
            if (child != null && !child.hasFocusable() && inList) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }

                if (mPerformClick == null) {
                    invalidate();
                    mPerformClick = new PerformClick();
                }

                final PerformClick performClick = mPerformClick;
                performClick.mClickMotionPosition = motionPosition;
                performClick.rememberWindowAttachCount();

                if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                    final Handler handlerTouch = getHandler();
                    if (handlerTouch != null) {
                        handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap
                                : mPendingCheckForLongPress);
                    }
                    mLayoutMode = LAYOUT_NORMAL;

                    if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        mTouchMode = TOUCH_MODE_TAP;

                        layoutChildren(mDataChanged);
                        child.setPressed(true);
                        positionSelector(mMotionPosition, child);
                        setPressed(true);
                        if (mSelector != null) {
                            Drawable d = mSelector.getCurrent();
                            if (d != null && d instanceof TransitionDrawable) {
                                ((TransitionDrawable) d).resetTransition();
                            }
                        }
                        if (mTouchModeReset != null) {
                            removeCallbacks(mTouchModeReset);
                        }
                        mTouchModeReset = new Runnable() {
                            @Override
                            public void run() {
                                mTouchMode = TOUCH_MODE_REST;
                                child.setPressed(false);
                                setPressed(false);
                                if (!mDataChanged) {
                                    performClick.run();
                                }
                            }
                        };
                        postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());

                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                    }
                    return true;
                } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                    performClick.run();
                }
            }

            mTouchMode = TOUCH_MODE_REST;
        }

        mBeginClick = false;

        updateSelectorState();
    }
        break;
    }
    return true;
}

From source file:com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer.java

protected void touchUp(MotionEvent event) {
    if ((mTouchMode == TOUCH_MODE_SCROLL || mTouchMode == TOUCH_MODE_OVERFLING) && mVelocityTracker != null) {

        mVelocityTracker.computeCurrentVelocity(1000, maxFlingVelocity);

        if (Math.abs(mVelocityTracker.getXVelocity()) > minFlingVelocity
                || Math.abs(mVelocityTracker.getYVelocity()) > minFlingVelocity) {

            int maxX = mLayout.getContentWidth() - getWidth();
            int maxY = mLayout.getContentHeight() - getHeight();

            int allowedScrollOffset;
            if (mTouchMode == TOUCH_MODE_SCROLL) {
                allowedScrollOffset = 0;
            } else {
                allowedScrollOffset = overflingDistance;
            }//  w w w .j a v  a 2  s  .c o m

            scroller.fling(viewPortX, viewPortY, -(int) mVelocityTracker.getXVelocity(),
                    -(int) mVelocityTracker.getYVelocity(), 0, maxX, 0, maxY, allowedScrollOffset,
                    allowedScrollOffset);

            mTouchMode = TOUCH_MODE_FLING;

            if (mOnTouchModeChangedListener != null) {
                mOnTouchModeChangedListener.onTouchModeChanged(mTouchMode);
            }

            post(flingRunnable);

        } else {
            mTouchMode = TOUCH_MODE_REST;

            if (mOnTouchModeChangedListener != null) {
                mOnTouchModeChangedListener.onTouchModeChanged(mTouchMode);
            }
        }

    } else if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_DONE_WAITING) {
        if (mTouchModeReset != null) {
            removeCallbacks(mTouchModeReset);
        }

        FreeFlowItem endTouchAt = ViewUtils.getItemAt(frames, (int) (viewPortX + event.getX()),
                (int) (viewPortY + event.getY()));

        if (beginTouchAt != null && beginTouchAt.view != null && beginTouchAt == endTouchAt) {

            beginTouchAt.view.setPressed(true);

            mTouchModeReset = new Runnable() {
                @Override
                public void run() {
                    mTouchModeReset = null;
                    mTouchMode = TOUCH_MODE_REST;

                    if (mOnTouchModeChangedListener != null) {
                        mOnTouchModeChangedListener.onTouchModeChanged(mTouchMode);
                    }

                    if (beginTouchAt != null && beginTouchAt.view != null) {
                        beginTouchAt.view.setPressed(false);
                    }
                    if (mChoiceActionMode == null && mOnItemSelectedListener != null) {
                        mOnItemSelectedListener.onItemSelected(FreeFlowContainer.this, selectedFreeFlowItem);
                    }
                }
            };
            selectedFreeFlowItem = beginTouchAt;
            postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());

            mTouchMode = TOUCH_MODE_TAP;
            mPerformClick = new PerformClick();
            mPerformClick.run();

            if (mOnTouchModeChangedListener != null) {
                mOnTouchModeChangedListener.onTouchModeChanged(mTouchMode);
            }
        } else {
            mTouchMode = TOUCH_MODE_REST;

            if (mOnTouchModeChangedListener != null) {
                mOnTouchModeChangedListener.onTouchModeChanged(mTouchMode);
            }
        }

    }
}

From source file:caesar.feng.framework.widget.StaggeredGrid.ExtendableListView.java

private boolean onTouchUpTap(final MotionEvent event) {
    final int motionPosition = mMotionPosition;
    if (motionPosition >= 0) {
        final View child = getChildAt(motionPosition);
        if (child != null && !child.hasFocusable()) {
            if (mTouchMode != TOUCH_MODE_DOWN) {
                child.setPressed(false);
            }// w w w  . jav  a 2  s.  co  m

            if (mPerformClick == null) {
                invalidate();
                mPerformClick = new PerformClick();
            }

            final PerformClick performClick = mPerformClick;
            performClick.mClickMotionPosition = motionPosition;
            performClick.rememberWindowAttachCount();

            //            mResurrectToPosition = motionPosition;

            if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                final Handler handler = getHandler();
                if (handler != null) {
                    handler.removeCallbacks(
                            mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress);
                }
                mLayoutMode = LAYOUT_NORMAL;
                if (!mDataChanged && motionPosition >= 0 && mAdapter.isEnabled(motionPosition)) {
                    mTouchMode = TOUCH_MODE_TAP;
                    layoutChildren();
                    child.setPressed(true);
                    setPressed(true);
                    postDelayed(new Runnable() {
                        public void run() {
                            child.setPressed(false);
                            setPressed(false);
                            if (!mDataChanged) {
                                post(performClick);
                            }
                            mTouchMode = TOUCH_MODE_IDLE;
                        }
                    }, ViewConfiguration.getPressedStateDuration());
                } else {
                    mTouchMode = TOUCH_MODE_IDLE;
                }
                return true;
            } else if (!mDataChanged && motionPosition >= 0 && mAdapter.isEnabled(motionPosition)) {
                post(performClick);
            }
        }
    }
    mTouchMode = TOUCH_MODE_IDLE;

    return true;
}

From source file:com.sintn.hera.client.widget.view.stagegered.ExtendableListView.java

private boolean onTouchUpTap(final MotionEvent event) {
    final int motionPosition = mMotionPosition;
    if (motionPosition >= 0) {
        final View child = getChildAt(motionPosition);
        if (child != null && !child.hasFocusable()) {
            if (mTouchMode != TOUCH_MODE_DOWN) {
                child.setPressed(false);
            }//from w  w w  . j a  va2 s.c om

            if (mPerformClick == null) {
                invalidate();
                mPerformClick = new PerformClick();
            }

            final PerformClick performClick = mPerformClick;
            performClick.mClickMotionPosition = motionPosition;
            performClick.rememberWindowAttachCount();

            // mResurrectToPosition = motionPosition;

            if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                final Handler handler = getHandler();
                if (handler != null) {
                    handler.removeCallbacks(
                            mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress);
                }
                mLayoutMode = LAYOUT_NORMAL;
                if (!mDataChanged && motionPosition >= 0 && mAdapter.isEnabled(motionPosition)) {
                    mTouchMode = TOUCH_MODE_TAP;
                    layoutChildren();
                    child.setPressed(true);
                    setPressed(true);
                    postDelayed(new Runnable() {
                        public void run() {
                            child.setPressed(false);
                            setPressed(false);
                            if (!mDataChanged) {
                                post(performClick);
                            }
                            mTouchMode = TOUCH_MODE_IDLE;
                        }
                    }, ViewConfiguration.getPressedStateDuration());
                } else {
                    mTouchMode = TOUCH_MODE_IDLE;
                }
                return true;
            } else if (!mDataChanged && motionPosition >= 0 && mAdapter.isEnabled(motionPosition)) {
                post(performClick);
            }
        }
    }
    mTouchMode = TOUCH_MODE_IDLE;

    return true;
}