List of usage examples for android.view MotionEvent ACTION_POINTER_UP
int ACTION_POINTER_UP
To view the source code for android.view MotionEvent ACTION_POINTER_UP.
Click Source Link
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);/*from w w w.ja v a 2 s . c o m*/ 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.coco.slidinguppanel.SlidingUpPanel.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // This method JUST determines whether we want to intercept the motion. // If we return true, onMotionEvent will be called and we do the actual // scrolling there. final int action = MotionEventCompat.getActionMasked(ev); // Always take care of the touch gesture being complete. if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { // Release the drag. DEBUG_LOG("Intercept done!"); endDrag();/*from www .j ava 2s .c om*/ return false; } // Nothing more to do here if we have decided whether or not we are dragging. if (action != MotionEvent.ACTION_DOWN) { if (mIsBeingDragged) { DEBUG_LOG("Intercept returning true!"); return true; } if (mIsUnableToDrag) { DEBUG_LOG("Intercept returning false!"); return false; } } // Check whether the user has moved far enough from his original down touch. switch (action) { case MotionEvent.ACTION_DOWN: { onTouchDown(ev, true); DEBUG_LOG("***Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged + " mIsUnableToDrag=" + mIsUnableToDrag); break; } case MotionEvent.ACTION_MOVE: { final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { // If we don't have a valid id, the touch down wasn't on content. break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); final float xDiff = Math.abs(x - mInitialMotionX); final float yDiff = Math.abs(y - mInitialMotionY); DEBUG_LOG("***Moved to " + x + "," + y + " diff=" + xDiff + "," + yDiff); onTouchMove(x, y, xDiff, yDiff, true); break; } case MotionEvent.ACTION_POINTER_UP: onTouchPointerUp(ev); break; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); // The only time we want to intercept motion events is if we are in the drag mode. return mIsBeingDragged; }
From source file:com.heneryh.aquanotes.ui.controllers.GraphsFragment.java
public boolean onTouch(View arg0, MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: // Start gesture firstFinger = new PointF(event.getX(), event.getY()); mode = ONE_FINGER_DRAG;//from ww w. j av a 2s . co m break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: //When the gesture ends, a thread is created to give inertia to the scrolling and zoom final Timer t = new Timer(); t.schedule(new TimerTask() { @Override public void run() { while (Math.abs(lastScrolling) > 1f || Math.abs(lastZooming - 1) < 1.01) { lastScrolling *= .8; //speed of scrolling damping scroll(lastScrolling); lastZooming += (1 - lastZooming) * .2; //speed of zooming damping zoom(lastZooming); checkBoundaries(); try { mySimpleXYPlot.postRedraw(); } catch (final InterruptedException e) { e.printStackTrace(); } // the thread lives until the scrolling and zooming are imperceptible } } }, 0); case MotionEvent.ACTION_POINTER_DOWN: // second finger distBetweenFingers = spacing(event); // the distance check is done to avoid false alarms if (distBetweenFingers > 5f) mode = TWO_FINGERS_DRAG; break; case MotionEvent.ACTION_MOVE: if (mode == ONE_FINGER_DRAG) { final PointF oldFirstFinger = firstFinger; firstFinger = new PointF(event.getX(), event.getY()); lastScrolling = oldFirstFinger.x - firstFinger.x; scroll(lastScrolling); lastZooming = (firstFinger.y - oldFirstFinger.y) / mySimpleXYPlot.getHeight(); if (lastZooming < 0) lastZooming = 1 / (1 - lastZooming); else lastZooming += 1; zoom(lastZooming); checkBoundaries(); mySimpleXYPlot.redraw(); } else if (mode == TWO_FINGERS_DRAG) { final float oldDist = distBetweenFingers; distBetweenFingers = spacing(event); lastZooming = oldDist / distBetweenFingers; zoom(lastZooming); checkBoundaries(); mySimpleXYPlot.redraw(); } break; } return true; }
From source file:net.osmand.plus.views.controls.DynamicListView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { if (singleTapDetector.onTouchEvent(event)) { if (tag != null) { tag.onClick();/*from www . ja v a2 s .co m*/ } touchEventsCancelled(); return super.onTouchEvent(event); } switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: if (!mCellIsMobile && mHoverCell == null) { // Find the view that the user pressed their finger down on. View v = findViewAtPositionWithDragIconTag(getRootView(), (int) event.getRawX(), (int) event.getRawY()); // If the view contains a tag set to "DragIcon" class, it means that the user wants to // reorder the list item. if ((v != null) && (v.getTag() != null) && (v.getTag() instanceof DragIcon)) { mDownX = (int) event.getX(); mDownY = (int) event.getY(); mActivePointerId = event.getPointerId(0); mTotalOffset = 0; tag = (DragIcon) v.getTag(); int position = pointToPosition(mDownX, mDownY); if (position != INVALID_POSITION) { Object item = getAdapter().getItem(position); if (mActiveItemsList == null || mActiveItemsList.contains(item)) { int itemNum = position - getFirstVisiblePosition(); itemsSwapped = false; View selectedView = getChildAt(itemNum); mMobileItemId = getAdapter().getItemId(position); mHoverCell = getAndAddHoverView(selectedView); selectedView.setVisibility(INVISIBLE); mCellIsMobile = true; updateNeighborViewsForID(mMobileItemId); if (dCallbacks != null) { dCallbacks.onItemSwapping(position); } } } } } break; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER_ID) { break; } int pointerIndex = event.findPointerIndex(mActivePointerId); mLastEventY = (int) event.getY(pointerIndex); int deltaY = mLastEventY - mDownY; if (mCellIsMobile && mHoverCell != null) { mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mHoverCellOriginalBounds.top + deltaY + mTotalOffset); mHoverCell.setBounds(mHoverCellCurrentBounds); invalidate(); handleCellSwitch(); mIsMobileScrolling = false; handleMobileCellScroll(); return false; } break; case MotionEvent.ACTION_UP: touchEventsEnded(); break; case MotionEvent.ACTION_CANCEL: touchEventsCancelled(); break; case MotionEvent.ACTION_POINTER_UP: /* If a multitouch event took place and the original touch dictating * the movement of the hover cell has ended, then the dragging event * ends and the hover cell is animated to its corresponding position * in the listview. */ pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int pointerId = event.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { touchEventsEnded(); } break; default: break; } return super.onTouchEvent(event); }
From source file:com.github.crvv.wubinput.wubi.dictionary.suggestions.SuggestionStripView.java
@Override public boolean onInterceptTouchEvent(final MotionEvent me) { if (!mMoreSuggestionsView.isShowingInParent()) { mLastX = (int) me.getX(); mLastY = (int) me.getY(); return mMoreSuggestionsSlidingDetector.onTouchEvent(me); }/*from w w w.j a v a 2 s .co m*/ final int action = me.getAction(); final int index = me.getActionIndex(); final int x = (int) me.getX(index); final int y = (int) me.getY(index); if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance || mOriginY - y >= mMoreSuggestionsModalTolerance) { // Decided to be in the sliding suggestion mode only when the touch point has been moved // upward. Further {@link MotionEvent}s will be delivered to // {@link #onTouchEvent(MotionEvent)}. mNeedsToTransformTouchEventToHoverEvent = AccessibilityUtils.getInstance().isTouchExplorationEnabled(); mIsDispatchingHoverEventToMoreSuggestions = false; return true; } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { // Decided to be in the modal input mode. mMoreSuggestionsView.adjustVerticalCorrectionForModalMode(); } return false; }
From source file:org.i_chera.wolfensteineditor.fragments.LevelFragment.java
@Override public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); if (mScrollLockCheck.isChecked()) { // We also need to avoid interfering with the left drawer // Cancel DOWN if too left. But don't cancel MOVE if too left if (v == mCentralContent && !mDrawerLayout.isDrawerVisible(Gravity.LEFT)) { int count = MotionEventCompat.getPointerCount(event); for (int k = 0; k < count; ++k) { if (action != MotionEvent.ACTION_DOWN && action != MotionEventCompat.ACTION_POINTER_DOWN || MotionEventCompat.getX(event, k) >= mTileSize) { hitTileOnView(event, k, false); }//from w w w . j ava 2 s. c om } return true; } return false; } if (v == mVerticalScroll) { // LOL trickery needed to scroll the below horiz view while this is // getting operated on if (mVerticalScroll.isScrollable() && mDoNotPropagateScroll == false) { mHorizontalScroll.setScrollingEnabled(true); mHorizontalScroll.dispatchTouchEvent(event); mHorizontalScroll.setScrollingEnabled(false); } if (action == MotionEvent.ACTION_DOWN || action == MotionEventCompat.ACTION_POINTER_DOWN) { mPressDown = true; //return true; } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { if (mPressDown) { hitTileOnView(event, (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT, true); } } return false; } return false; }
From source file:org.uoyabause.android.PadButton.java
public boolean onTouch(View v, MotionEvent event) { int action = event.getActionMasked(); int touchCount = event.getPointerCount(); int pointerIndex = event.getActionIndex(); int pointerId = event.getPointerId(pointerIndex); int posx = (int) event.getX(pointerIndex); int posy = (int) event.getY(pointerIndex); float hitsize = 15.0f * wscale * base_scale; RectF hittest = new RectF((int) (posx - hitsize), (int) (posy - hitsize), (int) (posx + hitsize), (int) (posy + hitsize)); switch (action) { case MotionEvent.ACTION_DOWN: for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].intersects(hittest)) { buttons[btnindex].On(pointerId); }//from w w w . j a v a 2s . co m } if (_pad_mode == 1) { updatePad(hittest, posx, posy, pointerId); } break; case MotionEvent.ACTION_POINTER_DOWN: for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].intersects(hittest)) { buttons[btnindex].On(pointerId); } } if (_pad_mode == 1) { updatePad(hittest, posx, posy, pointerId); } break; case MotionEvent.ACTION_POINTER_UP: for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].intersects(hittest)) { buttons[btnindex].Off(); } } if (_pad_mode == 1) { releasePad(pointerId); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].intersects(hittest)) { buttons[btnindex].Off(); } } if (_pad_mode == 1) { releasePad(pointerId); } break; case MotionEvent.ACTION_MOVE: for (int index = 0; index < touchCount; index++) { int eventID2 = event.getPointerId(index); float x2 = event.getX(index); float y2 = event.getY(index); RectF hittest2 = new RectF((int) (x2 - hitsize), (int) (y2 - hitsize), (int) (x2 + hitsize), (int) (y2 + hitsize)); for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (eventID2 == buttons[btnindex].getPointId()) { if (buttons[btnindex].intersects(hittest2) == false) { buttons[btnindex].Off(); } } else if (buttons[btnindex].intersects(hittest2)) { buttons[btnindex].On(eventID2); } } if (_pad_mode == 1) { updatePad(hittest2, (int) x2, (int) y2, eventID2); } } break; } if (!testmode) { if (_pad_mode == 0) { for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].isOn()) { YabauseRunnable.press(btnindex, 0); } else { YabauseRunnable.release(btnindex, 0); } } } else { for (int btnindex = PadEvent.BUTTON_RIGHT_TRIGGER; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].isOn()) { YabauseRunnable.press(btnindex, 0); } else { YabauseRunnable.release(btnindex, 0); } } } } if (testmode) { status = ""; status += "START:"; if (buttons[PadEvent.BUTTON_START].isOn()) status += "ON "; else status += "OFF "; status += "\nUP:"; if (buttons[PadEvent.BUTTON_UP].isOn()) status += "ON "; else status += "OFF "; status += "DOWN:"; if (buttons[PadEvent.BUTTON_DOWN].isOn()) status += "ON "; else status += "OFF "; status += "LEFT:"; if (buttons[PadEvent.BUTTON_LEFT].isOn()) status += "ON "; else status += "OFF "; status += "RIGHT:"; if (buttons[PadEvent.BUTTON_RIGHT].isOn()) status += "ON "; else status += "OFF "; status += "\nA:"; if (buttons[PadEvent.BUTTON_A].isOn()) status += "ON "; else status += "OFF "; status += "B:"; if (buttons[PadEvent.BUTTON_B].isOn()) status += "ON "; else status += "OFF "; status += "C:"; if (buttons[PadEvent.BUTTON_C].isOn()) status += "ON "; else status += "OFF "; status += "\nX:"; if (buttons[PadEvent.BUTTON_X].isOn()) status += "ON "; else status += "OFF "; status += "Y:"; if (buttons[PadEvent.BUTTON_Y].isOn()) status += "ON "; else status += "OFF "; status += "Z:"; if (buttons[PadEvent.BUTTON_Z].isOn()) status += "ON "; else status += "OFF "; status += "\nLT:"; if (buttons[PadEvent.BUTTON_LEFT_TRIGGER].isOn()) status += "ON "; else status += "OFF "; status += "RT:"; if (buttons[PadEvent.BUTTON_RIGHT_TRIGGER].isOn()) status += "ON "; else status += "OFF "; status += "\nAX:"; if (_analog_pad.isOn()) status += "ON " + _axi_x; else status += "OFF " + _axi_x; status += "AY:"; if (_analog_pad.isOn()) status += "ON " + _axi_y; else status += "OFF " + _axi_y; } if ((listener != null)) { listener.onPad(null); } return true; }
From source file:org.cocos2dx.lib.TextInputWraper.java
private void dumpEvent(MotionEvent event) { String names[] = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" }; StringBuilder sb = new StringBuilder(); int action = event.getAction(); int actionCode = action & MotionEvent.ACTION_MASK; sb.append("event ACTION_").append(names[actionCode]); if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) { sb.append("(pid ").append(action >> MotionEvent.ACTION_POINTER_ID_SHIFT); sb.append(")"); }//from w ww .j av a2s. co m sb.append("["); for (int i = 0; i < event.getPointerCount(); i++) { sb.append("#").append(i); sb.append("(pid ").append(event.getPointerId(i)); sb.append(")=").append((int) event.getX(i)); sb.append(",").append((int) event.getY(i)); if (i + 1 < event.getPointerCount()) sb.append(";"); } sb.append("]"); Log.d(TAG, sb.toString()); }
From source file:com.androidinspain.deskclock.alarms.AlarmActivity.java
@Override public boolean onTouch(View view, MotionEvent event) { if (mAlarmHandled) { LOGGER.v("onTouch ignored: %s", event); return false; }//from w ww . ja v a2s.c o m final int action = event.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { LOGGER.v("onTouch started: %s", event); // Track the pointer that initiated the touch sequence. mInitialPointerIndex = event.getPointerId(event.getActionIndex()); // Stop the pulse, allowing the last pulse to finish. mPulseAnimator.setRepeatCount(0); } else if (action == MotionEvent.ACTION_CANCEL) { LOGGER.v("onTouch canceled: %s", event); // Clear the pointer index. mInitialPointerIndex = MotionEvent.INVALID_POINTER_ID; // Reset everything. resetAnimations(); } final int actionIndex = event.getActionIndex(); if (mInitialPointerIndex == MotionEvent.INVALID_POINTER_ID || mInitialPointerIndex != event.getPointerId(actionIndex)) { // Ignore any pointers other than the initial one, bail early. return true; } final int[] contentLocation = { 0, 0 }; mContentView.getLocationOnScreen(contentLocation); final float x = event.getRawX() - contentLocation[0]; final float y = event.getRawY() - contentLocation[1]; final int alarmLeft = mAlarmButton.getLeft() + mAlarmButton.getPaddingLeft(); final int alarmRight = mAlarmButton.getRight() - mAlarmButton.getPaddingRight(); final float snoozeFraction, dismissFraction; if (mContentView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { snoozeFraction = getFraction(alarmRight, mSnoozeButton.getLeft(), x); dismissFraction = getFraction(alarmLeft, mDismissButton.getRight(), x); } else { snoozeFraction = getFraction(alarmLeft, mSnoozeButton.getRight(), x); dismissFraction = getFraction(alarmRight, mDismissButton.getLeft(), x); } setAnimatedFractions(snoozeFraction, dismissFraction); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { LOGGER.v("onTouch ended: %s", event); mInitialPointerIndex = MotionEvent.INVALID_POINTER_ID; if (snoozeFraction == 1.0f) { snooze(); } else if (dismissFraction == 1.0f) { dismiss(); } else { if (snoozeFraction > 0.0f || dismissFraction > 0.0f) { // Animate back to the initial state. AnimatorUtils.reverse(mAlarmAnimator, mSnoozeAnimator, mDismissAnimator); } else if (mAlarmButton.getTop() <= y && y <= mAlarmButton.getBottom()) { // User touched the alarm button, hint the dismiss action. hintDismiss(); } // Restart the pulse. mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE); if (!mPulseAnimator.isStarted()) { mPulseAnimator.start(); } } } return true; }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripView.java
@Override public boolean onInterceptTouchEvent(final MotionEvent me) { if (mStripVisibilityGroup.isShowingImportantNoticeStrip()) { return false; }//from w w w. ja v a2 s . c om // Detecting sliding up finger to show {@link MoreSuggestionsView}. if (!mMoreSuggestionsView.isShowingInParent()) { mLastX = (int) me.getX(); mLastY = (int) me.getY(); return mMoreSuggestionsSlidingDetector.onTouchEvent(me); } if (mMoreSuggestionsView.isInModalMode()) { return false; } final int action = me.getAction(); final int index = me.getActionIndex(); final int x = (int) me.getX(index); final int y = (int) me.getY(index); if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance || mOriginY - y >= mMoreSuggestionsModalTolerance) { // Decided to be in the sliding suggestion mode only when the touch point has been moved // upward. Further {@link MotionEvent}s will be delivered to // {@link #onTouchEvent(MotionEvent)}. mNeedsToTransformTouchEventToHoverEvent = AccessibilityUtils.getInstance().isTouchExplorationEnabled(); mIsDispatchingHoverEventToMoreSuggestions = false; return true; } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { // Decided to be in the modal input mode. mMoreSuggestionsView.setModalMode(); } return false; }