List of usage examples for android.view MotionEvent getPointerId
public final int getPointerId(int pointerIndex)
From source file:study.com.s_sxl.carelib.pullRefreshView.layout.FlingLayout.java
/******************************************************************/ @Override/*from w ww .jav a2 s . c o m*/ public boolean dispatchTouchEvent(MotionEvent ev) { if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) { float moveY = getMoveY(); int pointerCount = ev.getPointerCount(); int pointerIndex = ev.getActionIndex(); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mPointerId = ev.getPointerId(pointerIndex); float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); tempY = downY = y; tempX = downX = x; tempStateType = SCROLL_STATE_TOUCH_SCROLL; if (moveY != 0) { return true; } break; case MotionEvent.ACTION_POINTER_DOWN: mPointerId = ev.getPointerId(pointerIndex); tempX = ev.getX(pointerIndex); tempY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: pointerIndex = ev.findPointerIndex(mPointerId); float mx; float my; if (pointerCount > pointerIndex && pointerIndex >= 0) { mx = ev.getX(pointerIndex); my = ev.getY(pointerIndex); } else { mx = ev.getX(); my = ev.getY(); } //????? int dataX = (int) (mx - tempX); int dataY = (int) (my - tempY); tempX = mx; tempY = my; if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) { isScrolling = true; if (moveY == 0) { // 0,0 //?? if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) { moveBy(dataY); return true; } } else { //?0,0 ev.setAction(MotionEvent.ACTION_CANCEL);//? if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) { //0,0 ev.setAction(MotionEvent.ACTION_DOWN); moveTo(0); } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) { //?? if (maxDistance == 0 || Math.abs(moveY) < maxDistance) { int ps = 0; int hDataY = dataY / 2; if (maxDistance == 0) { ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY; } else { ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY; } moveBy(ps + dataY); } else if (moveY > maxDistance) { moveTo(maxDistance); } else if (moveY < -maxDistance) { moveTo(-maxDistance); } } else { moveBy(dataY); } } } else { ev.setLocation(mx, downY); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: startFling(); isScrolling = false; break; case MotionEvent.ACTION_POINTER_UP: // ?? int pointerIdLeave = ev.getPointerId(pointerIndex); if (mPointerId == pointerIdLeave) { // ??????VelocityTracker int reIndex = pointerIndex == 0 ? 1 : 0; mPointerId = ev.getPointerId(reIndex); // ? tempY = ev.getY(reIndex); } } return super.dispatchTouchEvent(ev) || isScrolling; } else { return super.dispatchTouchEvent(ev); } }
From source file:com.leap.mini.widget.pullrefresh.base.layout.FlingLayout.java
/******************************************************************/ @Override//from ww w . j a v a2s . c o m public boolean dispatchTouchEvent(MotionEvent ev) { if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) { float moveY = getMoveY(); int pointerCount = ev.getPointerCount(); int pointerIndex = ev.getActionIndex(); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mPointerId = ev.getPointerId(pointerIndex); float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); tepmY = downY = y; tepmX = downX = x; tempStateType = SCROLL_STATE_TOUCH_SCROLL; if (moveY != 0) { return true; } break; case MotionEvent.ACTION_POINTER_DOWN: mPointerId = ev.getPointerId(pointerIndex); tepmX = ev.getX(pointerIndex); tepmY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: pointerIndex = ev.findPointerIndex(mPointerId); float mx; float my; if (pointerCount > pointerIndex && pointerIndex >= 0) { mx = ev.getX(pointerIndex); my = ev.getY(pointerIndex); } else { mx = ev.getX(); my = ev.getY(); } // ????? int dataX = (int) (mx - tepmX); int dataY = (int) (my - tepmY); tepmX = mx; tepmY = my; if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) { isScrolling = true; if (moveY == 0) { // 0,0 // ?? if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) { moveBy(dataY); return true; } } else { // ?0,0 ev.setAction(MotionEvent.ACTION_CANCEL);// ? if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) { // 0,0 ev.setAction(MotionEvent.ACTION_DOWN); moveTo(0); } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) { // ?? if (maxDistance == 0 || Math.abs(moveY) < maxDistance) { int ps = 0; int hDataY = dataY / 2; if (maxDistance == 0) { ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY; } else { ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY; } moveBy(ps + dataY); } else if (moveY > maxDistance) { moveTo(maxDistance); } else if (moveY < -maxDistance) { moveTo(-maxDistance); } } else { moveBy(dataY); } } } else { ev.setLocation(mx, downY); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: startFling(); isScrolling = false; break; case MotionEvent.ACTION_POINTER_UP: // ?? int pointerIdLeave = ev.getPointerId(pointerIndex); if (mPointerId == pointerIdLeave) { // ??????VelocityTracker int reIndex = pointerIndex == 0 ? 1 : 0; mPointerId = ev.getPointerId(reIndex); // ? tepmY = ev.getY(reIndex); } } return super.dispatchTouchEvent(ev) || isScrolling; } else { return super.dispatchTouchEvent(ev); } }
From source file:com.ybao.pullrefreshview.layout.FlingLayout.java
/******************************************************************/ @Override/*from w ww. j av a 2 s. c o m*/ public boolean dispatchTouchEvent(MotionEvent ev) { if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) { float moveY = getMoveY(); int pointerCount = ev.getPointerCount(); int pointerIndex = ev.getActionIndex(); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mPointerId = ev.getPointerId(pointerIndex); float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); tepmY = downY = y; tepmX = downX = x; tempStateType = SCROLL_STATE_TOUCH_SCROLL; if (moveY != 0) { return true; } break; case MotionEvent.ACTION_POINTER_DOWN: mPointerId = ev.getPointerId(pointerIndex); tepmX = ev.getX(pointerIndex); tepmY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: pointerIndex = ev.findPointerIndex(mPointerId); float mx; float my; if (pointerCount > pointerIndex && pointerIndex >= 0) { mx = ev.getX(pointerIndex); my = ev.getY(pointerIndex); } else { mx = ev.getX(); my = ev.getY(); } //????? int dataX = (int) (mx - tepmX); int dataY = (int) (my - tepmY); tepmX = mx; tepmY = my; if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) { isScrolling = true; if (moveY == 0) { // 0,0 //?? if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) { moveBy(dataY); return true; } } else { //?0,0 ev.setAction(MotionEvent.ACTION_CANCEL);//? if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) { //0,0 ev.setAction(MotionEvent.ACTION_DOWN); moveTo(0); } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) { //?? if (maxDistance == 0 || Math.abs(moveY) < maxDistance) { int ps = 0; int hDataY = dataY / 2; if (maxDistance == 0) { ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY; } else { ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY; } moveBy(ps + dataY); } else if (moveY > maxDistance) { moveTo(maxDistance); } else if (moveY < -maxDistance) { moveTo(-maxDistance); } } else { moveBy(dataY); } } } else { ev.setLocation(mx, downY); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: startFling(); isScrolling = false; break; case MotionEvent.ACTION_POINTER_UP: // ?? int pointerIdLeave = ev.getPointerId(pointerIndex); if (mPointerId == pointerIdLeave) { // ??????VelocityTracker int reIndex = pointerIndex == 0 ? 1 : 0; mPointerId = ev.getPointerId(reIndex); // ? tepmY = ev.getY(reIndex); } } return super.dispatchTouchEvent(ev) || isScrolling; } else { return super.dispatchTouchEvent(ev); } }
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 va 2 s . 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: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();/*from ww w. j a v a2s . c o m*/ 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.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 w w . j ava 2s.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.cocarechina.pullrefreshview.layout.FlingLayout.java
/******************************************************************/ @Override//w w w. j a va 2s. c o m public boolean dispatchTouchEvent(MotionEvent ev) { if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) { float moveY = getMoveY(); int pointerCount = ev.getPointerCount(); int pointerIndex = ev.getActionIndex(); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mPointerId = ev.getPointerId(pointerIndex); float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); tepmY = downY = y; tepmX = downX = x; tempStateType = SCROLL_STATE_TOUCH_SCROLL; if (moveY != 0) { return true; } lastY = ev.getY(); Log.v("lastY", moveY + ""); break; case MotionEvent.ACTION_POINTER_DOWN: mPointerId = ev.getPointerId(pointerIndex); tepmX = ev.getX(pointerIndex); tepmY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: pointerIndex = ev.findPointerIndex(mPointerId); float mx; float my; if (pointerCount > pointerIndex && pointerIndex >= 0) { mx = ev.getX(pointerIndex); my = ev.getY(pointerIndex); } else { mx = ev.getX(); my = ev.getY(); } //????? int dataX = (int) (mx - tepmX); int dataY = (int) (my - tepmY); tepmX = mx; tepmY = my; if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) { isScrolling = true; if (moveY == 0) { // 0,0 //?? if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) { moveBy(dataY); return true; } } else { //?0,0 ev.setAction(MotionEvent.ACTION_CANCEL);//? if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) { //0,0 ev.setAction(MotionEvent.ACTION_DOWN); moveTo(0); } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) { //?? if (maxDistance == 0 || Math.abs(moveY) < maxDistance) { int ps = 0; int hDataY = dataY / 2; if (maxDistance == 0) { ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY; } else { ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY; } moveBy(ps + dataY); } else if (moveY > maxDistance) { moveTo(maxDistance); } else if (moveY < -maxDistance) { moveTo(-maxDistance); } } else { moveBy(dataY); } } } else { ev.setLocation(mx, downY); } Log.v("flingLayout", "ev.getY()" + ev.getY() + " --- lastY " + lastY); if (ev.getY() - lastY > 5) { if (monScrollHeadListener != null) { monScrollHeadListener.onScrollBottom(); } } else if (ev.getY() - lastY < -10) { if (monScrollHeadListener != null) { monScrollHeadListener.onScrollTop(); } } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: startFling(); isScrolling = false; break; case MotionEvent.ACTION_POINTER_UP: // ?? int pointerIdLeave = ev.getPointerId(pointerIndex); if (mPointerId == pointerIdLeave) { // ??????VelocityTracker int reIndex = pointerIndex == 0 ? 1 : 0; mPointerId = ev.getPointerId(reIndex); // ? tepmY = ev.getY(reIndex); } } return super.dispatchTouchEvent(ev) || isScrolling; } else { return super.dispatchTouchEvent(ev); } }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
/** * {@inheritDoc}//from w ww . j av a2 s . c o m */ @Override public boolean onTouchEvent(final MotionEvent event) { final int action = event.getActionMasked(); final int index = event.getActionIndex(); final int pointerId = event.getPointerId(index); switch (action) { case MotionEvent.ACTION_DOWN: // Initialize velocity tracker if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else { mVelocityTracker.clear(); } mVelocityTracker.addMovement(event); mScroller.forceFinished(true); mState = STATE_INITIALIZE; mInitialTouchOffset = mCurrentOffset; mInitialTouchX = event.getX(); mInitialTouchY = event.getY(); return true; case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(event); float diffX = event.getX() - mInitialTouchX; float diffY = event.getY() - mInitialTouchY; if (Math.abs(diffX) > mTouchSlop || mState >= STATE_MOVING) { mCurrentOffset = mInitialTouchOffset + diffX; if (mCurrentOffset < 0) { onOverScroll(); mCurrentOffset = 0; } else if (mCurrentOffset > mMaxOffset) { onOverScroll(); mCurrentOffset = mMaxOffset; } mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity); mState = STATE_MOVING; ViewCompat.postInvalidateOnAnimation(this); } else if (Math.abs(diffY) > mTouchSlop && mState < STATE_MOVING) { return false; } return true; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mState >= STATE_MOVING) { final int velocity = (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, pointerId); mScroller.forceFinished(true); mState = STATE_FLINGING; mScroller.fling((int) mCurrentOffset, 0, velocity, 0, 0, (int) mMaxOffset, 0, 0); ViewCompat.postInvalidateOnAnimation(this); } else { // Reset scrolling state mState = STATE_IDLE; } return true; } return false; }
From source file:au.gov.ga.worldwind.androidremote.client.Remote.java
@Override public boolean onTouchEvent(MotionEvent event) { if (controlling) { velocityTracker.addMovement(event); velocityTracker.computeCurrentVelocity(1); boolean down = event.getActionMasked() == MotionEvent.ACTION_DOWN || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN; boolean up = event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP; Finger[] fingers = new Finger[event.getPointerCount()]; for (int i = 0; i < event.getPointerCount(); i++) { fingers[i] = new Finger(event.getPointerId(i), event.getX(i), event.getY(i), velocityTracker.getXVelocity(i), velocityTracker.getYVelocity(i), !(event.getActionIndex() == i && up)); }/* w w w . j av a 2 s .c o m*/ FingerMessage<?> message = up ? new UpMessage(fingers) : down ? new DownMessage(fingers) : new MoveMessage(fingers); communicator.sendMessage(message); } return super.onTouchEvent(event); }
From source file:havidarou.com.appgestosfoto.MainActivity.java
@Override public boolean onTouchEvent(MotionEvent event) { // Get the event in order to switch between the options int action = MotionEventCompat.getActionMasked(event); a1.getLocationInWindow(p1);//www . j av a 2 s . c o m a2.getLocationInWindow(p2); a3.getLocationInWindow(p3); b1.getLocationInWindow(p4); b2.getLocationInWindow(p5); b3.getLocationInWindow(p6); c1.getLocationInWindow(p7); c2.getLocationInWindow(p8); c3.getLocationInWindow(p9); switch (action) { // If the movement has just begun case (MotionEvent.ACTION_DOWN): helper.setText("Do a recognized pattern"); // Get the initial point initialX = event.getX(event.getPointerId(0)); initialY = event.getY(event.getPointerId(0)); Log.d("X:", Float.toString(initialX)); Log.d("Y:", Float.toString(initialY)); break; // If the user is moving across the screen case (MotionEvent.ACTION_MOVE): // Get the current point currentX = event.getX(event.getPointerId(0)); currentY = event.getY(event.getPointerId(0)); // Depending on the current position and where are we moving we add to the current movement if ((currentX > p1[0] - 60 && currentX < p1[0] + 70) && (currentY > p1[1] - 60) && (currentY < p1[1] + 70) && (movement.get(movement.size() - 1) != 1)) { Log.d("Movement:", Float.toString(1)); movement.add(1); } else if ((currentX > p2[0] - 60 && currentX < p2[0] + 70) && (currentY > p2[1] - 60) && (currentY < p2[1] + 70) && (movement.get(movement.size() - 1) != 2)) { Log.d("Movement:", Float.toString(2)); movement.add(2); } else if ((currentX > p3[0] - 60 && currentX < p3[0] + 70) && (currentY > p3[1] - 60) && (currentY < p3[1] + 70) && (movement.get(movement.size() - 1) != 3)) { Log.d("Movement:", Float.toString(3)); movement.add(3); } else if ((currentX > p4[0] - 60 && currentX < p4[0] + 70) && (currentY > p4[1] - 60) && (currentY < p4[1] + 70) && (movement.get(movement.size() - 1) != 4)) { Log.d("Movement:", Float.toString(4)); movement.add(4); } else if ((currentX > p5[0] - 60 && currentX < p5[0] + 70) && (currentY > p5[1] - 60) && (currentY < p5[1] + 70) && (movement.get(movement.size() - 1) != 5)) { Log.d("Movement:", Float.toString(5)); movement.add(5); } else if ((currentX > p6[0] - 60 && currentX < p6[0] + 70) && (currentY > p6[1] - 60) && (currentY < p6[1] + 70) && (movement.get(movement.size() - 1) != 6)) { Log.d("Movement:", Float.toString(6)); movement.add(6); } else if ((currentX > p7[0] - 60 && currentX < p7[0] + 70) && (currentY > p7[1] - 60) && (currentY < p7[1] + 70) && (movement.get(movement.size() - 1) != 7)) { Log.d("Movement:", Float.toString(7)); movement.add(7); } else if ((currentX > p8[0] - 50 && currentX < p8[0] + 70) && (currentY > p8[1] - 60) && (currentY < p8[1] + 70) && (movement.get(movement.size() - 1) != 8)) { Log.d("Movement:", Float.toString(8)); movement.add(8); } else if ((currentX > p9[0] - 60 && currentX < p9[0] + 70) && (currentY > p9[1] - 60) && (currentY < p9[1] + 70) && (movement.get(movement.size() - 1) != 9)) { Log.d("Movement:", Float.toString(9)); movement.add(9); } break; // If the user stops touching the screen then we check if the pattern matches with any of the recognized ones case (MotionEvent.ACTION_UP): if (movement.equals(zMovement) || movement.equals(lMovement) || movement.equals(mMovement) || movement.equals(nMovement) || movement.equals(vMovement)) { rightPattern = true; helper.setText("Recognized pattern"); view.setVisibility(View.VISIBLE); a1.setVisibility(View.INVISIBLE); a2.setVisibility(View.INVISIBLE); a3.setVisibility(View.INVISIBLE); b1.setVisibility(View.INVISIBLE); b2.setVisibility(View.INVISIBLE); b3.setVisibility(View.INVISIBLE); c1.setVisibility(View.INVISIBLE); c2.setVisibility(View.INVISIBLE); c3.setVisibility(View.INVISIBLE); try { camera.setPreviewDisplay(view.getHolder()); // Associate the holder with the preview } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.setDisplayOrientation(90); camera.startPreview(); // A recognized pattern has been done, now we start the timer startTimer(view); } else { helper.setText("Unrecognized pattern"); } movement.clear(); movement.add(0); break; } return true; }