Example usage for android.view MotionEvent obtain

List of usage examples for android.view MotionEvent obtain

Introduction

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

Prototype

static public MotionEvent obtain(MotionEvent other) 

Source Link

Document

Create a new MotionEvent, copying from an existing one.

Usage

From source file:Main.java

private static MotionEvent transformEventNew(MotionEvent e, Matrix m) {
    MotionEvent newEvent = MotionEvent.obtain(e);
    newEvent.transform(m);
    return newEvent;
}

From source file:Main.java

public static MotionEvent transformEvent(final MotionEvent e, final Matrix m) {
    final MotionEvent newEvent = MotionEvent.obtain(e);
    newEvent.transform(m);//from  ww  w  .  j ava2s  .co  m
    return newEvent;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static MotionEvent transformEventNew(final MotionEvent e, final Matrix m) {
    final MotionEvent newEvent = MotionEvent.obtain(e);
    newEvent.transform(m);// w  w w  . j a v  a 2 s  .co m
    return newEvent;
}

From source file:com.ftinc.kit.widget.TightSwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mPrevX = MotionEvent.obtain(event).getX();
        break;/*from  www.j  av a 2  s.c om*/

    case MotionEvent.ACTION_MOVE:
        final float eventX = event.getX();
        float xDiff = Math.abs(eventX - mPrevX);

        if (xDiff > mTouchSlop) {
            return false;
        }
    }

    return super.onInterceptTouchEvent(event);
}

From source file:org.mozilla.focus.web.NestedGeckoView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    boolean eventHandled = false;

    final MotionEvent event = MotionEvent.obtain(ev);
    final int action = MotionEventCompat.getActionMasked(event);
    if (action == MotionEvent.ACTION_DOWN) {
        mNestedOffsetY = 0;/*  w  w  w . j  a  v a2  s.c om*/
    }
    final int eventY = (int) event.getY();
    event.offsetLocation(0, mNestedOffsetY);

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastY - eventY;

        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            mLastY = eventY - mScrollOffset[1];
            event.offsetLocation(0, -mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
        }

        eventHandled = super.onTouchEvent(event);

        if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
            event.offsetLocation(0, mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
            mLastY -= mScrollOffset[1];
        }
        break;

    case MotionEvent.ACTION_DOWN:
        eventHandled = super.onTouchEvent(event);
        mLastY = eventY;

        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        eventHandled = super.onTouchEvent(event);
        stopNestedScroll();
        break;

    default:
        // We don't care about other touch events
    }

    return eventHandled;
}

From source file:de.stadtrallye.rallyesoft.widget.GalleryPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (touchEnabled) {
        return super.onInterceptTouchEvent(ev);
    } else {/*  w  ww.  j  ava2s.  c o  m*/
        if (!cancelled) {
            MotionEvent e = MotionEvent.obtain(ev);
            e.setAction(MotionEvent.ACTION_CANCEL);
            super.onInterceptTouchEvent(e);
            cancelled = true;
            e.recycle();
        }
        return false;
    }
}

From source file:de.gebatzens.sia.view.CustomSwipeLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        MotionEvent m = MotionEvent.obtain(event);
        prevX = m.getX();/*from  w w  w  .  j  a  v a  2  s .c  o  m*/
        m.recycle();
        return super.onInterceptTouchEvent(event);
    case MotionEvent.ACTION_MOVE:
        if (SIAApp.SIA_APP.school.fragments.get(SIAApp.SIA_APP.getFragmentIndex())
                .getType() == FragmentData.FragmentType.PLAN) {
            float xd = Math.abs(event.getX() - prevX);
            if (xd > touchSlop)
                return false;
        }

    }

    return super.onInterceptTouchEvent(event);
}

From source file:de.gebatzens.ggvertretungsplan.view.SubstSwipeLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        MotionEvent m = MotionEvent.obtain(event);
        mPrevX = m.getX();/* w w w.java  2 s  . com*/
        m.recycle();

        break;

    case MotionEvent.ACTION_MOVE:
        float xd = Math.abs(event.getX() - mPrevX);
        if (xd > mTouchSlop)
            return false;

        if (GGApp.GG_APP.getFragmentType() == GGApp.FragmentType.PLAN) {
            int i = ((SubstFragment) ((MainActivity) getContext()).mContent).mViewPager.getCurrentItem();
            SubstPagerFragment frag = (SubstPagerFragment) ((FragmentPagerAdapter) ((SubstFragment) ((MainActivity) getContext()).mContent).mViewPager
                    .getAdapter()).getItem(i);
            ScrollView sv = (ScrollView) frag.getView().findViewWithTag("ggfrag_scrollview");

            if (sv != null && sv.getScrollY() != 0)
                return false;
        }
    }

    return super.onInterceptTouchEvent(event);
}

From source file:com.github.takahirom.webview_in_coodinator_layout.NestedWebView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    boolean returnValue = false;

    MotionEvent event = MotionEvent.obtain(ev);
    final int action = MotionEventCompat.getActionMasked(event);
    if (action == MotionEvent.ACTION_DOWN) {
        mNestedOffsetY = 0;/*from   w w  w  .j  ava 2s.  c om*/
    }
    int eventY = (int) event.getY();
    event.offsetLocation(0, mNestedOffsetY);
    switch (action) {
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastY - eventY;
        // NestedPreScroll
        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            mLastY = eventY - mScrollOffset[1];
            event.offsetLocation(0, -mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
        }
        returnValue = super.onTouchEvent(event);

        // NestedScroll
        if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
            event.offsetLocation(0, mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
            mLastY -= mScrollOffset[1];
        }
        break;
    case MotionEvent.ACTION_DOWN:
        returnValue = super.onTouchEvent(event);
        if (firstScroll) {
            // dispatching first down scrolling properly by making sure that first deltaY will be -ve
            mLastY = eventY - 5;
            firstScroll = false;
        } else {
            mLastY = eventY;
        }
        // start NestedScroll
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        returnValue = super.onTouchEvent(event);
        // end NestedScroll
        stopNestedScroll();
        break;
    }
    return returnValue;
}

From source file:com.github.takahirom.zerobrowser.view.webview.ZeroBrowserWebView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    boolean returnValue = true;

    MotionEvent event = MotionEvent.obtain(ev);
    final int action = MotionEventCompat.getActionMasked(event);
    if (action == MotionEvent.ACTION_DOWN) {
        mNestedOffsetY = 0;/*from   w ww. java 2  s  .  c  o m*/
    }
    int eventY = (int) event.getY();
    event.offsetLocation(0, mNestedOffsetY);
    switch (action) {
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastY - eventY;
        // NestedPreScroll
        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            mLastY = eventY - mScrollOffset[1];
            event.offsetLocation(0, -mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
        }
        returnValue = super.onTouchEvent(event);

        // NestedScroll
        if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
            event.offsetLocation(0, mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
            mLastY -= mScrollOffset[1];
        }
        break;
    case MotionEvent.ACTION_DOWN:
        returnValue = super.onTouchEvent(event);
        mLastY = eventY;
        // start NestedScroll
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        returnValue = super.onTouchEvent(event);
        // end NestedScroll
        stopNestedScroll();
        break;
    }

    return returnValue;
}