List of usage examples for android.view MotionEvent getSource
@Override public final int getSource()
From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java
@Override public boolean onGenericMotionEvent(MotionEvent event) { // Ignore TOOL_TYPE_FINGER events that come from the touchscreen with HOVER type action // which cause pointer jumping trouble in simulated touchpad for some devices. int a = event.getAction(); if (!((a == MotionEvent.ACTION_HOVER_ENTER || a == MotionEvent.ACTION_HOVER_EXIT || a == MotionEvent.ACTION_HOVER_MOVE) && event.getSource() == InputDevice.SOURCE_TOUCHSCREEN && event.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER)) { try {/*from ww w .j av a2s . c om*/ return inputHandler.onTouchEvent(event); } catch (NullPointerException e) { } } return super.onGenericMotionEvent(event); }
From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private void processJoystickInput(MotionEvent event, int historyPos) { float hatX = 0.0f; InputDevice.MotionRange range = event.getDevice().getMotionRange(MotionEvent.AXIS_HAT_X, event.getSource()); if (range != null) { if (historyPos >= 0) { hatX = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_X, historyPos)); } else {// w ww . j a va 2 s . co m hatX = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_HAT_X)); } } float hatY = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_HAT_Y, event.getSource()); if (range != null) { if (historyPos >= 0) { hatY = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_Y, historyPos)); } else { hatY = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_HAT_Y)); } } float joyX = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_X, event.getSource()); if (range != null) { if (historyPos >= 0) { joyX = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_X, historyPos)); } else { joyX = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_X)); } } float joyY = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_Y, event.getSource()); if (range != null) { if (historyPos >= 0) { joyY = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_Y, historyPos)); } else { joyY = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_Y)); } } float joy2X = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_Z, event.getSource()); if (range != null) { if (historyPos >= 0) { joy2X = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_Z, historyPos)); } else { joy2X = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_Z)); } } float joy2Y = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_RZ, event.getSource()); if (range != null) { if (historyPos >= 0) { joy2Y = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_RZ, historyPos)); } else { joy2Y = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_RZ)); } } if (mAnalogStickPref == 0) { mMouseThread.setCoord( (int) ((Math.abs(joyX * 32.0f) > DEADZONE) ? (-joyX * 32.0f * mMouseSensitivityX) : 0), (int) ((Math.abs(joyY * 32.0f) > DEADZONE) ? (-joyY * 32.0f * mMouseSensitivityY) : 0)); DosBoxControl.nativeJoystick((int) ((joy2X * 256.0f) + mJoyCenterX), (int) ((joy2Y * 256.0f) + mJoyCenterY), ACTION_MOVE, -1); } else { mMouseThread.setCoord( (int) ((Math.abs(joy2X * 32.0f) > DEADZONE) ? (-joy2X * 32.0f * mMouseSensitivityX) : 0), (int) ((Math.abs(joy2Y * 32.0f) > DEADZONE) ? (-joy2Y * 32.0f * mMouseSensitivityY) : 0)); DosBoxControl.nativeJoystick((int) ((joyX * 256.0f) + mJoyCenterX), (int) ((joyY * 256.0f) + mJoyCenterY), ACTION_MOVE, -1); } // Handle all other keyevents int value = 0; int tKeyCode = MAP_NONE; if (hatX < 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_LEFT); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift); } } hatXlast = hatX; } else if (hatX > 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_RIGHT); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift); } } hatXlast = hatX; } else { // released if (hatX != hatXlast) { if (hatXlast < 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_LEFT); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_LEFT)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt, mModifierShift); } } } else if (hatXlast > 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_RIGHT); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_RIGHT)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt, mModifierShift); } } } } hatXlast = hatX; } if (hatY < 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_UP); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift); } } hatYlast = hatY; } else if (hatY > 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_DOWN); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift); } } hatYlast = hatY; } else { // released if (hatY != hatYlast) { if (hatYlast < 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_UP); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_UP)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt, mModifierShift); } } } else if (hatYlast > 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_DOWN); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_DOWN)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt, mModifierShift); } } } } hatYlast = hatY; } }
From source file:com.android.launcher2.PagedView.java
@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;/*from w ww .ja v a 2s .co m*/ hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); } else { vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL); hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL); } if (hscroll != 0 || vscroll != 0) { if (hscroll > 0 || vscroll > 0) { scrollRight(); } else { scrollLeft(); } return true; } } } } return super.onGenericMotionEvent(event); }
From source file:com.hippo.widget.BothScrollView.java
@Override public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: { if (!mIsBeingDragged) { if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) { final float hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); if (hscroll != 0) { final int delta = (int) (hscroll * getHorizontalScrollFactor()); final int range = getHorizontalScrollRange(); int oldScrollX = getScrollX(); int newScrollX = oldScrollX + delta; if (newScrollX < 0) { newScrollX = 0; } else if (newScrollX > range) { newScrollX = range; }//from w ww . j a v a 2 s . co m if (newScrollX != oldScrollX) { super.scrollTo(newScrollX, getScrollY()); return true; } } } else { final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); if (vscroll != 0) { final int delta = (int) (vscroll * getVerticalScrollFactor()); final int range = getVerticalScrollRange(); int oldScrollY = getScrollY(); int newScrollY = oldScrollY - delta; if (newScrollY < 0) { newScrollY = 0; } else if (newScrollY > range) { newScrollY = range; } if (newScrollY != oldScrollY) { super.scrollTo(getScrollX(), newScrollY); return true; } } } } } } } return super.onGenericMotionEvent(event); }
From source file:cc.flydev.launcher.Page.java
@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;// w w w. ja v a2s. c o m 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 = isLayoutRtl() ? (hscroll < 0 || vscroll < 0) : (hscroll > 0 || vscroll > 0); if (isForwardScroll) { scrollRight(); } else { scrollLeft(); } return true; } } } } return super.onGenericMotionEvent(event); }
From source file:com.n2hsu.launcher.Page.java
@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;/*from www. j av a 2s . com*/ 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 = isLayoutRtl() ? (hscroll < 0 || vscroll < 0) : (hscroll > 0 || vscroll > 0); if (isForwardScroll) { scrollRight(); } else { scrollLeft(); } return true; } } } } return super.onGenericMotionEvent(event); }
From source file:com.glview.widget.AbsListView.java
@Override public boolean onGenericMotionEvent(MotionEvent event) { 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; }//from w w w.ja v a 2 s.co m } } } } } return super.onGenericMotionEvent(event); }
From source file:com.example.libwidgettv.bak.AbsListView.java
@Override public boolean onGenericMotionEvent(MotionEvent event) { 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 * 0.3); if (!trackMotionScroll(delta, delta)) { return true; }/* w ww .j a v a 2 s. c o m*/ } } } } } return super.onGenericMotionEvent(event); }
From source file:com.appunite.list.AbsHorizontalListView.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override//from w ww . j a v a2s. c om public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: { if (mTouchMode == TOUCH_MODE_REST) { final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL); if (hscroll != 0) { final int delta = (int) (hscroll * getHorizontalScrollFactorUnhide()); if (!trackMotionScroll(delta, delta)) { return true; } } } } } } return super.onGenericMotionEvent(event); }