Example usage for android.view MotionEvent ACTION_POINTER_UP

List of usage examples for android.view MotionEvent ACTION_POINTER_UP

Introduction

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

Prototype

int ACTION_POINTER_UP

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

Click Source Link

Document

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

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";
    }//  www.j  ava2  s . co m
    return "UNKNOWN";
}

From source file:Main.java

/**
 * Gets the name of an action.//from  ww  w.  j  av  a2 s .  c  o  m
 * 
 * @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) {
    // ?//from  w w  w.  j  av  a 2s  . c  om
    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;//ww w  . ja  v a 2s .c o  m
    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:danonino.danonino_the_game.Core.Labels.PowerUp.java

public int onTouch(MotionEvent event) {
    int index = MotionEventCompat.getActionIndex(event);
    int x;/*w w w.  jav a  2 s .c  o m*/
    int y;

    if (event.getPointerCount() > 1) {
        // The coordinates of the current screen contact, relative to
        // the responding View or Activity.
        x = (int) MotionEventCompat.getX(event, index);
        y = (int) MotionEventCompat.getY(event, index);

    } else {
        // Single touch event
        x = (int) MotionEventCompat.getX(event, index);
        y = (int) MotionEventCompat.getY(event, index);
    }

    if (this.usePowerUpBtn.btn_rect.contains(x, y) || ((event.getActionMasked() == MotionEvent.ACTION_UP
            || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) && usePowerUpBtnPressed)) {
        this.usePowerUpBtnPressed = !this.usePowerUpBtnPressed;
        this.usePowerUpBtn.onTouch(event);
        return 1;
    }
    return 0;
}

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;
    }//w  w  w .  java 2  s. c o m

    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.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();/*  www  .j  ava 2  s.  co 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.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  w  w  .j a  v a2s  .  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.windnow.StationPicActivity.java

@SuppressLint("NewApi")
@Override//from  w w w  .  java2 s  . c  o  m
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:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java

private void onTouchActivePointer(int action, MotionEvent ev) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = ev.getPointerId(0);
        break;/*from ww w . j a  va  2s . co  m*/
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mActivePointerId = INVALID_POINTER_ID;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
            mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
            mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
        }

        break;
    }

    mActivePointerIndex = MotionEventCompat.findPointerIndex(ev,
            mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}