Example usage for android.view MotionEvent getPointerCount

List of usage examples for android.view MotionEvent getPointerCount

Introduction

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

Prototype

public final int getPointerCount() 

Source Link

Document

The number of pointers of data contained in this event.

Usage

From source file:ch.fhnw.comgr.GLES3Activity.java

public boolean handleTouchMove(final MotionEvent event) {
    final int x0 = (int) event.getX(0);
    final int y0 = (int) event.getY(0);
    int touchCount = event.getPointerCount();
    //Log.i(TAG, "Mv:" + touchCount);

    if (touchCount == 1) {
        myView.queueEvent(new Runnable() {
            public void run() {
                GLES3Lib.onMouseMove(x0, y0);
            }//from www  .  j av  a 2  s.  c  o  m
        });
    } else if (touchCount == 2) {
        final int x1 = (int) event.getX(1);
        final int y1 = (int) event.getY(1);
        myView.queueEvent(new Runnable() {
            public void run() {
                GLES3Lib.onTouch2Move(x0, y0, x1, y1);
            }
        });
    }
    myView.requestRender();
    return true;
}

From source file:chenyoufu.hciprojectes10.MyGLSurfaceView.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    int action = MotionEventCompat.getActionMasked(event);
    int index = MotionEventCompat.getActionIndex(event);

    if (event.getPointerCount() > 1) {
        if (action == MotionEvent.ACTION_POINTER_UP && event.getPointerCount() == 2) {
            xOri = MotionEventCompat.getX(event, 1 - index);
            yOri = MotionEventCompat.getY(event, 1 - index);
        }/*from w  ww  .j a  v a 2  s  .  c  o m*/
        mScaleDetector.onTouchEvent(event);
    } else {
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            xOri = MotionEventCompat.getX(event, index);
            yOri = MotionEventCompat.getY(event, index);

            break;
        case MotionEvent.ACTION_MOVE:
            float xNow = MotionEventCompat.getX(event, index);
            float yNow = MotionEventCompat.getY(event, index);

            float[] xMove = Global.fArrayMul(Global.getCamCrossProductNV(), (xOri - xNow) / Global.moveFactor);
            Global.cameraEye = Global.fArrayAdd(Global.cameraEye, xMove);
            Global.cameraCentre = Global.fArrayAdd(Global.cameraCentre, xMove);
            float[] yMove = Global.fArrayMul(Global.cameraUp, (yNow - yOri) / Global.moveFactor);
            Global.cameraEye = Global.fArrayAdd(Global.cameraEye, yMove);
            Global.cameraCentre = Global.fArrayAdd(Global.cameraCentre, yMove);
            xOri = xNow;
            yOri = yNow;
            break;
        default:
            break;
        }
    }
    requestRender();
    return true;
}

From source file:de.gobro.andreas.pa.pa_cleint_java.SendTouch.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        Log.d("down", "action_down");
        break;/*from www .  j a v  a 2  s . c  o m*/
    }
    case MotionEvent.ACTION_MOVE: {
        for (Integer i = 0; (i < ev.getPointerCount()) && (i < maxPoints); i++) {
            //final Integer pointerIndex = MotionEventCompat.getActionIndex(ev);

            Integer id = ev.getPointerId(i);
            Log.d("ind", "pinterindex" + i.toString());
            Log.d("ind", "ID" + id.toString());
            Log.d("pos", "(" + String.valueOf(MotionEventCompat.getX(ev, i)) + ";"
                    + String.valueOf(MotionEventCompat.getY(ev, i)) + ")");
            Log.d("test", "action_move");

            try {
                serializer.startTag("", "touch");
                serializer.startTag("", "dx");
                serializer.text(String.valueOf(MotionEventCompat.getX(ev, i) / size.x));
                serializer.endTag("", "dx");
                serializer.startTag("", "dy");
                serializer.text(String.valueOf(MotionEventCompat.getY(ev, i) / size.y));
                serializer.endTag("", "dy");
                serializer.startTag("", "id");
                serializer.text(id.toString());
                serializer.endTag("", "id");
                serializer.endTag("", "touch");

            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (RuntimeException e) {
                e.printStackTrace();
            }

            //             try {
            //               writer.writeStartElement("touch");
            //                  writer.writeStartElement("dx");
            //                     writer.writeCharacters(String.valueOf(MotionEventCompat.getX(ev, i)/size.x));
            //                  writer.writeEndElement();
            //                  writer.writeStartElement("dy");
            //                     writer.writeCharacters(String.valueOf(MotionEventCompat.getY(ev, i)/size.y));
            //                  writer.writeEndElement();
            //                  writer.writeStartElement("id");
            //                     writer.writeCharacters(id.toString());
            //                  writer.writeEndElement();                  
            //               writer.writeEndElement();
            //            } catch (XMLStreamException e) {
            //               // TODO Auto-generated catch block
            //               e.printStackTrace();
            //            }

        }

        //write the stuff to the network
        try {
            serializer.flush();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            finish();

        }
        break;
    }
    case MotionEvent.ACTION_UP: {
        Log.d("test", "action_up");
        break;
    }
    case MotionEvent.ACTION_CANCEL: {
        Log.d("test", "action_cancel");
        break;
    }
    case MotionEvent.ACTION_POINTER_DOWN: {
        Log.d("down", "action_p_down");
        break;
    }
    case MotionEvent.ACTION_POINTER_UP: {
        Log.d("test", "action_p_up");
        break;
    }
    }
    return true;
}

From source file:org.witness.informacam.app.editors.image.ImageRegion.java

public boolean onTouch(View v, MotionEvent event) {

    fingerCount = event.getPointerCount();
    //   Log.v(LOGTAG,"onTouch: fingers=" + fingerCount);

    switch (event.getAction() & MotionEvent.ACTION_MASK) {

    case MotionEvent.ACTION_DOWN:

        mImageEditor.doRealtimePreview = true;
        mImageEditor.updateDisplayImage();
        //mTmpBounds = new RectF(mBounds);

        if (fingerCount == 1) {
            //float[] points = {event.getX(), event.getY()};                   
            //iMatrix.mapPoints(points);
            //mStartPoint = new PointF(points[0],points[1]);
            mStartPoint = new PointF(event.getX(), event.getY());
            //Log.v(LOGTAG,"startPoint: " + mStartPoint.x + " " + mStartPoint.y);
        }//www.  j a va2  s . c o m

        moved = false;

        return false;
    case MotionEvent.ACTION_POINTER_UP:

        Log.v(LOGTAG, "second finger removed - pointer up!");

        return moved;

    case MotionEvent.ACTION_UP:

        mImageEditor.doRealtimePreview = true;
        mImageEditor.updateDisplayImage();
        //mTmpBounds = null;

        return moved;

    case MotionEvent.ACTION_MOVE:

        if (fingerCount > 1) {

            float[] points = { event.getX(0), event.getY(0), event.getX(1), event.getY(1) };
            iMatrix.mapPoints(points);

            mStartPoint = new PointF(points[0], points[1]);

            RectF newBox = new RectF();
            newBox.left = Math.min(points[0], points[2]);
            newBox.top = Math.min(points[1], points[3]);
            newBox.right = Math.max(points[0], points[2]);
            newBox.bottom = Math.max(points[1], points[3]);

            moved = true;

            if (newBox.left != newBox.right && newBox.top != newBox.bottom) {

                updateBounds(newBox.left, newBox.top, newBox.right, newBox.bottom);
            }

        } else if (fingerCount == 1) {

            if (Math.abs(mStartPoint.x - event.getX()) > MIN_MOVE) {
                moved = true;

                float[] points = { mStartPoint.x, mStartPoint.y, event.getX(), event.getY() };

                iMatrix.mapPoints(points);

                float diffX = points[0] - points[2];
                float diffY = points[1] - points[3];

                float left = 0, top = 0, right = 0, bottom = 0;

                if (cornerMode == CORNER_NONE) {

                    left = mBounds.left - diffX;
                    top = mBounds.top - diffY;
                    right = mBounds.right - diffX;
                    bottom = mBounds.bottom - diffY;
                } else if (cornerMode == CORNER_UPPER_LEFT) {
                    left = mBounds.left - diffX;
                    top = mBounds.top - diffY;
                    right = mBounds.right;
                    bottom = mBounds.bottom;

                } else if (cornerMode == CORNER_LOWER_LEFT) {
                    left = mBounds.left - diffX;
                    top = mBounds.top;
                    right = mBounds.right;
                    bottom = mBounds.bottom - diffY;

                } else if (cornerMode == CORNER_UPPER_RIGHT) {
                    left = mBounds.left;
                    top = mBounds.top - diffY;
                    right = mBounds.right - diffX;
                    bottom = mBounds.bottom;
                } else if (cornerMode == CORNER_LOWER_RIGHT) {
                    left = mBounds.left;
                    top = mBounds.top;
                    right = mBounds.right - diffX;
                    bottom = mBounds.bottom - diffY;
                }

                if ((left + CORNER_MAX) > right || (top + CORNER_MAX) > bottom)
                    return false;

                //updateBounds(Math.min(left, right), Math.min(top,bottom), Math.max(left, right), Math.max(top, bottom));
                updateBounds(left, top, right, bottom);

                mStartPoint = new PointF(event.getX(), event.getY());
            } else {
                moved = false;
            }

        }

        mImageEditor.updateDisplayImage();

        return true;

    }

    return false;

}

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

/**
 * Send event data.//from w  ww  .ja  va  2s  .  c  o  m
 *
 * @param state MotionEvent state.
 * @param event MotionEvent.
 * @param events Event request list.
 */
private void sendEventData(final String state, final MotionEvent event, final List<Event> events) {
    List<Event> touchEvents = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
            ATTRIBUTE_ON_TOUCH_CHANGE);
    Bundle touchdata = new Bundle();
    List<Bundle> touchlist = new ArrayList<Bundle>();
    Bundle touches = new Bundle();
    for (int n = 0; n < event.getPointerCount(); n++) {
        int pointerId = event.getPointerId(n);
        touchdata.putInt(TouchProfile.PARAM_ID, pointerId);
        touchdata.putFloat(TouchProfile.PARAM_X, event.getX(n));
        touchdata.putFloat(TouchProfile.PARAM_Y, event.getY(n));
        touchlist.add((Bundle) touchdata.clone());
    }
    touches.putParcelableArray(TouchProfile.PARAM_TOUCHES, touchlist.toArray(new Bundle[touchlist.size()]));
    for (int i = 0; i < events.size(); i++) {
        Event eventdata = events.get(i);
        String attr = eventdata.getAttribute();
        Intent intent = EventManager.createEventMessage(eventdata);
        intent.putExtra(TouchProfile.PARAM_TOUCH, touches);
        intent.setAction(HostTouchProfile.ACTION_TOUCH);
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
        mApp.setTouchCache(attr, touches);
    }
    for (int i = 0; i < touchEvents.size(); i++) {
        Event eventdata = touchEvents.get(i);
        String attr = eventdata.getAttribute();
        touches.putString("state", state);
        Intent intent = EventManager.createEventMessage(eventdata);
        intent.putExtra(TouchProfile.PARAM_TOUCH, touches);
        intent.setAction(HostTouchProfile.ACTION_TOUCH);
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
        mApp.setTouchCache(attr, touches);
    }

}

From source file:com.apptentive.android.sdk.util.image.PreviewImageView.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    gestureDetector.onTouchEvent(event);
    scaleGestureDetector.onTouchEvent(event);

    float x = 0, y = 0;
    // Get multiple touch points
    final int pointerCount = event.getPointerCount();
    // Calculate average x and y
    for (int i = 0; i < pointerCount; i++) {
        x += event.getX(i);/*ww  w  . j  a  v  a 2 s .  c o m*/
        y += event.getY(i);
    }
    x = x / pointerCount;
    y = y / pointerCount;

    /**
     * Reset lastX and lastY
     */
    if (pointerCount != lastPointerCount) {
        isCanDrag = false;
        lastX = x;
        lastY = y;
    }

    lastPointerCount = pointerCount;

    switch (event.getAction()) {
    case MotionEvent.ACTION_MOVE:
        float dx = x - lastX;
        float dy = y - lastY;

        if (!isCanDrag) {
            isCanDrag = isCanDrag(dx, dy);
        }
        if (isCanDrag) {
            RectF rectF = getMatrixRectF();
            if (getDrawable() != null) {
                isCheckLeftAndRight = isCheckTopAndBottom = true;
                // No left/right translation if image width is less than screen width
                if (rectF.width() < getWidth()) {
                    dx = 0;
                    isCheckLeftAndRight = false;
                }
                // No Up/Down translation if image height is less than screen height
                if (rectF.height() < getHeight()) {
                    dy = 0;
                    isCheckTopAndBottom = false;
                }
                scaleMatrix.postTranslate(dx, dy);
                checkMatrixBounds();
                setImageMatrix(scaleMatrix);
            }
        }
        lastX = x;
        lastY = y;
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        lastPointerCount = 0;
        break;
    }
    return true;
}

From source file:org.cocos2dx.lib.TextInputWraper.java

public boolean onTouchEvent(final MotionEvent event) {
    // these data are used in ACTION_MOVE and ACTION_CANCEL
    final int pointerNumber = event.getPointerCount();
    final int[] ids = new int[pointerNumber];
    final float[] xs = new float[pointerNumber];
    final float[] ys = new float[pointerNumber];

    for (int i = 0; i < pointerNumber; i++) {
        ids[i] = event.getPointerId(i);/*w w w . j  av a 2  s. c om*/
        xs[i] = event.getX(i);
        ys[i] = event.getY(i);
    }

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN:
        final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerDown = event.getPointerId(indexPointerDown);
        final float xPointerDown = event.getX(indexPointerDown);
        final float yPointerDown = event.getY(indexPointerDown);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown);
            }
        });
        break;

    case MotionEvent.ACTION_DOWN:
        // there are only one finger on the screen
        final int idDown = event.getPointerId(0);
        final float xDown = xs[0];
        final float yDown = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idDown, xDown, yDown);
            }
        });
        break;

    case MotionEvent.ACTION_MOVE:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionMove(ids, xs, ys);
            }
        });
        break;

    case MotionEvent.ACTION_POINTER_UP:
        final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerUp = event.getPointerId(indexPointUp);
        final float xPointerUp = event.getX(indexPointUp);
        final float yPointerUp = event.getY(indexPointUp);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp);
            }
        });
        break;

    case MotionEvent.ACTION_UP:
        // there are only one finger on the screen
        final int idUp = event.getPointerId(0);
        final float xUp = xs[0];
        final float yUp = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idUp, xUp, yUp);
            }
        });
        break;

    case MotionEvent.ACTION_CANCEL:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionCancel(ids, xs, ys);
            }
        });
        break;
    }

    if (debug) {
        dumpEvent(event);
    }
    return true;
}

From source file:com.dj.hacktor.nshiddenlayout.views.CustomNestedScrollView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        xDistance = yDistance = 0f;// w  w  w.j  a  v a2 s  . com
        lastX = ev.getX();
        lastY = ev.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        final float curX = ev.getX();
        final float curY = ev.getY();
        xDistance += Math.abs(curX - lastX);
        yDistance += Math.abs(curY - lastY);
        lastX = curX;
        lastY = curY;
        if (xDistance > yDistance)
            return false;
    }

    return super.onInterceptTouchEvent(ev) || ev.getPointerCount() == 2;
}

From source file:com.funzio.pure2D.demo.particles.NovaActivity.java

@Override
public boolean onTouch(final View v, final MotionEvent event) {
    final int action = event.getAction() & MotionEvent.ACTION_MASK;

    // null check
    if (mNovaFactory == null) {
        return false;
    }//from  w w  w  .j a  v a2  s  . c o m

    if (action == MotionEvent.ACTION_DOWN) {
        mStage.queueEvent(new Runnable() {
            @Override
            public void run() {
                final int pointerCount = event.getPointerCount();
                for (int i = 0; i < pointerCount; i++) {
                    // for demo, limit the number of emitters
                    if (mScene.getNumGrandChildren() < mNovaFactory.getPoolSize()) {
                        addObject(event.getX(i), mDisplaySize.y - event.getY(i));
                    }
                }
            }
        });
    }

    return true;
}

From source file:de.dmxcontrol.activity.ControlActivity.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getPointerCount() == 2 && oldState == ActionSelectorFragment.STATE_OPTIC_PANEL) {
        return false;
    } else {/*  w w w .  j  a v  a 2  s . c  o  m*/
        return gestureDetector.onTouchEvent(event);
    }
}