Example usage for android.view ViewConfiguration getTapTimeout

List of usage examples for android.view ViewConfiguration getTapTimeout

Introduction

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

Prototype

public static int getTapTimeout() 

Source Link

Usage

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;
        }/*from   ww w .ja  va2s . 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.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 ww .  ja va  2  s. com*/
    }
    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 onTouchDown(MotionEvent ev) {
    if (isLayoutFrozen() || mTouchFromScrolling) {
        return;//from w w w.j  a va  2s . com
    }

    final float x = ev.getX();
    final float y = ev.getY();
    mStartX = x;
    mStartY = y;

    mMotionView = findChildViewUnder(x, y);
    mMotionPosition = getChildAdapterPosition(mMotionView);

    if (mMotionView != null && mMotionPosition >= 0 && mMotionView.isEnabled()) {
        mHasPerformedLongPress = false;

        mPrePressed = true;
        if (mPendingCheckForTap == null) {
            mPendingCheckForTap = new CheckForTap();
        }
        mPendingCheckForTap.x = x;
        mPendingCheckForTap.y = y;
        mPendingCheckForTap.v = mMotionView;
        mPendingCheckForTap.p = mMotionPosition;
        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());

    } else {
        mMotionView = null;
    }
}

From source file:freeflow.core.FreeFlowContainer.java

protected void touchDown(MotionEvent event) {
    /*//from   w  ww.ja  va  2 s  .c o  m
     * Recompute this just to be safe. TODO: We should optimize this to be
    * only calculated when a data or layout change happens
    */
    mScrollableHeight = mLayout.getContentHeight() - getHeight();
    mScrollableWidth = mLayout.getContentWidth() - getWidth();

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

    deltaX = event.getX();
    deltaY = event.getY();

    mTouchMode = TOUCH_MODE_DOWN;

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

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

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

}

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

protected void touchDown(MotionEvent event) {
    if (isAnimatingChanges) {
        layoutAnimator.onContainerTouchDown(event);
    }//from  w ww  .  jav  a2 s  .  c om

    /*
     * Recompute this just to be safe. TODO: We should optimize this to be
     * only calculated when a data or layout change happens
     */
    mScrollableHeight = mLayout.getContentHeight() - getHeight();
    mScrollableWidth = mLayout.getContentWidth() - getWidth();

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

    deltaX = event.getX();
    deltaY = event.getY();

    mTouchMode = TOUCH_MODE_DOWN;

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

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

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

}

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

private boolean onTouchDown(final MotionEvent event) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    int motionPosition = pointToPosition(x, y);

    mVelocityTracker.clear();//w  w  w. j  a v  a  2 s .  c om
    mActivePointerId = MotionEventCompat.getPointerId(event, 0);

    // TODO : use the motion position for fling support
    // TODO : support long press!
    // startLongPressCheck();

    if ((mTouchMode != TOUCH_MODE_FLINGING) && !mDataChanged && motionPosition >= 0
            && getAdapter().isEnabled(motionPosition)) {
        // is it a tap or a scroll .. we don't know yet!
        mTouchMode = TOUCH_MODE_DOWN;

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

        if (event.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;
        }
    } else if (mTouchMode == TOUCH_MODE_FLINGING) {
        mTouchMode = TOUCH_MODE_SCROLLING;
        mMotionCorrection = 0;
        motionPosition = findMotionRow(y);
    }

    mMotionX = x;
    mMotionY = y;
    mMotionPosition = motionPosition;
    mLastY = Integer.MIN_VALUE;

    return true;
}

From source file:com.xuejian.client.lxp.common.widget.freeflow.core.FreeFlowContainer.java

protected void touchDown(MotionEvent event) {
    if (isAnimatingChanges) {
        layoutAnimator.onContainerTouchDown(event);
    }// ww  w. j  a v  a2  s. co  m

    /*
     * Recompute this just to be safe. TODO: We should optimize this to be
     * only calculated when a data or layout change happens
     */
    mScrollableHeight = mLayout.getContentHeight() - getHeight();
    mScrollableWidth = mLayout.getContentWidth() - getWidth();
    LogUtil.d("freeflow", "mScrollableHeight=" + mScrollableHeight);
    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()));

    deltaX = event.getX();
    deltaY = event.getY();

    mTouchMode = TOUCH_MODE_DOWN;

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

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

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

}

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

private boolean onTouchDown(final MotionEvent event) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    int motionPosition = pointToPosition(x, y);

    mVelocityTracker.clear();/*www .j  av a  2  s  . co  m*/
    mActivePointerId = MotionEventCompat.getPointerId(event, 0);

    // TODO : use the motion position for fling support
    // TODO : support long press!
    // startLongPressCheck();

    if ((mTouchMode != TOUCH_MODE_FLINGING) && !mDataChanged && motionPosition >= 0
            && getAdapter().isEnabled(motionPosition)) {
        // is it a tap or a scroll .. we don't know yet!
        mTouchMode = TOUCH_MODE_DOWN;

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

        if (event.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;
        }
    } else if (mTouchMode == TOUCH_MODE_FLINGING) {
        mTouchMode = TOUCH_MODE_SCROLLING;
        mMotionCorrection = 0;
        motionPosition = findMotionRow(y);
    }

    mMotionX = x;
    mMotionY = y;
    mMotionPosition = motionPosition;
    mLastY = Integer.MIN_VALUE;

    return true;
}

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

private void onTouchDown(MotionEvent ev) {
    mActivePointerId = ev.getPointerId(0);

    if (mTouchMode == TOUCH_MODE_OVERFLING) {
        // Stopped the fling. It is a scroll.
        mFlingRunnable.endFling();/*from   w  w w  .j av a  2 s  .  c o  m*/
        /*if (mPositionScroller != null) {
        mPositionScroller.stop();
        }*/
        mTouchMode = TOUCH_MODE_OVERSCROLL;
        mLastTouchX = (int) ev.getX();
        mLastTouchY = (int) ev.getY();
        mTouchRemainderY = mLastTouchY;
        mMotionCorrection = 0;
        //mDirection = 0;
    } else {
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        int motionPosition = pointToPosition(x, y);

        if (!mDataChanged) {
            if (mTouchMode == TOUCH_MODE_FLINGING) {
                // Stopped a fling. It is a scroll.
                //createScrollingCache();
                mTouchMode = TOUCH_MODE_DRAGGING;
                mMotionCorrection = 0;
                motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY);//findMotionRow(y);
                mFlingRunnable.flywheelTouch();
            } else if ((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());
            }
        }

        if (motionPosition >= 0) {
            // Remember where the motion event started
            final View v = getChildAt(motionPosition - mFirstPosition);
            //mMotionViewOriginalTop = v.getTop();
        }

        mLastTouchX = x;
        mLastTouchY = y;
        mMotionPosition = motionPosition;
        mTouchRemainderY = Integer.MIN_VALUE;
    }

    if (mTouchMode == TOUCH_MODE_DOWN && mMotionPosition != INVALID_POSITION
    /*&& performButtonActionOnTouchDown(ev)*/) {
        removeCallbacks(mPendingCheckForTap);
    }
}

From source file:org.telegram.ui.ArticleViewer.java

protected void startCheckLongPress() {
    if (checkingForLongPress) {
        return;// w w w . j a  v  a  2s.c  o m
    }
    checkingForLongPress = true;
    if (pendingCheckForTap == null) {
        pendingCheckForTap = new CheckForTap();
    }
    windowView.postDelayed(pendingCheckForTap, ViewConfiguration.getTapTimeout());
}