Example usage for android.view MotionEvent ACTION_POINTER_DOWN

List of usage examples for android.view MotionEvent ACTION_POINTER_DOWN

Introduction

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

Prototype

int ACTION_POINTER_DOWN

To view the source code for android.view MotionEvent ACTION_POINTER_DOWN.

Click Source Link

Document

Constant for #getActionMasked : A non-primary pointer has gone down.

Usage

From source file:Main.java

public static String eventToString(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        return "DOWN";
    case MotionEvent.ACTION_MOVE:
        return "MOVE";
    case MotionEvent.ACTION_UP:
        return "UP";
    case MotionEvent.ACTION_CANCEL:
        return "CANCEL";
    case MotionEvent.ACTION_OUTSIDE:
        return "OUTSIDE";
    case MotionEvent.ACTION_POINTER_DOWN:
        return "POINTER DOWN";
    case MotionEvent.ACTION_POINTER_UP:
        return "POINTER UP";
    }/*w w  w  .j  a  v  a  2 s  .co m*/
    return "UNKNOWN";
}

From source file:Main.java

/**
 * Gets the name of an action.//from   w  w w.  j av a2s. c  om
 * 
 * @param action        The action being performed.
 * @param isMotionEvent Whether or not the action is a motion event.
 * 
 * @return The name of the action being performed.
 */
public static String getActionName(int action, boolean isMotionEvent) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        return "DOWN";
    case MotionEvent.ACTION_UP:
        return "UP";
    case MotionEvent.ACTION_MOVE:
        return isMotionEvent ? "MOVE" : "MULTIPLE";
    case MotionEvent.ACTION_CANCEL:
        return "CANCEL";
    case MotionEvent.ACTION_OUTSIDE:
        return "OUTSIDE";
    case MotionEvent.ACTION_POINTER_DOWN:
        return "POINTER_DOWN";
    case MotionEvent.ACTION_POINTER_UP:
        return "POINTER_UP";
    case MotionEvent.ACTION_HOVER_MOVE:
        return "HOVER_MOVE";
    case MotionEvent.ACTION_SCROLL:
        return "SCROLL";
    case MotionEvent.ACTION_HOVER_ENTER:
        return "HOVER_ENTER";
    case MotionEvent.ACTION_HOVER_EXIT:
        return "HOVER_EXIT";
    default:
        return "ACTION_" + Integer.toString(action);
    }
}

From source file:cn.limc.androidcharts.event.SlipGestureDetector.java

public boolean onTouchEvent(MotionEvent event) {
    int pointers = event.getPointerCount();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    // ?//ww w  .  j  av  a2  s . com
    case MotionEvent.ACTION_DOWN:
        initalX = event.getX();
        if (pointers > 1) {
            touchMode = TOUCH_MODE_MULTI;
        } else {
            touchMode = TOUCH_MODE_SINGLE;
        }
        break;
    case MotionEvent.ACTION_UP:
        startPointA = null;
        startPointB = null;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        startPointA = null;
        startPointB = null;
    case MotionEvent.ACTION_POINTER_DOWN:
        olddistance = calcDistance(event);
        if (olddistance > MIN_DISTANCE) {
            touchMode = TOUCH_MODE_MULTI;
            startPointA = new PointF(event.getX(0), event.getY(0));
            startPointB = new PointF(event.getX(1), event.getY(1));
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (touchMode == TOUCH_MODE_SINGLE) {
            final float finalX = event.getX();
            // MotionEvent finalEvent = event;
            if (performLongClick) {
                return super.onTouchEvent(event);
            } else {
                if (finalX - initalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveRight((ISlipable) instance, event);
                    }
                } else if (initalX - finalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveLeft((ISlipable) instance, event);
                    }
                }
                initalX = finalX;
                // initalEvent = finalEvent;
                return true;
            }
        } else if (touchMode == TOUCH_MODE_MULTI) {
            newdistance = calcDistance(event);
            if (Math.abs(newdistance - olddistance) > MIN_DISTANCE) {
                if (onZoomGestureListener != null) {
                    if (newdistance > olddistance) {
                        onZoomGestureListener.onZoomIn((IZoomable) instance, event);
                    } else {
                        onZoomGestureListener.onZoomOut((IZoomable) instance, event);
                    }
                }
            }
            olddistance = newdistance;
            return true;
            // startPointA = new PointF(event.getX(), event.getY());
            // startPointB = new PointF(event.getX(1), event.getY(1));
        }
        break;
    }
    return super.onTouchEvent(event);
}

From source file:com.facebook.react.uimanager.events.TouchEvent.java

private void init(int viewTag, long timestampMs, TouchEventType touchEventType, MotionEvent motionEventToCopy,
        float viewX, float viewY) {
    super.init(viewTag, timestampMs);

    short coalescingKey = 0;
    int action = (motionEventToCopy.getAction() & MotionEvent.ACTION_MASK);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        TouchEventCoalescingKeyHelper.addCoalescingKey(motionEventToCopy.getDownTime());
        break;/*w  w w .  ja  va2 s  . com*/
    case MotionEvent.ACTION_UP:
        TouchEventCoalescingKeyHelper.removeCoalescingKey(motionEventToCopy.getDownTime());
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_POINTER_UP:
        TouchEventCoalescingKeyHelper.incrementCoalescingKey(motionEventToCopy.getDownTime());
        break;
    case MotionEvent.ACTION_MOVE:
        coalescingKey = TouchEventCoalescingKeyHelper.getCoalescingKey(motionEventToCopy.getDownTime());
        break;
    case MotionEvent.ACTION_CANCEL:
        TouchEventCoalescingKeyHelper.removeCoalescingKey(motionEventToCopy.getDownTime());
        break;
    default:
        throw new RuntimeException("Unhandled MotionEvent action: " + action);
    }
    mTouchEventType = touchEventType;
    mMotionEvent = MotionEvent.obtain(motionEventToCopy);
    mCoalescingKey = coalescingKey;
    mViewX = viewX;
    mViewY = viewY;
}

From source file:com.android.cts.uiautomator.TestGenericDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View rootView = inflater.inflate(R.layout.test_results_detail_fragment, container, false);
    if (mItem != null) {
        ((TextView) rootView.findViewById(R.id.testResultsTextView)).setText(mItem.mName);
    }//from   w  ww.  ja v a 2s.co m

    // listen to touch events to verify the multiPointerGesture APIs
    // Since API Level 18
    rootView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                // Reset any collected touch coordinate results on the primary touch down
                resetTouchResults();
                // collect this event
                collectStartAction(event, v, 0);
                break;

            case MotionEvent.ACTION_POINTER_DOWN:
                // collect this event
                collectStartAction(event, v, getPointerIndex(event));
                break;

            case MotionEvent.ACTION_POINTER_UP:
                // collect this event
                collectEndAction(event, v, getPointerIndex(event));
                break;

            case MotionEvent.ACTION_UP:
                // collect this event
                collectEndAction(event, v, 0);
                // on the primary touch up display results collected for all pointers
                displayTouchResults();
                break;
            }
            return true;
        }
    });

    return rootView;
}

From source file:com.fishstix.dosboxfree.ButtonLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);//((action & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT);
    final int pId = ev.getPointerId(pointerIndex) + 1;
    KeyEvent evt = null;//w ww .  jav a  2  s.  com
    Message msg = Message.obtain();
    msg.what = DBMain.HANDLER_SEND_KEYCODE;
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN: {
        Log.i("DosBoxTurbo", "button onDown()");
        int x = (int) ev.getX(pointerIndex);//(int) mWrap.getX(ev,pointerIndex);
        int width = getWidth();
        //int y = (int) mWrap.getY(ev,pointerIndex);
        float val = ((float) x / (float) width) * 4f;
        if (val < 1.0) {
            // first button
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_A) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_A);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_A);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_A;
            mDBLauncher.bButtonA.setBackgroundColor(0x80FF0000);
        } else if (val < 2.0) {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_B) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_B);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_B);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_B;
            mDBLauncher.bButtonB.setBackgroundColor(0x80FF0000);
        } else if (val < 3.0) {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_C) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_C);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_C);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_C;
            mDBLauncher.bButtonC.setBackgroundColor(0x80FF0000);
        } else {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_D) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_D);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_D);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_D;
            mDBLauncher.bButtonD.setBackgroundColor(0x80FF0000);
        }
        msg.obj = evt;
        msg.arg1 = 0;
        mDBLauncher.mSurfaceView.virtButton[pointerIndex] = true;
        mDBLauncher.mSurfaceView.mFilterLongClick = true; // prevent long click listener from getting in the way
        mDBLauncher.mHandler.sendMessage(msg);
        return true;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP: {
        Log.i("DosBoxTurbo", "button onUp()");
        msg.arg2 = virtualbutton_hm.get(pId);
        switch (msg.arg2) {
        case HardCodeWrapper.KEYCODE_VIRTUAL_A:
            mDBLauncher.bButtonA.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_B:
            mDBLauncher.bButtonB.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_C:
            mDBLauncher.bButtonC.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_D:
            mDBLauncher.bButtonD.setBackgroundColor(0x80FFFF00);
            break;
        }
        virtualbutton_hm.delete(pId);
        if (msg.arg2 == 0)
            return false;
        evt = new KeyEvent(action, msg.arg2);
        msg.obj = evt;
        msg.arg1 = 1;
        mDBLauncher.mSurfaceView.virtButton[pointerIndex] = false;
        mDBLauncher.mSurfaceView.mFilterLongClick = false;
        mDBLauncher.mHandler.sendMessage(msg);
        return true;
    }
    }
    return false;
}

From source file:com.hippo.largeimageview.GestureRecognizer.java

public void onTouchEvent(MotionEvent event) {
    // If pointer count is more than 1, must be scale action
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_UP:
        mListener.onUp();//  ww w.  j a  v a  2 s.  c o m
        break;
    case MotionEvent.ACTION_CANCEL:
        mListener.onCancel();
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        mScale = event.getPointerCount() > 1;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        mScale = (event.getPointerCount() - 1) > 1;
        break;
    }

    mGestureDetector.onTouchEvent(event);
    mScaleDetector.onTouchEvent(event);
}

From source file:com.github.nisrulz.sensey.TouchTypeDetector.java

/**
 * On touch event boolean./*from  w w w  .  j  a va  2  s .  co  m*/
 *
 * @param event
 *     the event
 * @return the boolean
 */
boolean onTouchEvent(MotionEvent event) {

    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_POINTER_DOWN:
        if (event.getPointerCount() == 3) {
            touchTypListener.onThreeFingerSingleTap();
        } else if (event.getPointerCount() == 2) {
            touchTypListener.onTwoFingerSingleTap();
        }
    }
    return gDetect.onTouchEvent(event);
}

From source file:ngoctdn.vng.gesture.CupcakeGestureDetector.java

public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        mVelocityTracker = VelocityTracker.obtain();
        if (null != mVelocityTracker) {
            mVelocityTracker.addMovement(ev);
        } else {//  ww w  .ja  v  a 2  s  .co m
            Log.i(LOG_TAG, "Velocity tracker is null");
        }

        mLastTouchX = getActiveX(ev);
        mLastTouchY = getActiveY(ev);
        mFirstRawTouchY = ev.getRawY();
        mLastRawTouchY = ev.getRawY();
        mIsDragging = false;
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEvent.ACTION_POINTER_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;

    case MotionEvent.ACTION_MOVE: {
        final float x = getActiveX(ev);
        final float y = getActiveY(ev);
        final float dx = x - mLastTouchX, dy = y - mLastTouchY;

        if (!mIsDragging) {
            // Use Pythagoras to see if drag length is larger than
            // touch slop
            mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
        }

        if (mIsDragging) {
            if (ev.getPointerCount() == 1)
                mListener.onDrag(mLastRawTouchY, ev.getRawY(), dx, dy);
            mLastTouchX = x;
            mLastTouchY = y;
            mLastRawTouchY = ev.getRawY();
            // if (mListener != null) {
            // mListener.onScrolling(mLastRawTouchY, ev.getRawY());
            // mLastRawTouchY = ev.getRawY();
            // }

            if (null != mVelocityTracker) {
                mVelocityTracker.addMovement(ev);
            }
        }
        if (mActivePointerId == -1 && mListener != null) {
            mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }
        break;
    }

    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {

        if (mIsDragging) {
            if (null != mVelocityTracker) {

                mLastTouchX = getActiveX(ev);
                mLastTouchY = getActiveY(ev);

                // if (mListener != null) {
                // mListener.onScrolling(mFirstTouchY, mLastTouchY);
                // }

                // Compute velocity within the last 1000ms
                mVelocityTracker.addMovement(ev);
                mVelocityTracker.computeCurrentVelocity(1000);

                final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();

                // If the velocity is greater than minVelocity, call
                // listener
                if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
                    mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
                }
            }
        }

        if (mListener != null) {
            mLastRawTouchY = ev.getRawY();
            if (mVelocityTracker != null)
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), mVelocityTracker.getYVelocity());
            else
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }

        // Recycle Velocity Tracker
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

    return true;
}

From source file:ngoctdn.vng.gesture.DragGestureDetector.java

public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        mVelocityTracker = VelocityTracker.obtain();
        if (null != mVelocityTracker) {
            mVelocityTracker.addMovement(ev);
        } else {// www. j av a  2s . co  m
            Log.i(LOG_TAG, "Velocity tracker is null");
        }

        mLastTouchX = getActiveX(ev);
        mLastTouchY = getActiveY(ev);
        mFirstRawTouchY = ev.getRawY();
        mLastRawTouchY = ev.getRawY();
        mIsDragging = false;
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEvent.ACTION_POINTER_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;

    case MotionEvent.ACTION_MOVE: {
        final float x = getActiveX(ev);
        final float y = getActiveY(ev);
        final float dx = x - mLastTouchX, dy = y - mLastTouchY;

        if (!mIsDragging) {
            // Use Pythagoras to see if drag length is larger than
            // touch slop
            mIsDragging = (float) Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
        }

        if (mIsDragging) {
            if (ev.getPointerCount() == 1)
                mListener.onDrag(mLastRawTouchY, ev.getRawY(), dx, dy);
            mLastTouchX = x;
            mLastTouchY = y;
            mLastRawTouchY = ev.getRawY();
            // if (mListener != null) {
            // mListener.onScrolling(mLastRawTouchY, ev.getRawY());
            // mLastRawTouchY = ev.getRawY();
            // }

            if (null != mVelocityTracker) {
                mVelocityTracker.addMovement(ev);
            }
        }
        if (mActivePointerId == -1 && mListener != null) {
            mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }
        break;
    }

    //      case MotionEvent.ACTION_CANCEL: {
    //         if (mListener != null) {
    //            mLastRawTouchY = ev.getRawY();
    //            mListener.onRelease(mFirstRawTouchY, ev.getRawY());
    //         }
    //         // Recycle Velocity Tracker
    //         if (null != mVelocityTracker) {
    //            mVelocityTracker.recycle();
    //            mVelocityTracker = null;
    //         }
    //         break;
    //      }
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {

        if (mIsDragging) {
            if (null != mVelocityTracker) {

                mLastTouchX = getActiveX(ev);
                mLastTouchY = getActiveY(ev);

                // if (mListener != null) {
                // mListener.onScrolling(mFirstTouchY, mLastTouchY);
                // }

                // Compute velocity within the last 1000ms
                mVelocityTracker.addMovement(ev);
                mVelocityTracker.computeCurrentVelocity(1000);

                final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();

                // If the velocity is greater than minVelocity, call
                // listener
                if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
                    mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
                }
            }
        }

        if (mListener != null) {
            mLastRawTouchY = ev.getRawY();
            if (mVelocityTracker != null)
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), mVelocityTracker.getYVelocity());
            else
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }

        // Recycle Velocity Tracker
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

    return true;
}