Example usage for android.view MotionEvent obtainNoHistory

List of usage examples for android.view MotionEvent obtainNoHistory

Introduction

In this page you can find the example usage for android.view MotionEvent obtainNoHistory.

Prototype

static public MotionEvent obtainNoHistory(MotionEvent other) 

Source Link

Document

Create a new MotionEvent, copying from an existing one, but not including any historical point information.

Usage

From source file:android.support.v7.widget.ForwardingListener.java

/**
 * Handles forwarded motion events and determines when to stop
 * forwarding./*from  w  ww .j  a  v  a2s .c om*/
 *
 * @param srcEvent motion event in source view coordinates
 * @return true to continue forwarding motion events, false to cancel
 */
private boolean onTouchForwarded(MotionEvent srcEvent) {
    final View src = mSrc;
    final ShowableListMenu popup = getPopup();
    if (popup == null || !popup.isShowing()) {
        return false;
    }

    final DropDownListView dst = (DropDownListView) popup.getListView();
    if (dst == null || !dst.isShown()) {
        return false;
    }

    // Convert event to destination-local coordinates.
    final MotionEvent dstEvent = MotionEvent.obtainNoHistory(srcEvent);
    toGlobalMotionEvent(src, dstEvent);
    toLocalMotionEvent(dst, dstEvent);

    // Forward converted event to destination view, then recycle it.
    final boolean handled = dst.onForwardedEvent(dstEvent, mActivePointerId);
    dstEvent.recycle();

    // Always cancel forwarding when the touch stream ends.
    final int action = MotionEventCompat.getActionMasked(srcEvent);
    final boolean keepForwarding = action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_CANCEL;

    return handled && keepForwarding;
}

From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java

private void populateStdMotion(@NonNull MotionEvent srcEvent) {
    // Track current movement to be able to handle
    // flings correctly.
    MotionEvent dstEvent = MotionEvent.obtainNoHistory(srcEvent);
    mVelocityTracker.addMovement(MotionEvent.obtainNoHistory(srcEvent));
    dstEvent.recycle();//w w w .jav a2  s.  c  om

    // No need to handle swipe-to-dismiss if the
    // widget is not dismissible.
    if (!isDismissible(mSelectedWidget)) {
        return;
    }

    final float y = srcEvent.getY() - mIconsContainer.getHeight();

    if (y <= 0) {
        if (mSceneContainer.getTranslationY() != 0) {
            resetSceneContainerParams();
        }
        return;
    }

    // Populate current animation
    float height = getSceneView().getHeight();
    float progress = MathUtils.range(y / height, 0f, 1f);
    populateStdAnimation(progress);
}

From source file:com.marshalchen.ultimaterecyclerview.UltimateRecyclerView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    URLogs.d("ev---" + ev);
    if (mCallbacks != null) {

        switch (ev.getActionMasked()) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            mIntercepted = false;/* w  w  w .jav  a2 s  . c o m*/
            mDragging = false;
            mCallbacks.onUpOrCancelMotionEvent(mObservableScrollState);
            break;
        case MotionEvent.ACTION_MOVE:
            if (mPrevMoveEvent == null) {
                mPrevMoveEvent = ev;
            }
            float diffY = ev.getY() - mPrevMoveEvent.getY();
            mPrevMoveEvent = MotionEvent.obtainNoHistory(ev);
            if (getCurrentScrollY() - diffY <= 0) {
                // Can't scroll anymore.

                if (mIntercepted) {
                    // Already dispatched ACTION_DOWN event to parents, so stop here.
                    return false;
                }

                // Apps can set the interception target other than the direct parent.
                final ViewGroup parent;
                if (mTouchInterceptionViewGroup == null) {
                    parent = (ViewGroup) getParent();
                } else {
                    parent = mTouchInterceptionViewGroup;
                }

                // Get offset to parents. If the parent is not the direct parent,
                // we should aggregate offsets from all of the parents.
                float offsetX = 0;
                float offsetY = 0;
                for (View v = this; v != null && v != parent; v = (View) v.getParent()) {
                    offsetX += v.getLeft() - v.getScrollX();
                    offsetY += v.getTop() - v.getScrollY();
                }
                final MotionEvent event = MotionEvent.obtainNoHistory(ev);
                event.offsetLocation(offsetX, offsetY);

                if (parent.onInterceptTouchEvent(event)) {
                    mIntercepted = true;

                    // If the parent wants to intercept ACTION_MOVE events,
                    // we pass ACTION_DOWN event to the parent
                    // as if these touch events just have began now.
                    event.setAction(MotionEvent.ACTION_DOWN);

                    // Return this onTouchEvent() first and set ACTION_DOWN event for parent
                    // to the queue, to keep events sequence.
                    post(new Runnable() {
                        @Override
                        public void run() {
                            parent.dispatchTouchEvent(event);
                        }
                    });
                    return false;
                }
                // Even when this can't be scrolled anymore,
                // simply returning false here may cause subView's click,
                // so delegate it to super.
                return super.onTouchEvent(ev);
            }
            break;
        }
    }
    return super.onTouchEvent(ev);
}