Java Code Examples for android.view.MotionEvent#getSource()
The following examples show how to use
android.view.MotionEvent#getSource() .
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: AndroidInputHandler14.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public boolean onHover(View view, MotionEvent event) { if (view != getView()) { return false; } boolean consumed = false; int source = event.getSource(); // logger.log(Level.INFO, "onTouch source: {0}", source); boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN); // logger.log(Level.INFO, "onTouch source: {0}, isTouch: {1}", // new Object[]{source, isTouch}); if (isTouch && touchInput != null) { // send the event to the touch processor consumed = ((AndroidTouchInput14)touchInput).onHover(event); } return consumed; }
Example 2
Source File: AbsHListView.java From letv with Apache License 2.0 | 6 votes |
@TargetApi(12) public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & 2) != 0) { switch (event.getAction()) { case 8: if (this.mTouchMode == -1) { float hscroll = event.getAxisValue(10); if (hscroll != 0.0f) { int delta = (int) (getHorizontalScrollFactor() * hscroll); if (!trackMotionScroll(delta, delta)) { return true; } } } break; } } return super.onGenericMotionEvent(event); }
Example 3
Source File: AndroidInputHandler14.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public boolean onGenericMotion(View view, MotionEvent event) { if (view != getView()) { return false; } boolean consumed = false; int source = event.getSource(); // logger.log(Level.INFO, "onGenericMotion source: {0}", source); boolean isJoystick = ((source & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK); if (isJoystick && joyInput != null) { // logger.log(Level.INFO, "onGenericMotion source: {0}, isJoystick: {1}", // new Object[]{source, isJoystick}); // send the event to the touch processor consumed = consumed || ((AndroidJoyInput14)joyInput).onGenericMotion(event); } return consumed; }
Example 4
Source File: AxisMappingDialogPreference.java From crazyflie-android-client with GNU General Public License v2.0 | 6 votes |
@Override public boolean onGenericMotion(View v, MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE) { List<MotionRange> motionRanges = event.getDevice().getMotionRanges(); for(MotionRange mr : motionRanges){ int axis = mr.getAxis(); if(event.getAxisValue(axis) > 0.5 || event.getAxisValue(axis) < -0.5){ Log.i(TAG, "Axis found: " + MotionEvent.axisToString(axis)); this.mAxisName = MotionEvent.axisToString(axis); mValueTextView.setText(mAxisName); } } }else{ Log.i(TAG, "Not a joystick event."); } return true; }
Example 5
Source File: ZrcAbsListView.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override public boolean onGenericMotionEvent(MotionEvent event) { if (Build.VERSION.SDK_INT >= 12) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: { if (mTouchMode == TOUCH_MODE_REST) { final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); if (vscroll != 0) { final int delta = (int) (vscroll * getVerticalScrollFactor()); if (!trackMotionScroll(delta, delta)) { return true; } } } } } } } return super.onGenericMotionEvent(event); }
Example 6
Source File: FilmstripGestureRecognizer.java From Camera2 with Apache License 2.0 | 6 votes |
public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: { final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL); final float vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL); if (hscroll != 0.0f || vscroll != 0.0f) { mListener.onMouseScroll(hscroll, vscroll); } } } } return true; }
Example 7
Source File: WebViewEx.java From FairEmail with GNU General Public License v3.0 | 5 votes |
@Override public boolean onGenericMotionEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_SCROLL && (event.getSource() & InputDevice.SOURCE_MOUSE) != 0) return false; return super.onGenericMotionEvent(event); }
Example 8
Source File: AndroidView.java From Alite with GNU General Public License v3.0 | 5 votes |
@Override public boolean onGenericMotionEvent(MotionEvent event) { if (game.getCurrentScreen() == null) { return true; } if (isController(event.getSource())) { if (Dpad.isDpadDevice(event)) { if (game.getCurrentScreen() != null) { game.getCurrentScreen().processDPad(dpad.getDirectionPressed(event)); } } // Check that the event came from a game controller if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) { // Process all historical movement samples in the batch final int historySize = event.getHistorySize(); // Process the movements starting from the // earliest historical position in the batch for (int i = 0; i < historySize; i++) { // Process the event at historical position i processJoystickInput(game.getCurrentScreen(), event, i); } // Process the current movement sample in the batch (position -1) processJoystickInput(game.getCurrentScreen(), event, -1); } } return super.onGenericMotionEvent(event); }
Example 9
Source File: MainActivity.java From crazyflie-android-client with GNU General Public License v2.0 | 5 votes |
@Override public boolean dispatchGenericMotionEvent(MotionEvent event) { // Check that the event came from a joystick since a generic motion event could be almost anything. if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE && mController instanceof GamepadController) { mGamepadController.dealWithMotionEvent(event); updateFlightData(); return true; } else { return super.dispatchGenericMotionEvent(event); } }
Example 10
Source File: GameControllerInput.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override public boolean dispatchGenericMotionEvent(MotionEvent event) { // Check that the event came from a joystick since a generic motion event // could be almost anything. if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE) { // Update device state for visualization and logging. InputDeviceState state = getInputDeviceState(event); if (state != null && state.onJoystickMotion(event)) { mSummaryAdapter.show(state); } } return super.dispatchGenericMotionEvent(event); }
Example 11
Source File: PagedView.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
@Override public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: { // Handle mouse (or ext. device) by shifting the page depending on the scroll final float vscroll; final float hscroll; if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) { vscroll = 0; hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); } else { vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL); hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL); } if (hscroll != 0 || vscroll != 0) { boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0) : (hscroll > 0 || vscroll > 0); if (isForwardScroll) { scrollRight(); } else { scrollLeft(); } return true; } } } } return super.onGenericMotionEvent(event); }
Example 12
Source File: MotionEventHelper.java From ViewSupport with Apache License 2.0 | 5 votes |
private static MotionEvent transformEventOld(MotionEvent e, Matrix m) { long downTime = e.getDownTime(); long eventTime = e.getEventTime(); int action = e.getAction(); int pointerCount = e.getPointerCount(); int[] pointerIds = getPointerIds(e); PointerCoords[] pointerCoords = getPointerCoords(e); int metaState = e.getMetaState(); float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource(); int flags = e.getFlags(); // Copy the x and y coordinates into an array, map them, and copy back. float[] xy = new float[pointerCoords.length * 2]; for (int i = 0; i < pointerCount;i++) { xy[2 * i] = pointerCoords[i].x; xy[2 * i + 1] = pointerCoords[i].y; } m.mapPoints(xy); for (int i = 0; i < pointerCount;i++) { pointerCoords[i].x = xy[2 * i]; pointerCoords[i].y = xy[2 * i + 1]; pointerCoords[i].orientation = transformAngle( m, pointerCoords[i].orientation); } MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords, metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags); return n; }
Example 13
Source File: StickyGridHeadersGridView.java From UltimateAndroid with Apache License 2.0 | 5 votes |
private MotionEvent transformEvent(MotionEvent e, int headerPosition) { if (headerPosition == MATCHED_STICKIED_HEADER) { return e; } long downTime = e.getDownTime(); long eventTime = e.getEventTime(); int action = e.getAction(); int pointerCount = e.getPointerCount(); int[] pointerIds = getPointerIds(e); MotionEvent.PointerCoords[] pointerCoords = getPointerCoords(e); int metaState = e.getMetaState(); float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource(); int flags = e.getFlags(); View headerHolder = getChildAt(headerPosition); for (int i = 0; i < pointerCount;i++) { pointerCoords[i].y -= headerHolder.getTop(); } MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords, metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags); return n; }
Example 14
Source File: InputManagerEventInjectionStrategy.java From android-test with Apache License 2.0 | 4 votes |
private static boolean isFromTouchpadInGlassDevice(MotionEvent motionEvent) { return (Build.DEVICE.contains("glass") || Build.DEVICE.contains("Glass") || Build.DEVICE.contains("wingman")) && ((motionEvent.getSource() & InputDevice.SOURCE_TOUCHPAD) != 0); }
Example 15
Source File: MotionAlertDialog.java From citra_android with GNU General Public License v3.0 | 4 votes |
private boolean onMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0) return false; if (event.getAction() != MotionEvent.ACTION_MOVE) return false; InputDevice input = event.getDevice(); List<InputDevice.MotionRange> motionRanges = input.getMotionRanges(); int numMovedAxis = 0; float axisMoveValue = 0.0f; InputDevice.MotionRange lastMovedRange = null; char lastMovedDir = '?'; if (mWaitingForEvent) { // Get only the axis that seem to have moved (more than .5) for (InputDevice.MotionRange range : motionRanges) { int axis = range.getAxis(); float origValue = event.getAxisValue(axis); float value = mControllerMappingHelper.scaleAxis(input, axis, origValue); if (Math.abs(value) > 0.5f) { // It is common to have multiple axis with the same physical input. For example, // shoulder butters are provided as both AXIS_LTRIGGER and AXIS_BRAKE. // To handle this, we ignore an axis motion that's the exact same as a motion // we already saw. This way, we ignore axis with two names, but catch the case // where a joystick is moved in two directions. // ref: bottom of https://developer.android.com/training/game-controllers/controller-input.html if (value != axisMoveValue) { axisMoveValue = value; numMovedAxis++; lastMovedRange = range; lastMovedDir = value < 0.0f ? '-' : '+'; } } } // If only one axis moved, that's the winner. if (numMovedAxis == 1) { mWaitingForEvent = false; saveMotionInput(input, lastMovedRange, lastMovedDir); } } return true; }
Example 16
Source File: ApiWrapper.java From JotaTextEditor with Apache License 2.0 | 4 votes |
static public int getSourceOfEvent( MotionEvent event ) { return event.getSource(); }
Example 17
Source File: Instrumentation.java From AndroidComponentPlugin with Apache License 2.0 | 3 votes |
/** * Dispatch a pointer event. Finished at some point after the recipient has * returned from its event processing, though it may <em>not</em> have * completely finished reacting from the event -- for example, if it needs * to update its display as a result, it may still be in the process of * doing that. * * @param event A motion event describing the pointer action. (As noted in * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use * {@link SystemClock#uptimeMillis()} as the timebase. */ public void sendPointerSync(MotionEvent event) { validateNotAppThread(); if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { event.setSource(InputDevice.SOURCE_TOUCHSCREEN); } InputManager.getInstance().injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); }
Example 18
Source File: Instrumentation.java From android_9.0.0_r45 with Apache License 2.0 | 3 votes |
/** * Dispatch a trackball event. Finished at some point after the recipient has * returned from its event processing, though it may <em>not</em> have * completely finished reacting from the event -- for example, if it needs * to update its display as a result, it may still be in the process of * doing that. * * @param event A motion event describing the trackball action. (As noted in * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use * {@link SystemClock#uptimeMillis()} as the timebase. */ public void sendTrackballEventSync(MotionEvent event) { validateNotAppThread(); if ((event.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { event.setSource(InputDevice.SOURCE_TRACKBALL); } InputManager.getInstance().injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); }
Example 19
Source File: Instrumentation.java From AndroidComponentPlugin with Apache License 2.0 | 3 votes |
/** * Dispatch a trackball event. Finished at some point after the recipient has * returned from its event processing, though it may <em>not</em> have * completely finished reacting from the event -- for example, if it needs * to update its display as a result, it may still be in the process of * doing that. * * @param event A motion event describing the trackball action. (As noted in * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use * {@link SystemClock#uptimeMillis()} as the timebase. */ public void sendTrackballEventSync(MotionEvent event) { validateNotAppThread(); if ((event.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { event.setSource(InputDevice.SOURCE_TRACKBALL); } InputManager.getInstance().injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); }
Example 20
Source File: MotionEventUtils.java From libcommon with Apache License 2.0 | 2 votes |
/** * 指定したMotionEventの入力ソースが指定したクラスかどうかをチェック * @param event * @param sourceClass * @return */ public static boolean isFromSource(@NonNull final MotionEvent event, final int sourceClass) { return (event.getSource() & sourceClass) == sourceClass; }