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:paulscode.android.mupen64plusae.game.GameDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    // Only intercept this touch event if it is not directly over a touchscreen input
    // (So the game sidebar is never accidentally triggered)

    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;
    long currentEventTime = System.currentTimeMillis();

    boolean upAction = (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_CANCEL
            || actionCode == MotionEvent.ACTION_POINTER_UP);

    // If the touch ended along the left edge, ignore edge swipes for a little while
    if (upAction) {
        int actionIndex = MotionEventCompat.getActionIndex(event);
        int xLocation = (int) event.getX(actionIndex);
        if (xLocation < 10)
            mLastEdgeTime = currentEventTime;
    }/*from   ww  w. ja  va 2 s.  c om*/

    if (ignore.contains(event)) {
        if (upAction)
            ignore.remove(event);
        return false;
    } else if (actionCode == MotionEvent.ACTION_POINTER_DOWN
            || (actionCode == MotionEvent.ACTION_DOWN && currentEventTime - mLastEdgeTime < 250)) {
        // Ignore secondary inputs and inputs too close to the most recent one (0.25 seconds)
        ignore.add(event);
        return false;
    } else if (actionCode == MotionEvent.ACTION_DOWN && !isDrawerOpen(GravityCompat.START)
            && mTouchMap != null) {
        for (int i = 0; i < event.getPointerCount(); i++) {
            int xLocation = (int) event.getX(i);
            int yLocation = (int) event.getY(i);

            // See if it touches the d-pad or the C buttons,
            // as they are small enough to interfere with left edge swipes
            // (fortunately placing the C buttons on the left is unusual)
            int buttonIndex = mTouchMap.getButtonPress(xLocation, yLocation);
            if (buttonIndex != TouchMap.UNMAPPED) {
                if ("dpad".equals(TouchMap.ASSET_NAMES.get(buttonIndex))
                        || "groupC".equals(TouchMap.ASSET_NAMES.get(buttonIndex))) {
                    ignore.add(event);
                    return false;
                }
            }

            // See if it touches the analog stick
            Point point = mTouchMap.getAnalogDisplacement(xLocation, yLocation);

            int dX = point.x;
            int dY = point.y;
            float displacement = (float) Math.sqrt((dX * dX) + (dY * dY));

            // Add a slightly larger hit area around the analog stick,
            // by artificially shrinking the size of the displacement
            displacement = displacement * 0.9f;

            if (mTouchMap.isInCaptureRange(displacement)) {
                ignore.add(event);
                return false;
            }
        }
    }

    // Let the parent DrawerLayout deal with it
    try {
        return super.onInterceptTouchEvent(event);
    } catch (Exception ex) {
        // For some reason this is very prone to crashing here when using multitouch:
        // android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent
        // But fortunately this is very unimportant, so we can safely ignore it
        // The source code is here if you want to attempt a fix:
        // https://github.com/android/platform_frameworks_support/blob/master/v4/java/android/support/v4/widget/ViewDragHelper.java
        return false;
    }
}

From source file:com.intel.xdk.multitouch.MultiTouch.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();/*w  w  w.  j  a  va  2 s . com*/

    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                try {
                    Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class);
                    m.invoke(WebView.class, true);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //WebView.setWebContentsDebuggingEnabled(true);
            }
        }
    });

    touchy = new View.OnTouchListener() {

        private SparseArray<Long> pointerId2Identifier = new SparseArray<Long>();

        @Override
        public boolean onTouch(View v, MotionEvent ev) {
            if (isMultitouchEnabled) {
                int pointerCount = ev.getPointerCount();

                //get the correct action
                int maskedAction = ev.getActionMasked();
                int idx = ev.getActionIndex();
                try {
                    String js = null;
                    if (maskedAction == MotionEvent.ACTION_POINTER_DOWN
                            || maskedAction == MotionEvent.ACTION_DOWN) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        //make a timestamp identifier and store it
                        long identifier = System.currentTimeMillis();
                        pointerId2Identifier.put(id, identifier);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchstart'},", identifier, x, y,
                                h, w);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_POINTER_UP
                            || maskedAction == MotionEvent.ACTION_UP) {
                        int x = (int) ev.getX(idx);
                        int y = (int) ev.getY(idx);
                        int h = (int) v.getHeight();
                        int w = (int) v.getWidth();
                        int id = ev.getPointerId(idx);
                        js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchend'},",
                                pointerId2Identifier.get(id), x, y, h, w);
                        pointerId2Identifier.remove(id);
                        queueMultitouchData(js, id, maskedAction);
                    } else if (maskedAction == MotionEvent.ACTION_MOVE) {
                        //send all events if it is a move
                        for (int i = 0; i < pointerCount; i++) {
                            int x = (int) ev.getX(i);
                            int y = (int) ev.getY(i);
                            int h = (int) v.getHeight();
                            int w = (int) v.getWidth();
                            int id = ev.getPointerId(i);
                            js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchmove'},",
                                    pointerId2Identifier.get(id), x, y, h, w);
                            queueMultitouchData(js, id, maskedAction);
                        }
                    } else {
                        Log.e("[intel.xdk]", "got a MotionEvent that is not up/down/move:" + ev);
                    }
                    //Log.i("[intel.xdk]", "onTouchEvent:"+js);
                } catch (Exception e) {
                    Log.e("[intel.xdk]", "Got an exception back from WebView: ", e);
                }

                return true;
            } else {
                return false;
            }
        }
    };
    webView.setOnTouchListener(touchy);

    lock = this;
    messages = new ArrayList<String>(0);
}

From source file:com.just.agentweb.NestedScrollAgentWebView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean result = false;

    MotionEvent trackedEvent = MotionEvent.obtain(event);

    final int action = MotionEventCompat.getActionMasked(event);

    if (action == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;/*from  w w w. j a  va  2  s  .c o m*/
    }

    int y = (int) event.getY();

    event.offsetLocation(0, mNestedYOffset);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = y;
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        result = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastMotionY - y;

        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            trackedEvent.offsetLocation(0, mScrollOffset[1]);
            mNestedYOffset += mScrollOffset[1];
        }

        mLastMotionY = y - mScrollOffset[1];

        int oldY = getScrollY();
        int newScrollY = Math.max(0, oldY + deltaY);
        int dyConsumed = newScrollY - oldY;
        int dyUnconsumed = deltaY - dyConsumed;

        if (dispatchNestedScroll(0, dyConsumed, 0, dyUnconsumed, mScrollOffset)) {
            mLastMotionY -= mScrollOffset[1];
            trackedEvent.offsetLocation(0, mScrollOffset[1]);
            mNestedYOffset += mScrollOffset[1];
        }

        result = super.onTouchEvent(trackedEvent);
        trackedEvent.recycle();
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        stopNestedScroll();
        result = super.onTouchEvent(event);
        break;
    }
    return result;
}

From source file:com.windnow.StationPicActivity.java

@SuppressLint("NewApi")
@Override//from  w w w  . j  a va2 s . c  om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_station_pic);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }
    TextView tv = (TextView) findViewById(R.id.textViewPicName);
    tv.setText(getIntent().getExtras().getString("name"));
    imageDetail = (ImageView) findViewById(R.id.imageView1);
    String filename = "pic" + getIntent().getExtras().getString("txt").hashCode();
    Bitmap pic = null;
    try {
        FileInputStream is = this.openFileInput(filename);
        pic = BitmapFactory.decodeStream(is);
        is.close();
    } catch (IOException e) {
        LoadSaveOps.printErrorToLog(e);
    }
    imageDetail.setImageBitmap(pic);
    imageDetail.setOnTouchListener(new View.OnTouchListener() {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            ImageView view = (ImageView) v;
            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:

                savedMatrix.set(matrix);
                startPoint.set(event.getX(), event.getY());
                mode = DRAG;
                break;

            case MotionEvent.ACTION_POINTER_DOWN:

                oldDist = spacing(event);

                if (oldDist > 10f) {
                    savedMatrix.set(matrix);
                    midPoint(midPoint, event);
                    mode = ZOOM;
                }
                break;

            case MotionEvent.ACTION_UP:

            case MotionEvent.ACTION_POINTER_UP:
                mode = NONE;

                break;

            case MotionEvent.ACTION_MOVE:
                if (mode == DRAG) {
                    matrix.set(savedMatrix);
                    matrix.postTranslate(event.getX() - startPoint.x, event.getY() - startPoint.y);
                } else if (mode == ZOOM) {
                    float newDist = spacing(event);
                    if (newDist > 10f) {
                        matrix.set(savedMatrix);
                        float scale = newDist / oldDist;
                        matrix.postScale(scale, scale, midPoint.x, midPoint.y);
                        matrix.postTranslate(event.getX() - startPoint.x, event.getY() - startPoint.y); //new
                    }
                }
                break;

            }
            view.setImageMatrix(matrix);

            return true;
        }

        @SuppressLint("FloatMath")
        private float spacing(MotionEvent event) {
            float x = event.getX(0) - event.getX(1);
            float y = event.getY(0) - event.getY(1);
            return FloatMath.sqrt(x * x + y * y);
        }

        private void midPoint(PointF point, MotionEvent event) {
            float x = event.getX(0) + event.getX(1);
            float y = event.getY(0) + event.getY(1);
            point.set(x / 2, y / 2);
        }
    });

}

From source file:akhil.alltrans.NestedScrollingMarkDownView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean result = false;

    MotionEvent trackedEvent = MotionEvent.obtain(event);

    final int action = MotionEventCompat.getActionMasked(event);

    if (action == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;/* ww w  .ja  v a 2  s.c  o  m*/
    }

    int y = (int) event.getY();

    event.offsetLocation(0, mNestedYOffset);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = y;
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        result = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastMotionY - y;

        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            trackedEvent.offsetLocation(0, mScrollOffset[1]);
            mNestedYOffset += mScrollOffset[1];
        }

        int oldY = getScrollY();
        mLastMotionY = y - mScrollOffset[1];
        if (deltaY < 0) {
            int newScrollY = Math.max(0, oldY + deltaY);
            deltaY -= newScrollY - oldY;
            if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
                mLastMotionY -= mScrollOffset[1];
                trackedEvent.offsetLocation(0, mScrollOffset[1]);
                mNestedYOffset += mScrollOffset[1];
            }
        }

        result = super.onTouchEvent(trackedEvent);
        trackedEvent.recycle();
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        stopNestedScroll();
        result = super.onTouchEvent(event);
        break;
    }
    return result;
}

From source file:ch.jeda.platform.android.CanvasFragment.java

@Override
public boolean onTouch(final View view, final MotionEvent event) {
    int index;/*from   w w w.j a  v a  2s .  c om*/
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        index = event.getActionIndex();
        this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_DOWN, event.getPointerId(index),
                (int) event.getX(index), (int) event.getY(index)));
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        index = event.getActionIndex();
        this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_UP, event.getPointerId(index),
                (int) event.getX(index), (int) event.getY(index)));
        break;
    case MotionEvent.ACTION_MOVE:
        for (index = 0; index < event.getPointerCount(); ++index) {
            this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_MOVED,
                    event.getPointerId(index), (int) event.getX(index), (int) event.getY(index)));
        }

        break;
    }
    return true;
}

From source file:com.aohuan.dodo.dispatchevent_about.dummy_demo.view1.NestedScrollWebView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean result = false;

    MotionEvent trackedEvent = MotionEvent.obtain(event);

    final int action = MotionEventCompat.getActionMasked(event);

    if (action == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;//from  w w  w . j  ava  2 s.  com
    }

    int y = (int) event.getY();

    event.offsetLocation(0, mNestedYOffset);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = y;
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        result = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastMotionY - y;

        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            trackedEvent.offsetLocation(0, mScrollOffset[1]);
            mNestedYOffset += mScrollOffset[1];
        }

        int oldY = getScrollY();
        mLastMotionY = y - mScrollOffset[1];
        if (deltaY < 0) {
            int newScrollY = Math.max(0, oldY + deltaY);
            deltaY -= newScrollY - oldY;
            if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
                mLastMotionY -= mScrollOffset[1];
                trackedEvent.offsetLocation(0, mScrollOffset[1]);
                mNestedYOffset += mScrollOffset[1];
            }
        }

        trackedEvent.recycle();
        result = super.onTouchEvent(trackedEvent);
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        stopNestedScroll();
        result = super.onTouchEvent(event);
        break;
    }
    return result;
}

From source file:org.deviceconnect.android.deviceplugin.host.activity.TouchProfileActivity.java

@Override
public boolean onTouchEvent(final MotionEvent event) {
    List<Event> events;
    String state = null;// w w  w .jav  a 2 s.  c  o m
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: // 1st touch only.
    case MotionEvent.ACTION_POINTER_DOWN: // Others touch.
        state = HostDeviceApplication.STATE_START;
        // "ontouch" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH);
        if (events != null) {
            sendEventData(state, event, events);
        }

        // "ontouchstart" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_START);
        break;
    case MotionEvent.ACTION_UP: // Last touch remove only.
    case MotionEvent.ACTION_POINTER_UP: // Others touch move.
        state = HostDeviceApplication.STATE_END;
        // "ontouchend" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_END);
        break;
    case MotionEvent.ACTION_MOVE:
        state = HostDeviceApplication.STATE_MOVE;
        // "ontouchmove" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_MOVE);
        break;
    case MotionEvent.ACTION_CANCEL:
        state = HostDeviceApplication.STATE_CANCEL;
        // "ontouchcancel" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_CANCEL);
        break;
    default:
        return mGestureDetector.onTouchEvent(event);
    }

    if (events != null) {
        sendEventData(state, event, events);
    }
    return mGestureDetector.onTouchEvent(event);
}

From source file:org.deviceconnect.android.deviceplugin.wear.activity.WearTouchProfileActivity.java

@Override
public boolean dispatchTouchEvent(@NonNull final MotionEvent event) {
    boolean execFlag = false;
    int action = (event.getAction() & MotionEvent.ACTION_MASK);
    String strAction = null;/*from  ww  w  . j  av  a 2  s.  c o m*/
    switch (action) {
    case MotionEvent.ACTION_DOWN: // 1st touch only.
    case MotionEvent.ACTION_POINTER_DOWN: // Others touch.
        // "ontouch" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCH) != 0) {
            sendEventData(WearConst.PARAM_TOUCH_TOUCH, event);
        }

        // "ontouchstart" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHSTART) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHSTART;
            execFlag = true;
        }
        break;
    case MotionEvent.ACTION_UP: // Last touch remove only.
    case MotionEvent.ACTION_POINTER_UP: // Others touch move.
        // "ontouchend" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHEND) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHEND;
            execFlag = true;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        // "ontouchmove" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHMOVE) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHMOVE;
            execFlag = true;
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        // "ontouchcancel" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCANCEL) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHCANCEL;
            execFlag = true;
        }
        break;
    default:
        return mGestureDetector.onTouchEvent(event);
    }

    if (execFlag) {
        sendEventData(strAction, event);
    }
    return mGestureDetector.onTouchEvent(event) || super.dispatchTouchEvent(event);
}

From source file:org.mozilla.gecko.ui.SimpleScaleGestureDetector.java

/** Forward touch events to this function. */
public void onTouchEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        onTouchStart(event);// w w w . j  a  va  2 s.  co  m
        break;
    case MotionEvent.ACTION_MOVE:
        onTouchMove(event);
        break;
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        onTouchEnd(event);
        break;
    }
}