Java Code Examples for android.view.MotionEvent#isFromSource()
The following examples show how to use
android.view.MotionEvent#isFromSource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IInputMethodSessionWrapper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void onInputEvent(InputEvent event, int displayId) { if (mInputMethodSession == null) { // The session has been finished. finishInputEvent(event, false); return; } final int seq = event.getSequenceNumber(); mPendingEvents.put(seq, event); if (event instanceof KeyEvent) { KeyEvent keyEvent = (KeyEvent)event; mInputMethodSession.dispatchKeyEvent(seq, keyEvent, this); } else { MotionEvent motionEvent = (MotionEvent)event; if (motionEvent.isFromSource(InputDevice.SOURCE_CLASS_TRACKBALL)) { mInputMethodSession.dispatchTrackballEvent(seq, motionEvent, this); } else { mInputMethodSession.dispatchGenericMotionEvent(seq, motionEvent, this); } } }
Example 2
Source File: ActivityView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean onGenericMotionEvent(MotionEvent event) { if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { if (injectInputEvent(event)) { return true; } } return super.onGenericMotionEvent(event); }
Example 3
Source File: HorizontalScrollView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean onGenericMotionEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: { if (!mIsBeingDragged) { final float axisValue; if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) { axisValue = -event.getAxisValue(MotionEvent.AXIS_VSCROLL); } else { axisValue = event.getAxisValue(MotionEvent.AXIS_HSCROLL); } } else if (event.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)) { axisValue = event.getAxisValue(MotionEvent.AXIS_SCROLL); } else { axisValue = 0; } final int delta = Math.round(axisValue * mHorizontalScrollFactor); if (delta != 0) { final int range = getScrollRange(); int oldScrollX = mScrollX; int newScrollX = oldScrollX + delta; if (newScrollX < 0) { newScrollX = 0; } else if (newScrollX > range) { newScrollX = range; } if (newScrollX != oldScrollX) { super.scrollTo(newScrollX, mScrollY); return true; } } } } } return super.onGenericMotionEvent(event); }
Example 4
Source File: ScrollView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean onGenericMotionEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: final float axisValue; if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL); } else if (event.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)) { axisValue = event.getAxisValue(MotionEvent.AXIS_SCROLL); } else { axisValue = 0; } final int delta = Math.round(axisValue * mVerticalScrollFactor); if (delta != 0) { final int range = getScrollRange(); int oldScrollY = mScrollY; int newScrollY = oldScrollY - delta; if (newScrollY < 0) { newScrollY = 0; } else if (newScrollY > range) { newScrollY = range; } if (newScrollY != oldScrollY) { super.scrollTo(mScrollX, newScrollY); return true; } } break; } return super.onGenericMotionEvent(event); }
Example 5
Source File: SystemGesturesPointerEventListener.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override public void onPointerEvent(MotionEvent event) { if (mGestureDetector != null && event.isTouchEvent()) { mGestureDetector.onTouchEvent(event); } switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: mSwipeFireable = true; mDebugFireable = true; mDownPointers = 0; captureDown(event, 0); if (mMouseHoveringAtEdge) { mMouseHoveringAtEdge = false; mCallbacks.onMouseLeaveFromEdge(); } mCallbacks.onDown(); break; case MotionEvent.ACTION_POINTER_DOWN: captureDown(event, event.getActionIndex()); if (mDebugFireable) { mDebugFireable = event.getPointerCount() < 5; if (!mDebugFireable) { if (DEBUG) Slog.d(TAG, "Firing debug"); mCallbacks.onDebug(); } } break; case MotionEvent.ACTION_MOVE: if (mSwipeFireable) { final int swipe = detectSwipe(event); mSwipeFireable = swipe == SWIPE_NONE; if (swipe == SWIPE_FROM_TOP) { if (DEBUG) Slog.d(TAG, "Firing onSwipeFromTop"); mCallbacks.onSwipeFromTop(); } else if (swipe == SWIPE_FROM_BOTTOM) { if (DEBUG) Slog.d(TAG, "Firing onSwipeFromBottom"); mCallbacks.onSwipeFromBottom(); } else if (swipe == SWIPE_FROM_RIGHT) { if (DEBUG) Slog.d(TAG, "Firing onSwipeFromRight"); mCallbacks.onSwipeFromRight(); } else if (swipe == SWIPE_FROM_LEFT) { if (DEBUG) Slog.d(TAG, "Firing onSwipeFromLeft"); mCallbacks.onSwipeFromLeft(); } } break; case MotionEvent.ACTION_HOVER_MOVE: if (event.isFromSource(InputDevice.SOURCE_MOUSE)) { if (!mMouseHoveringAtEdge && event.getY() == 0) { mCallbacks.onMouseHoverAtTop(); mMouseHoveringAtEdge = true; } else if (!mMouseHoveringAtEdge && event.getY() >= screenHeight - 1) { mCallbacks.onMouseHoverAtBottom(); mMouseHoveringAtEdge = true; } else if (mMouseHoveringAtEdge && (event.getY() > 0 && event.getY() < screenHeight - 1)) { mCallbacks.onMouseLeaveFromEdge(); mMouseHoveringAtEdge = false; } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mSwipeFireable = false; mDebugFireable = false; mCallbacks.onUpOrCancel(); break; default: if (DEBUG) Slog.d(TAG, "Ignoring " + event); } }