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:cn.limc.androidcharts.event.SlipGestureDetector.java

public boolean onTouchEvent(MotionEvent event) {
    int pointers = event.getPointerCount();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    // ?/*from   w w  w.  j a  v a2s . c o  m*/
    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.waz.zclient.pages.main.conversation.views.image.ImageDragViewContainer.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (ev == null) {
        return false;
    }//from w  w  w. j a v a2 s  . c  om

    if (ev.getPointerCount() != 1) {
        return false;
    }

    boolean shouldDrag;
    try {
        shouldDrag = dragHelper.shouldInterceptTouchEvent(ev);
    } catch (Exception e) {
        return false;
    }

    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        imageViewDragCallback.startX = ev.getX();
        imageViewDragCallback.startY = ev.getY();
        imageViewDragCallback.centerX = getLeft() + (getRight() - getLeft()) / 2f;
        imageViewDragCallback.centerY = getTop() + (getBottom() - getTop()) / 2f;
    }

    boolean intercept = enabled && shouldDrag;
    if (callback != null && intercept) {
        callback.onStartDrag();
    }
    return intercept;
}

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

/**
 * Send event data./* w w  w .  j  ava  2s.  c o  m*/
 *
 * @param action Action.
 * @param event MotionEvent.
 */
private void sendEventData(final String action, final MotionEvent event) {
    int dataCount = event.getPointerCount();
    StringBuilder data = new StringBuilder(String.valueOf(dataCount));
    data.append(",").append(action);
    for (int n = 0; n < dataCount; n++) {
        int pointerId = event.getPointerId(n);
        data.append(",").append(pointerId).append(",").append(event.getX(n)).append(",").append(event.getY(n));
    }

    sendEvent(WearConst.WEAR_TO_DEVICE_TOUCH_DATA, data.toString());
}

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

/**
 * On touch event boolean.//  www.j  av a  2s . c  o 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:com.deanlib.ootb.widget.loopviewpager.LoopViewPager.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    try {//from w  w  w  .j a va  2  s.c  om

        if (ev.getPointerCount() > 1 && mIsDisallowIntercept) {
            requestDisallowInterceptTouchEvent(false);
            boolean handled = super.dispatchTouchEvent(ev);
            requestDisallowInterceptTouchEvent(true);
            return handled;
        }

        super.onTouchEvent(ev);

        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            mDownX = ev.getX();
            mDownY = ev.getY();
            downTime = System.currentTimeMillis();
            break;
        case MotionEvent.ACTION_MOVE:
            /*
             //??
             if(Math.abs(ev.getX()-mDownX) > 0 ){
               return true;
            }else{
               return false;
            }
            */
            if (Math.abs(ev.getX() - mDownX) > 0) {
                return true;
            } else {
                return false;
            }

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            break;
        default:
            break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return true;
}

From source file:com.community.yuequ.player.CommonGestures.java

public boolean onTouchEvent(MotionEvent event) {
    if (mListener == null)
        return false;

    if (mTapGestureDetector.onTouchEvent(event))
        return true;

    if (event.getPointerCount() > 1) {
        try {/* w w  w  .j a v  a2s. c om*/
            if (mScaleDetector != null && mScaleDetector.onTouchEvent(event))
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    if (mDoubleTapGestureDetector.onTouchEvent(event))
        return true;

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        mListener.onGestureEnd();
        break;
    }

    return false;
}

From source file:com.xgleng.androiddemo.touchscreen.CommonGestures.java

public boolean onTouchEvent(MotionEvent event) {
    if (mListener == null)
        return false;

    if (mTapGestureDetector.onTouchEvent(event))
        return true;

    if (event.getPointerCount() > 1) {
        if (mScaleDetector != null && mScaleDetector.onTouchEvent(event)) {
            return true;
        }/*from   w  w  w  .  j  a v a  2s .com*/
    }

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        mIsFristScroll = true;
        if (mIsScrolling) {
            mListener.onGestureEnd();
            if (Math.abs(event.getY() - mDownY) > Math.abs(event.getX() - mDownX)) {
                mListener.onVerticalScrollEnd();
            } else {
                mListener.onHorizontalScrollEnd();
            }
        }
        break;
    }
    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();// www .  ja v a 2s  .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:cn.kylinhuang.play.view.CommonGestures.java

public boolean onTouchEvent(MotionEvent event) {
    if (mListener == null)
        return false;

    if (null == event)
        return false;

    if (mTapGestureDetector.onTouchEvent(event))
        return true;

    if (event.getPointerCount() > 1) {
        try {/*from   w  w w  . j  ava  2  s.  co m*/
            if (mScaleDetector != null && mScaleDetector.onTouchEvent(event))
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    if (mDoubleTapGestureDetector.onTouchEvent(event))
        return true;

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        mListener.onGestureEnd();
        break;
    }

    return true;
}

From source file:com.anysoftkeyboard.devicespecific.AskV8GestureDetector.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
    int singleFingerEventPointerId = mSingleFingerEventPointerId;

    //I want to keep track on the first finger (https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300)
    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN:
        if (ev.getPointerCount() == 1) {
            mSingleFingerEventPointerId = ev.getPointerId(0);
            singleFingerEventPointerId = mSingleFingerEventPointerId;
        }//from w  ww  .j av a 2s  . c o  m
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (ev.getPointerCount() == 1)
            mSingleFingerEventPointerId = NOT_A_POINTER_ID;
    }
    try {
        //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/26
        mScaleGestureDetector.onTouchEvent(ev);
    } catch (IllegalArgumentException e) {
        //I have nothing I can do here.
    } catch (ArrayIndexOutOfBoundsException e) {
        //I have nothing I can do here.
    }
    //I'm going to pass the event to the super, only if it is a single touch, and the event is for the first finger
    //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300
    if (ev.getPointerCount() == 1 && ev.getPointerId(0) == singleFingerEventPointerId)
        return super.onTouchEvent(ev);
    else
        return false;
}