Search in sources :

Example 71 with MotionEvent

use of android.view.MotionEvent in project Android-ObservableScrollView by ksoichiro.

the class ObservableWebView method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (hasNoCallbacks()) {
        return super.onTouchEvent(ev);
    }
    switch(ev.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            mIntercepted = false;
            mDragging = false;
            dispatchOnUpOrCancelMotionEvent(mScrollState);
            break;
        case MotionEvent.ACTION_MOVE:
            if (mPrevMoveEvent == null) {
                mPrevMoveEvent = ev;
            }
            float diffY = ev.getY() - mPrevMoveEvent.getY();
            mPrevMoveEvent = MotionEvent.obtainNoHistory(ev);
            if (getCurrentScrollY() - diffY <= 0) {
                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;
                }
                // so delegate it to super.
                return super.onTouchEvent(ev);
            }
            break;
    }
    return super.onTouchEvent(ev);
}
Also used : ViewGroup(android.view.ViewGroup) View(android.view.View) WebView(android.webkit.WebView) MotionEvent(android.view.MotionEvent)

Example 72 with MotionEvent

use of android.view.MotionEvent in project Android-ObservableScrollView by ksoichiro.

the class TouchInterceptionFrameLayout method duplicateTouchEventForChildren.

/**
     * Duplicate touch events to child views.
     * We want to dispatch a down motion event and the move events to
     * child views, but calling dispatchTouchEvent() causes StackOverflowError.
     * Therefore we do it manually.
     *
     * @param ev            Motion event to be passed to children.
     * @param pendingEvents Pending events like ACTION_DOWN. This will be passed to the children before ev.
     */
private void duplicateTouchEventForChildren(MotionEvent ev, MotionEvent... pendingEvents) {
    if (ev == null) {
        return;
    }
    for (int i = getChildCount() - 1; 0 <= i; i--) {
        View childView = getChildAt(i);
        if (childView != null) {
            Rect childRect = new Rect();
            childView.getHitRect(childRect);
            MotionEvent event = MotionEvent.obtainNoHistory(ev);
            if (!childRect.contains((int) event.getX(), (int) event.getY())) {
                continue;
            }
            float offsetX = -childView.getLeft();
            float offsetY = -childView.getTop();
            boolean consumed = false;
            if (pendingEvents != null) {
                for (MotionEvent pe : pendingEvents) {
                    if (pe != null) {
                        MotionEvent peAdjusted = MotionEvent.obtainNoHistory(pe);
                        peAdjusted.offsetLocation(offsetX, offsetY);
                        consumed |= childView.dispatchTouchEvent(peAdjusted);
                    }
                }
            }
            event.offsetLocation(offsetX, offsetY);
            consumed |= childView.dispatchTouchEvent(event);
            if (consumed) {
                break;
            }
        }
    }
}
Also used : Rect(android.graphics.Rect) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 73 with MotionEvent

use of android.view.MotionEvent in project KJFrameForAndroid by kymjs.

the class Browser method initWidget.

@Override
public void initWidget() {
    super.initWidget();
    initWebView();
    initBarAnim();
    mGestureDetector = new GestureDetector(aty, new MyGestureListener());
    mWebView.loadUrl(mCurrentUrl);
    mWebView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return mGestureDetector.onTouchEvent(event);
        }
    });
}
Also used : OnTouchListener(android.view.View.OnTouchListener) GestureDetector(android.view.GestureDetector) ImageView(android.widget.ImageView) View(android.view.View) BindView(org.kymjs.kjframe.ui.BindView) WebView(android.webkit.WebView) MotionEvent(android.view.MotionEvent)

Example 74 with MotionEvent

use of android.view.MotionEvent in project Lazy by l123456789jy.

the class NoPreloadViewPager method beginFakeDrag.

/**
     * Start a fake drag of the pager.
     *
     * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
     * with the touch scrolling of another view, while still letting the ViewPager
     * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
     * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
     * {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
     *
     * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
     * is already in progress, this method will return false.
     *
     * @return true if the fake drag began successfully, false if it could not be started.
     *
     * @see #fakeDragBy(float)
     * @see #endFakeDrag()
     */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    }
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    mInitialMotionX = mLastMotionX = 0;
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    }
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}
Also used : MotionEvent(android.view.MotionEvent)

Example 75 with MotionEvent

use of android.view.MotionEvent in project rainbow by juankysoriano.

the class RainbowInputController method obtainEventWithNewPosition.

private MotionEvent obtainEventWithNewPosition(@NonNull MotionEvent event, float newEventX, float newEventY) {
    MotionEvent motionEvent = MotionEvent.obtain(event);
    motionEvent.setLocation(newEventX, newEventY);
    return motionEvent;
}
Also used : MotionEvent(android.view.MotionEvent)

Aggregations

MotionEvent (android.view.MotionEvent)702 View (android.view.View)242 TextView (android.widget.TextView)109 ImageView (android.widget.ImageView)86 Point (android.graphics.Point)62 GestureDetector (android.view.GestureDetector)46 OnTouchListener (android.view.View.OnTouchListener)44 Paint (android.graphics.Paint)40 ViewGroup (android.view.ViewGroup)36 Test (org.junit.Test)35 RecyclerView (android.support.v7.widget.RecyclerView)31 AdapterView (android.widget.AdapterView)31 ListView (android.widget.ListView)30 SuppressLint (android.annotation.SuppressLint)29 Intent (android.content.Intent)29 Instrumentation (android.app.Instrumentation)27 AbsListView (android.widget.AbsListView)27 Rect (android.graphics.Rect)22 OnClickListener (android.view.View.OnClickListener)22 Handler (android.os.Handler)20