Search in sources :

Example 6 with MotionEvent

use of android.view.MotionEvent in project Signal-Android by WhisperSystems.

the class BaseGestureDetector method updateStateByEvent.

protected void updateStateByEvent(MotionEvent curr) {
    final MotionEvent prev = mPrevEvent;
    // Reset mCurrEvent
    if (mCurrEvent != null) {
        mCurrEvent.recycle();
        mCurrEvent = null;
    }
    mCurrEvent = MotionEvent.obtain(curr);
    // Delta time
    mTimeDelta = curr.getEventTime() - prev.getEventTime();
    // Pressure
    mCurrPressure = curr.getPressure(curr.getActionIndex());
    mPrevPressure = prev.getPressure(prev.getActionIndex());
}
Also used : MotionEvent(android.view.MotionEvent)

Example 7 with MotionEvent

use of android.view.MotionEvent in project Signal-Android by WhisperSystems.

the class MoveGestureDetector method updateStateByEvent.

protected void updateStateByEvent(MotionEvent curr) {
    super.updateStateByEvent(curr);
    final MotionEvent prev = mPrevEvent;
    // Focus intenal
    mCurrFocusInternal = determineFocalPoint(curr);
    mPrevFocusInternal = determineFocalPoint(prev);
    // Focus external
    // - Prevent skipping of focus delta when a finger is added or removed
    boolean mSkipNextMoveEvent = prev.getPointerCount() != curr.getPointerCount();
    mFocusDeltaExternal = mSkipNextMoveEvent ? FOCUS_DELTA_ZERO : new PointF(mCurrFocusInternal.x - mPrevFocusInternal.x, mCurrFocusInternal.y - mPrevFocusInternal.y);
    // - Don't directly use mFocusInternal (or skipping will occur). Add
    // 	 unskipped delta values to mFocusExternal instead.
    mFocusExternal.x += mFocusDeltaExternal.x;
    mFocusExternal.y += mFocusDeltaExternal.y;
}
Also used : PointF(android.graphics.PointF) MotionEvent(android.view.MotionEvent)

Example 8 with MotionEvent

use of android.view.MotionEvent in project Signal-Android by WhisperSystems.

the class ShoveGestureDetector method updateStateByEvent.

@Override
protected void updateStateByEvent(MotionEvent curr) {
    super.updateStateByEvent(curr);
    final MotionEvent prev = mPrevEvent;
    float py0 = prev.getY(0);
    float py1 = prev.getY(1);
    mPrevAverageY = (py0 + py1) / 2.0f;
    float cy0 = curr.getY(0);
    float cy1 = curr.getY(1);
    mCurrAverageY = (cy0 + cy1) / 2.0f;
}
Also used : MotionEvent(android.view.MotionEvent)

Example 9 with MotionEvent

use of android.view.MotionEvent in project Signal-Android by WhisperSystems.

the class TwoFingerGestureDetector method updateStateByEvent.

protected void updateStateByEvent(MotionEvent curr) {
    super.updateStateByEvent(curr);
    final MotionEvent prev = mPrevEvent;
    mCurrLen = -1;
    mPrevLen = -1;
    // Previous
    final float px0 = prev.getX(0);
    final float py0 = prev.getY(0);
    final float px1 = prev.getX(1);
    final float py1 = prev.getY(1);
    final float pvx = px1 - px0;
    final float pvy = py1 - py0;
    mPrevFingerDiffX = pvx;
    mPrevFingerDiffY = pvy;
    // Current
    final float cx0 = curr.getX(0);
    final float cy0 = curr.getY(0);
    final float cx1 = curr.getX(1);
    final float cy1 = curr.getY(1);
    final float cvx = cx1 - cx0;
    final float cvy = cy1 - cy0;
    mCurrFingerDiffX = cvx;
    mCurrFingerDiffY = cvy;
}
Also used : MotionEvent(android.view.MotionEvent)

Example 10 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)

Aggregations

MotionEvent (android.view.MotionEvent)1088 View (android.view.View)497 TextView (android.widget.TextView)264 ImageView (android.widget.ImageView)190 GestureDetector (android.view.GestureDetector)95 Point (android.graphics.Point)81 AdapterView (android.widget.AdapterView)80 ViewGroup (android.view.ViewGroup)75 Paint (android.graphics.Paint)72 ListView (android.widget.ListView)70 SuppressLint (android.annotation.SuppressLint)69 OnTouchListener (android.view.View.OnTouchListener)69 Intent (android.content.Intent)68 RecyclerView (android.support.v7.widget.RecyclerView)53 Test (org.junit.Test)47 ScrollView (android.widget.ScrollView)46 Handler (android.os.Handler)43 AbsListView (android.widget.AbsListView)42 WindowManager (android.view.WindowManager)41 LinearLayout (android.widget.LinearLayout)40