@Override public boolean onTouch(View v, MotionEvent event) { if (!activated) return true; if (!canSend()) return true; int viewWidth = mView.getWidth(); int viewHeight = mView.getHeight(); final int pointerCount = event.getPointerCount(); Finger[] newFingers = new Finger[pointerCount]; for (int p = 0; p < pointerCount; p++) { event.getPointerCoords(p, pc); Finger f = new Finger(); float x = (float) pc.x / (float) viewWidth; float y = (float) pc.y / (float) viewHeight; f.setX(x); f.setY(y); f.setColor(randomColor); newFingers[p] = f; } FingerMessage msg = new FingerMessage(); msg.setClientUUID(clientUUIDString); msg.setFingers(newFingers); msg.setColor(randomColor); String json = gson.toJson(msg); this.channel.publish(json.getBytes()); lastSentTimestamp = System.currentTimeMillis(); return true; }
@Override public boolean onTouchEventInternal(MotionEvent e) { final int action = e.getActionMasked(); // This path mimics the Android long press detection while still allowing // other touch events to come through the gesture detector. if (!mUseDefaultLongPress) { if (e.getPointerCount() > 1) { // If there's more than one pointer ignore the long press. if (mLongPressRunnable.isPending()) { cancelLongPress(); } } else if (action == MotionEvent.ACTION_DOWN) { // If there was a pending event kill it off. if (mLongPressRunnable.isPending()) { cancelLongPress(); } mLongPressRunnable.init(e); mLongPressHandler.postDelayed(mLongPressRunnable, mLongPressTimeoutMs); } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { cancelLongPress(); } else if (mLongPressRunnable.isPending()) { // Allow for a little bit of touch slop. MotionEvent initialEvent = mLongPressRunnable.getInitialEvent(); float distanceX = initialEvent.getX() - e.getX(); float distanceY = initialEvent.getY() - e.getY(); float distance = distanceX * distanceX + distanceY * distanceY; // Save a square root here by comparing to squared touch slop if (distance > mScaledTouchSlop * mScaledTouchSlop) { cancelLongPress(); } } } // Sends the pinch event if two or more fingers touch the screen. According to test // Android handles the fingers order pretty consistently so always requesting // index 0 and 1 works here. // This might need some rework if 3 fingers event are supported. if (e.getPointerCount() > 1) { mHandler.onPinch( e.getX(0) * mPxToDp, e.getY(0) * mPxToDp, e.getX(1) * mPxToDp, e.getY(1) * mPxToDp, action == MotionEvent.ACTION_POINTER_DOWN); mDetector.setIsLongpressEnabled(false); mSingleInput = false; } else { mDetector.setIsLongpressEnabled(mUseDefaultLongPress); mSingleInput = true; } mDetector.onTouchEvent(e); // Propagate the up event after any gesture events. if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { mHandler.onUpOrCancel(); } return true; }
/** Show an event in the LogCat view, for debugging */ @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.ECLAIR) @SuppressLint("NewApi") 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(")"); } 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("]"); }
@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)); } FingerMessage<?> message = up ? new UpMessage(fingers) : down ? new DownMessage(fingers) : new MoveMessage(fingers); communicator.sendMessage(message); } return super.onTouchEvent(event); }
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // Ignore onScroll for a small time period after a double finger gesture has occured // Depending on how fingers are picked up after a double finger gesture, there could be a // residual "single" // finger pan which could also result in a fling. This check will ignore that. long time = e2.getEventTime(); if (((time - mLastDoubleGestureTime) < SCROLL_TIME_THRESHOLD) && e2.getPointerCount() == 1) { return false; } if (mShoveHandled) { return false; } float x = 0, y = 0; int n = e2.getPointerCount(); for (int i = 0; i < n; i++) { x += e2.getX(i) / n; y += e2.getY(i) / n; } handlePanGesture(x + distanceX, y + distanceY, x, y); return true; }
/** Show an event in the LogCat view, for debugging */ 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(")"); } 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("Touch Events ---------", sb.toString()); }
// @Override public boolean dispatchTouchEvent (MotionEvent event) { public boolean gotTouchEvent(MotionEvent event) { super.onTouchEvent(event); int evcount = event.getPointerCount(); if (evcount == 0) return true; int[] arr = new int[event.getPointerCount() * 3]; for (int i = 0; i < event.getPointerCount(); i++) { arr[i * 3 + 0] = (int) event.getPointerId(i); arr[i * 3 + 1] = (int) event.getX(i); arr[i * 3 + 2] = (int) event.getY(i); } // System.out.printf("gaction: %d\n",event.getAction()); switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { GodotLib.touch(0, 0, evcount, arr); // System.out.printf("action down at: %f,%f\n", event.getX(),event.getY()); } break; case MotionEvent.ACTION_MOVE: { GodotLib.touch(1, 0, evcount, arr); // for(int i=0;i<event.getPointerCount();i++) { // System.out.printf("%d - moved to: %f,%f\n",i, event.getX(i),event.getY(i)); // } } break; case MotionEvent.ACTION_POINTER_UP: { int pointer_idx = event.getActionIndex(); GodotLib.touch(4, pointer_idx, evcount, arr); // System.out.printf("%d - s.up at: %f,%f\n",pointer_idx, // event.getX(pointer_idx),event.getY(pointer_idx)); } break; case MotionEvent.ACTION_POINTER_DOWN: { int pointer_idx = event.getActionIndex(); GodotLib.touch(3, pointer_idx, evcount, arr); // System.out.printf("%d - s.down at: %f,%f\n",pointer_idx, // event.getX(pointer_idx),event.getY(pointer_idx)); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { GodotLib.touch(2, 0, evcount, arr); // for(int i=0;i<event.getPointerCount();i++) { // System.out.printf("%d - up! %f,%f\n",i, event.getX(i),event.getY(i)); // } } break; } return true; }
@Override public boolean onTouch(View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (fState == STATE.INIT && event.getPointerCount() == 1) { fState = STATE.WAIT; fPreviousEvents.add( new DrawManager.MyMotionEvent(event.getAction(), event.getX(), event.getY())); } if (fState == STATE.INIT && event.getPointerCount() == 2) { fState = STATE.ZOOM_PAN; initZoom(event); } break; case MotionEvent.ACTION_MOVE: if (fState == STATE.WAIT && event.getPointerCount() == 1) { if (trueMove(event)) { fState = STATE.DRAW; for (DrawManager.MyMotionEvent previousEvent : fPreviousEvents) { fDelegate.onTouch(view, previousEvent); } fDelegate.onTouch(view, event); fPreviousEvents.clear(); } else { fPreviousEvents.add( new DrawManager.MyMotionEvent(event.getAction(), event.getX(), event.getY())); } } else if (fState == STATE.WAIT && event.getPointerCount() == 2) { fState = STATE.ZOOM_PAN; // init zoom pan initZoom(event); } else if (fState == STATE.ZOOM_PAN) { // update zoom//pan updateZoomAndPan(event); } else if (fState == STATE.DRAW) { fDelegate.onTouch(view, event); } break; case MotionEvent.ACTION_UP: if (fState == STATE.ZOOM_PAN) { // finish zoom closeAction(); } else if (fState == STATE.WAIT) { for (DrawManager.MyMotionEvent previousEvent : fPreviousEvents) { fDelegate.onTouch(view, previousEvent); } fPreviousEvents.clear(); fDelegate.onTouch(view, event); } else if (fState == STATE.DRAW && event.getPointerCount() == 1) { fDelegate.onTouch(view, event); } fState = STATE.INIT; fPreviousEvents.clear(); break; } return true; }
@Override protected void updateStateByEvent(MotionEvent event) { final MotionEvent prev = mPreMotionEvent; mPrePointer = caculateFocalPointer(prev); mCurrentPointer = caculateFocalPointer(event); boolean mSkipMoveEvent = prev.getPointerCount() != event.getPointerCount(); mExtenalPointer.x = mSkipMoveEvent ? 0 : mCurrentPointer.x - mPrePointer.x; mExtenalPointer.y = mSkipMoveEvent ? 0 : mCurrentPointer.y - mPrePointer.y; }
@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (!mScrollEnabled) return false; if (e1 == null || e2 == null) return false; if (e1.getPointerCount() > 1 || e2.getPointerCount() > 1) return false; if (mScaleDetector.isInProgress()) return false; if (getScale() == 1f) return false; scrollBy(-distanceX, -distanceY); invalidate(); return super.onScroll(e1, e2, distanceX, distanceY); }
@Override public boolean onTouchEvent(MotionEvent event) { // Log.w( "a", "touch me " + Float.toString( event.getX() ) + ", " + Float.toString( // event.getY() ) ); float[] x = new float[event.getPointerCount()]; float[] y = new float[event.getPointerCount()]; for (int i = 0; i < event.getPointerCount(); i++) { x[i] = event.getX(i); y[i] = event.getY(i); } XoLib.input(1, x, y); mView.requestRender(); return true; }
@Override public boolean onTouchEvent(MotionEvent event) { int pointerCount = event.getPointerCount(); if (event.getAction() != MotionEvent.ACTION_UP) { if (pointerCount == 1) { pointerText1.setText("(" + event.getX(0) + "," + event.getY(0) + ")"); pointerText2.setText(""); } else if (pointerCount == 2) { pointerText1.setText(""); pointerText2.setText( "(" + event.getX(0) + "," + event.getY(0) + ")-(" + event.getX(1) + "," + event.getY(1) + ")"); } } return super.onTouchEvent(event); }
@Override public boolean onTouchEvent(MotionEvent event) { float mCurX; float mCurY; // API level 9 and above supports "Major" property on event which // gives // the size of the touch area at the point of contact // so for now we just hard code float TOUCH_AREA_SIZE = penWidth; int action = event.getAction(); if (action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_CANCEL) { int N = event.getHistorySize(); int P = event.getPointerCount(); for (int i = 0; i < N; i++) { for (int j = 0; j < P; j++) { mCurX = event.getHistoricalX(j, i); mCurY = event.getHistoricalY(j, i); drawPoint(mCurX, mCurY, event.getHistoricalPressure(j, i), TOUCH_AREA_SIZE); } } for (int j = 0; j < P; j++) { mCurX = event.getX(j); mCurY = event.getY(j); drawPoint(mCurX, mCurY, event.getPressure(j), TOUCH_AREA_SIZE); } } unsaved = true; return true; }
/** Called when the user drags one or more fingers across the touchscreen. */ @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { int pointerCount = e2.getPointerCount(); if (pointerCount == 3 && !mSwipeCompleted) { // Note that distance values are reversed. For example, dragging a finger in the // direction of increasing Y coordinate (downwards) results in distanceY being // negative. mTotalMotionY -= distanceY; return onSwipe(); } if (pointerCount == 2 && mSwipePinchDetector.isSwiping()) { mViewer.injectMouseWheelDeltaEvent(-(int) distanceX, -(int) distanceY); // Prevent the cursor being moved or flung by the gesture. mSuppressCursorMovement = true; return true; } if (pointerCount != 1 || mSuppressCursorMovement) { return false; } float[] delta = {distanceX, distanceY}; synchronized (mRenderData) { Matrix canvasToImage = new Matrix(); mRenderData.transform.invert(canvasToImage); canvasToImage.mapVectors(delta); } moveCursor(mCursorPosition.x - delta[0], mCursorPosition.y - delta[1]); return true; }
/** * MotionEvent has no getRawY(int) method; simulate it pending future API approval. * * @param event * @param pointerIndex * @return */ protected static float getRawY(MotionEvent event, int pointerIndex) { float offset = event.getY() - event.getRawY(); if (pointerIndex < event.getPointerCount()) { return event.getY(pointerIndex) + offset; } return 0f; }
public void handleTouch(MotionEvent e) { // Stop inertial animation // if (this.inertialAnimation_) { // this.inertialAnimation_.stop(false); // this.inertialAnimation_.dispose(); // this.inertialAnimation_ = null; // } if (e.getAction() != MotionEvent.ACTION_DOWN && oldX_ != 0.0f && oldY_ != 0.0f && e.getPointerCount() == 1) { onMouseMove_(e); } else { this.oldX_ = e.getX(); this.oldY_ = e.getY(); } this.dragging_ = true; // Unregister onMouseMove_ // if (!goog.isNull(this.listenKey_)) { // goog.events.unlistenByKey(this.listenKey_); // this.listenKey_ = null; // } // Register onMouseMove_ // this.listenKey_ = goog.events.listen( // goog.dom.getOwnerDocument(this.scene_.context.canvas), // goog.events.EventType.MOUSEMOVE, // goog.bind(this.onMouseMove_, this)); // e.preventDefault(); }
public boolean onTouch(View v, MotionEvent event) { GiderosApplication app = GiderosApplication.getInstance(); if (app == null) return false; int size = event.getPointerCount(); for (int i = 0; i < size; i++) { id[i] = event.getPointerId(i); x[i] = (int) event.getX(i); y[i] = (int) event.getY(i); } int actionMasked = event.getActionMasked(); boolean isPointer = (actionMasked == MotionEvent.ACTION_POINTER_DOWN || actionMasked == MotionEvent.ACTION_POINTER_UP); int actionIndex = isPointer ? event.getActionIndex() : 0; if (actionMasked == MotionEvent.ACTION_DOWN || actionMasked == MotionEvent.ACTION_POINTER_DOWN) { app.onTouchesBegin(size, id, x, y, actionIndex); } else if (actionMasked == MotionEvent.ACTION_MOVE) { app.onTouchesMove(size, id, x, y); } else if (actionMasked == MotionEvent.ACTION_UP || actionMasked == MotionEvent.ACTION_POINTER_UP) { app.onTouchesEnd(size, id, x, y, actionIndex); } else if (actionMasked == MotionEvent.ACTION_CANCEL) { app.onTouchesCancel(size, id, x, y); } return true; }
/** * M: Intercept the historical scroll to avoid webview shake left and right, when user scroll the * webview fastly with a angle of slope. Locking historical scroll with the following conditions: * 1) The slope (YVelocity/XVelocity) should be bigger than MAX_VELOCITY_RATE, 2) YVelocity && * XVelocity > mMaximumVelocity/VELOCITY_SCALE. */ private void needInterceptXMotion(MotionEvent ev) { if (ev.getPointerCount() > 1) { // Not handle multi-touch event. mInterceptXMotion = false; return; } mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); float scrollVelocityY = (float) mVelocityTracker.getYVelocity(ev.getPointerId(0)); float scrollVelocityX = (float) mVelocityTracker.getXVelocity(ev.getPointerId(0)); float threshold = mMaximumVelocity / VELOCITY_SCALE; if (Math.abs(scrollVelocityY) <= threshold && Math.abs(scrollVelocityX) <= threshold) { // Only handle fast scroll. mInterceptXMotion = false; return; } float rate = scrollVelocityY / scrollVelocityX; if (Math.abs(rate) >= MAX_VELOCITY_RATE) { mInterceptXMotion = true; } else { mInterceptXMotion = false; } }
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (!mScrollEnabled) return false; if (e1.getPointerCount() > 1 || e2.getPointerCount() > 1) return false; if (mScaleDetector.isInProgress()) return false; float diffX = e2.getX() - e1.getX(); float diffY = e2.getY() - e1.getY(); if (Math.abs(velocityX) > 800 || Math.abs(velocityY) > 800) { scrollBy(diffX / 2, diffY / 2, 300); invalidate(); } return super.onFling(e1, e2, velocityX, velocityY); }
public boolean onTouch(View paramView, MotionEvent paramMotionEvent) { c.onTouch(paramView, paramMotionEvent); if (paramMotionEvent.getPointerCount() > 1) { d.a(paramMotionEvent); return true; } if ((d.g == null) || (d.g.f() <= d.g.b()) || ((d.g.d() <= d.k.widthPixels) && (d.g.c() <= d.k.heightPixels)) || (a)) { d.i.onTouchEvent(paramMotionEvent); } for (; ; ) { if ((a) && (paramMotionEvent.getAction() == 1)) { d.i.g(); a = false; } d.f.onTouchEvent(paramMotionEvent); return true; if (b == null) { b = new bs(this, paramMotionEvent); } d.g.a(b); } }
@Override protected boolean onTouchImpl(View view, MotionEvent event) { boolean result = false; if (mJoystickLeft != null && mJoystickLeft.processTouch(view, event)) result = true; if (mJoystickRight != null && mJoystickRight.processTouch(view, event)) result = true; // check for double tap if (mSettings.isFlipEnabled() && event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) { long currTimestamp = event.getEventTime(); if (event.getPointerCount() > 1) { if (currTimestamp - timestampLast < DOUBLE_TAP_TIMESTAMP_DELTA && Math.abs(event.getX(1) - xLast) < COORDINATE_DELTA && Math.abs(event.getY(1) - yLast) < COORDINATE_DELTA) { // Double tap detected. mDroneControl.doLeftFlip(); result = true; } } } return result; }
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getAction(); // Enable / disable zoom support in case of multiple pointer, e.g. enable zoom when we have two // down pointers, disable with one pointer or when pointer up. // We do this to prevent the display of zoom controls, which are not useful and override over // the right bubble. if ((action == MotionEvent.ACTION_DOWN) || (action == MotionEvent.ACTION_POINTER_DOWN) || (action == MotionEvent.ACTION_POINTER_1_DOWN) || (action == MotionEvent.ACTION_POINTER_2_DOWN) || (action == MotionEvent.ACTION_POINTER_3_DOWN)) { if (ev.getPointerCount() > 1) { this.getSettings().setBuiltInZoomControls(true); this.getSettings().setSupportZoom(true); } else { this.getSettings().setBuiltInZoomControls(false); this.getSettings().setSupportZoom(false); } } else if ((action == MotionEvent.ACTION_UP) || (action == MotionEvent.ACTION_POINTER_UP) || (action == MotionEvent.ACTION_POINTER_1_UP) || (action == MotionEvent.ACTION_POINTER_2_UP) || (action == MotionEvent.ACTION_POINTER_3_UP)) { this.getSettings().setBuiltInZoomControls(false); this.getSettings().setSupportZoom(false); } return super.onTouchEvent(ev); }
private static MotionEvent transformEventOld(MotionEvent paramMotionEvent, Matrix paramMatrix) { long l1 = paramMotionEvent.getDownTime(); long l2 = paramMotionEvent.getEventTime(); int i = paramMotionEvent.getAction(); int j = paramMotionEvent.getPointerCount(); int[] arrayOfInt = getPointerIds(paramMotionEvent); MotionEvent.PointerCoords[] arrayOfPointerCoords = getPointerCoords(paramMotionEvent); int k = paramMotionEvent.getMetaState(); float f1 = paramMotionEvent.getXPrecision(); float f2 = paramMotionEvent.getYPrecision(); int l = paramMotionEvent.getDeviceId(); int i1 = paramMotionEvent.getEdgeFlags(); int i2 = paramMotionEvent.getSource(); int i3 = paramMotionEvent.getFlags(); float[] arrayOfFloat = new float[2 * arrayOfPointerCoords.length]; for (int i4 = 0; i4 < j; ++i4) { arrayOfFloat[(i4 * 2)] = arrayOfPointerCoords[i4].x; arrayOfFloat[(1 + i4 * 2)] = arrayOfPointerCoords[i4].y; } paramMatrix.mapPoints(arrayOfFloat); for (int i5 = 0; i5 < j; ++i5) { arrayOfPointerCoords[i5].x = arrayOfFloat[(i5 * 2)]; arrayOfPointerCoords[i5].y = arrayOfFloat[(1 + i5 * 2)]; arrayOfPointerCoords[i5].orientation = transformAngle(paramMatrix, arrayOfPointerCoords[i5].orientation); } return MotionEvent.obtain( l1, l2, i, j, arrayOfInt, arrayOfPointerCoords, k, f1, f2, l, i1, i2, i3); }
public boolean onTouchEvent(MotionEvent event) { TEManagerInput inputManager = TEManagerInput.sharedManager(); int pointerId; float x; float y; final int actionId = event.getAction(); TEInputTouch touch; final int pointerCount = event.getPointerCount(); for (int i = 0; i < pointerCount; ++i) { pointerId = event.getPointerId(i); x = event.getX(pointerId); y = mHeight - event.getY(pointerId); switch (actionId) { case MotionEvent.ACTION_DOWN: touch = new TEInputTouch(pointerId, x, y); inputManager.beginTouch(touch); break; case MotionEvent.ACTION_MOVE: touch = new TEInputTouch(pointerId, x, y); inputManager.moveTouch(touch); break; case MotionEvent.ACTION_UP: touch = new TEInputTouch(pointerId, x, y); inputManager.endTouch(touch); break; default: Log.v("info", "Couldn't identify " + String.valueOf(actionId)); break; } } return false; }
@Override public boolean onTouchEvent(MotionEvent event) { int action = event.getActionMasked(); int P = event.getPointerCount(); // int N = event.getHistorySize(); if (action != MotionEvent.ACTION_MOVE) { if (action == MotionEvent.ACTION_DOWN) { // startX = mCurX * mScale; // event.getX(); // startY = mCurY * mScale; // event.getY(); sX1 = mCurX * mScale - event.getX(0); sY1 = mCurY * mScale - event.getY(0); return true; } if (action == MotionEvent.ACTION_POINTER_DOWN) { // Toast.makeText(mContext, // Float.toString(sX1)+"apd", // Toast.LENGTH_SHORT).show(); if (P == 2) { float sX2 = event.getX(0) - event.getX(1); float sY2 = event.getY(0) - event.getY(1); sD = (float) Math.sqrt(sX2 * sX2 + sY2 * sY2); mBitmapViewWidthInitial = mBitmapViewWidth; return true; } else if (P == 3) { sMx = (float) mCenterX - event.getX(2); sMy = (float) mCenterY - event.getY(2); return true; } return false; } } else { if (P == 1) { float a = Math.abs(sX1 + event.getX()) % mX; float b = Math.abs(sY1 + event.getY()) % mY; mCurX = (int) (a / mScale); // *(int)(event.getHistoricalX(0)-event.getHistoricalX(1)); mCurY = (int) (b / mScale); // *(int)(event.getHistoricalY(0)-event.getHistoricalY(1)); } else if (P == 2) { float sX2 = event.getX(0) - event.getX(1); float sY2 = event.getY(0) - event.getY(1); float sD2 = (float) Math.sqrt(sX2 * sX2 + sY2 * sY2); int r = mBitmapViewWidthInitial + Math.round(sD2 - sD); if (r < mScreenRadius) r = mScreenRadius; setViewBitmapSizes(r); } else if (P == 3) { mCenterX = (int) (sMx + event.getX(2)); mCenterY = (int) (sMy + event.getY(2)); } else { return false; } drawIntoBitmap(); invalidate(); if (use3D) { updateTexture(); } } return true; }
private float spacing(MotionEvent event) { if (event == null || (event.getPointerCount() < 2)) return 0.0f; 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 findEventCenter(PointF centerOut, MotionEvent event) { if (event.getPointerCount() == 1) { centerOut.set(event.getX(0), event.getY(0)); } else { centerOut.set((event.getX(0) + event.getX(1)) / 2, (event.getY(0) + event.getY(1)) / 2); } }
// Touch events @Override public boolean onTouch(View v, MotionEvent event) { final int touchDevId = event.getDeviceId(); final int pointerCount = event.getPointerCount(); // touchId, pointerId, action, x, y, pressure int actionPointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; /* API 8: event.getActionIndex(); */ int pointerFingerId = event.getPointerId(actionPointerIndex); int action = (event.getAction() & MotionEvent.ACTION_MASK); /* API 8: event.getActionMasked(); */ float x = event.getX(actionPointerIndex) / mWidth; float y = event.getY(actionPointerIndex) / mHeight; float p = event.getPressure(actionPointerIndex); if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) { // TODO send motion to every pointer if its position has // changed since prev event. for (int i = 0; i < pointerCount; i++) { pointerFingerId = event.getPointerId(i); x = event.getX(i) / mWidth; y = event.getY(i) / mHeight; p = event.getPressure(i); SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); } } else { SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); } return true; }
@Override public boolean onTouchEvent(final MotionEvent ev) { final MainView me = this; final int action = ev.getAction(); int type = -1; switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: type = etTouchBegin; break; case MotionEvent.ACTION_POINTER_DOWN: type = etTouchBegin; break; case MotionEvent.ACTION_MOVE: type = etTouchMove; break; case MotionEvent.ACTION_UP: type = etTouchEnd; break; case MotionEvent.ACTION_POINTER_UP: type = etTouchEnd; break; case MotionEvent.ACTION_CANCEL: type = etTouchEnd; break; } // Log.e("VIEW","Actions : " + action ); // This is actually index, not id.... int idx = (action & MotionEvent.ACTION_POINTER_ID_MASK) >> (MotionEvent.ACTION_POINTER_ID_SHIFT); final int t = type; // if (type!=etTouchMove) // Log.e("VIEW","onTouchEvent " + ev.toString() ); for (int i = 0; i < ev.getPointerCount(); i++) { // Log.e("VIEW","onTouchEvent " + type + " x " + ev.getPointerCount() ); final int id = ev.getPointerId(i); final float x = ev.getX(i); final float y = ev.getY(i); final float sizeX = ev.getSize(i); final float sizeY = ev.getSize(i); // if (type!=etTouchMove) // Log.e("VIEW"," " + i + "] type=" + t + " id="+ id + " idx="+ idx +" " + x + ", "+ y + "," // + sizeX + "," + sizeY); if (type == etTouchMove || i == idx) { queueEvent( new Runnable() { public void run() { me.HandleResult(NME.onTouch(t, x, y, id, sizeX, sizeY)); } }); } } return true; }
public boolean onTouchEvent2(MotionEvent event) { // Cancel current circle on two-fingers touch (or more.) if (event.getPointerCount() > 1) { cancelCircle(false); return false; } // If current circle is canceled then // ignore all actions except of touch down (to reset state.) if (mCanceled && event.getActionMasked() != MotionEvent.ACTION_DOWN) return false; final float x = event.getX(); final float y = event.getY(); switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: clearAnimation(); // Initialize circle mRadiusMax = 0; mPoint[0] = x; mPoint[1] = y; mCanceled = false; mHandler.removeCallbacks(mDelayedCancel); mHandler.postDelayed(mDelayedCancel, 1000); mCallback.onCircleEvent(mRadius, calculateRatio(), ACTION_START); case MotionEvent.ACTION_MOVE: setRadius((float) Math.hypot(x - mPoint[0], y - mPoint[1])); // Cancel the circle if it's decreasing. if (mRadiusMax - mRadius > mRadiusDecreaseThreshold) { mRadiusAimed = false; cancelCircle(false); break; } if (calculateRatio() == 1) { if (!mRadiusAimed) { mRadiusAimed = true; performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); } } else if (mRadiusAimed) { mRadiusAimed = false; performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); } break; case MotionEvent.ACTION_UP: if (mRadiusAimed) { mCallback.onCircleEvent(mRadius, calculateRatio(), ACTION_UNLOCK); } case MotionEvent.ACTION_CANCEL: mHandler.removeCallbacks(mDelayedCancel); cancelCircle(mRadiusAimed); break; default: return super.onTouchEvent(event); } return false; }