List of usage examples for android.view MotionEvent getEventTime
@Override public final long getEventTime()
From source file:jmri.enginedriver.throttle.java
private void gestureStart(MotionEvent event) { gestureStartX = event.getX();/*from ww w . j a va2s. c o m*/ gestureStartY = event.getY(); // Log.d("Engine_Driver", "gestureStart y=" + gestureStartY); // check if the sliders are already hidden by preference if (!prefs.getBoolean("hide_slider_preference", false)) { // if gesture is attempting to start over an enabled slider, ignore it and return immediately. for (int throttleIndex = 0; throttleIndex < mainapp.numThrottles; throttleIndex++) { if ((sbs[throttleIndex].isEnabled() && gestureStartY >= tops[throttleIndex] && gestureStartY <= bottoms[throttleIndex])) { // Log.d("Engine_Driver","exiting gestureStart"); return; } } } gestureInProgress = true; gestureFailed = false; gestureLastCheckTime = event.getEventTime(); mVelocityTracker.clear(); // start the gesture timeout timer if (mainapp.throttle_msg_handler != null) mainapp.throttle_msg_handler.postDelayed(gestureStopped, gestureCheckRate); }
From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java
@Override public boolean onTouchEvent(final MotionEvent event) { final int pointerIndex = MotionEventCompat.getActionIndex(event); final int pointCnt = mWrap.getPointerCount(event); final int pointerId = MotionEventCompat.getPointerId(event, pointerIndex); if (pointCnt < MAX_POINT_CNT) { //if (pointerIndex <= MAX_POINT_CNT - 1){ {//from w w w . j a v a2 s . c o m for (int i = 0; i < pointCnt; i++) { int id = MotionEventCompat.getPointerId(event, i); if (id < MAX_POINT_CNT) { x_last[id] = x[id]; y_last[id] = y[id]; x[id] = mWrap.getX(event, i); y[id] = mWrap.getY(event, i); } } switch (MotionEventCompat.getActionMasked(event)) { case MotionEvent.ACTION_DOWN: case MotionEventCompat.ACTION_POINTER_DOWN: int button = -1; // Save the ID of this pointer if (mInputMode == INPUT_MODE_MOUSE) { } else if (mInputMode == INPUT_MODE_REAL_JOYSTICK) { int buttonState = mWrap.getButtonState(event); if ((buttonState & TouchEventWrapper.BUTTON_PRIMARY) != 0) { button = BTN_A; } else if ((buttonState & TouchEventWrapper.BUTTON_SECONDARY) != 0) { button = BTN_B; } DosBoxControl.nativeJoystick(0, 0, ACTION_DOWN, button); } else if (mInputMode == INPUT_MODE_REAL_MOUSE) { int buttonState = mWrap.getButtonState(event); if ((buttonState & TouchEventWrapper.BUTTON_PRIMARY) != 0) { button = BTN_A; } else if ((buttonState & TouchEventWrapper.BUTTON_SECONDARY) != 0) { button = BTN_B; } else if (buttonState == 0) { // handle trackpad presses as button clicks button = BTN_A; } DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_DOWN, button); } mButtonDown[pointerId] = button; break; case MotionEvent.ACTION_UP: case MotionEventCompat.ACTION_POINTER_UP: if (mInputMode == INPUT_MODE_MOUSE) { if (mLongClick) { // single tap long click release DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_UP, mGestureSingleClick - GESTURE_LEFT_CLICK); mLongClick = false; Log.i("DosBoxTurbo", "SingleTap Long Click Release"); return true; } else if (mDoubleLong) { // double tap long click release try { Thread.sleep(CLICK_DELAY); } catch (InterruptedException e) { } DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_UP, mGestureDoubleClick - GESTURE_LEFT_CLICK); Log.i("DosBoxTurbo", "DoubleTap Long Click Release"); mDoubleLong = false; //return true; } else if (pointCnt == 2) { // handle 2 finger tap gesture if (mLongPress) { if (!mTwoFingerAction) { // press button down Log.i("DosBoxTurbo", "2-Finger Long Click Down"); DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_DOWN, mGestureTwoFinger - GESTURE_LEFT_CLICK); mTwoFingerAction = true; } else { // already pressing button - release and press again Log.i("DosBoxTurbo", "2-Finger Long Click - AGAIN"); DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_UP, mGestureTwoFinger - GESTURE_LEFT_CLICK); try { Thread.sleep(CLICK_DELAY); } catch (InterruptedException e) { } DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_DOWN, mGestureTwoFinger - GESTURE_LEFT_CLICK); } } else { Log.i("DosBoxTurbo", "2-Finger Long Click Down-UP"); mouseClick(mGestureTwoFinger - GESTURE_LEFT_CLICK); } return true; } else if ((pointCnt == 1) && mTwoFingerAction) { // release two finger gesture Log.i("DosBoxTurbo", "2-Finger Long Click Release"); DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_UP, mGestureTwoFinger - GESTURE_LEFT_CLICK); mTwoFingerAction = false; //return true; } } else if (mInputMode == INPUT_MODE_REAL_MOUSE) { //Log.v("Mouse","BUTTON UP: " + (mButtonDown[pointerId])); DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_UP, mButtonDown[pointerId]); if (mWrap.getButtonState(event) > 0) { return true; // capture button touches, pass screen touches through to gesture detetor } } else if (mInputMode == INPUT_MODE_REAL_JOYSTICK) { DosBoxControl.nativeJoystick(0, 0, ACTION_UP, (mButtonDown[pointerId])); if (mWrap.getButtonState(event) > 0) { return true; } } break; case MotionEvent.ACTION_MOVE: //isTouch[pointerId] = true; switch (mInputMode) { case INPUT_MODE_SCROLL: mScroll_x += (int) (x[pointerId] - x_last[pointerId]); mScroll_y += (int) (y[pointerId] - y_last[pointerId]); forceRedraw(); break; case INPUT_MODE_MOUSE: case INPUT_MODE_REAL_MOUSE: if (event.getEventTime() + EVENT_THRESHOLD_DECAY < SystemClock.uptimeMillis()) { Log.i("DosBoxTurbo", "eventtime: " + event.getEventTime() + " systemtime: " + SystemClock.uptimeMillis()); return true; // get rid of old events } int idx = (!virtButton[0]) ? 0 : 1; if (mAbsolute) { DosBoxControl.nativeMouseWarp(x[idx], y[idx], mRenderer.x, mRenderer.y, mRenderer.width, mRenderer.height); } else { DosBoxControl.nativeMouse((int) (x[idx] * mMouseSensitivityX), (int) (y[idx] * mMouseSensitivityY), (int) (x_last[idx] * mMouseSensitivityX), (int) (y_last[idx] * mMouseSensitivityY), ACTION_MOVE, -1); } if (mDebug) { Log.d("DosBoxTurbo", "mAbsolute=" + mAbsolute + " MotionEvent MOVE(" + pointerId + ")" + " x[idx]=" + x[idx] + " y[idx]" + y[idx] + " mRenderer.x=" + mRenderer.x + " mRenderer.y=" + mRenderer.y + " mRenderer.width=" + mRenderer.width + " mRenderer.height=" + mRenderer.height); } try { if (!mInputLowLatency) Thread.sleep(95); else Thread.sleep(65); } catch (InterruptedException e) { } break; default: } break; } } } try { Thread.sleep(15); } catch (InterruptedException e) { e.printStackTrace(); } //Thread.yield(); return gestureScanner.onTouchEvent(event); }
From source file:com.processing.core.PApplet.java
/** * Figure out how to process a mouse event. When loop() has been * called, the events will be queued up until drawing is complete. * If noLoop() has been called, then events will happen immediately. *///from w w w.j a va 2 s. com protected void nativeMotionEvent(android.view.MotionEvent motionEvent) { // enqueueMotionEvent(event); // // // this will be the last event in the list // AndroidTouchEvent pme = motionEventQueue[motionEventCount + historyCount]; // pme.setAction(event.getAction()); // pme.setNumPointers(event.getPointerCount()); // pme.setPointers(event); // // // historical events happen before the 'current' values // if (pme.action == MotionEvent.ACTION_MOVE && historyCount > 0) { // for (int i = 0; i < historyCount; i++) { // AndroidTouchEvent hist = motionEventQueue[motionEventCount++]; // hist.setAction(event.getAction()); // hist.setNumPointers(event.getPointerCount()); // hist.setPointers(event, i); // } // } // ACTION_HOVER_ENTER and ACTION_HOVER_EXIT are passed into // onGenericMotionEvent(android.view.MotionEvent) // if we want to implement mouseEntered/Exited // http://developer.android.com/reference/android/view/MotionEvent.html // http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html // http://www.techrepublic.com/blog/app-builder/use-androids-gesture-detector-to-translate-a-swipe-into-an-event/1577 int metaState = motionEvent.getMetaState(); int modifiers = 0; if ((metaState & android.view.KeyEvent.META_SHIFT_ON) != 0) { modifiers |= Event.SHIFT; } if ((metaState & META_CTRL_ON) != 0) { modifiers |= Event.CTRL; } if ((metaState & META_META_ON) != 0) { modifiers |= Event.META; } if ((metaState & android.view.KeyEvent.META_ALT_ON) != 0) { modifiers |= Event.ALT; } int clickCount = 1; // not really set... (i.e. not catching double taps) int index; // MotionEvent.html -> getButtonState() does BUTTON_PRIMARY, SECONDARY, TERTIARY // use this for left/right/etc switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: motionPointerId = motionEvent.getPointerId(0); postEvent(new MouseEvent(motionEvent, motionEvent.getEventTime(), MouseEvent.PRESS, modifiers, (int) motionEvent.getX(), (int) motionEvent.getY(), LEFT, clickCount)); break; case MotionEvent.ACTION_MOVE: // int historySize = motionEvent.getHistorySize(); index = motionEvent.findPointerIndex(motionPointerId); if (index != -1) { postEvent(new MouseEvent(motionEvent, motionEvent.getEventTime(), MouseEvent.DRAG, modifiers, (int) motionEvent.getX(index), (int) motionEvent.getY(index), LEFT, clickCount)); } break; case MotionEvent.ACTION_UP: index = motionEvent.findPointerIndex(motionPointerId); if (index != -1) { postEvent(new MouseEvent(motionEvent, motionEvent.getEventTime(), MouseEvent.RELEASE, modifiers, (int) motionEvent.getX(index), (int) motionEvent.getY(index), LEFT, clickCount)); } break; } //postEvent(pme); }