List of usage examples for android.view MotionEvent AXIS_Y
int AXIS_Y
To view the source code for android.view MotionEvent AXIS_Y.
Click Source Link
From source file:tv.piratemedia.flightcontroller.ControlActivity.java
private void processJoystickInput(MotionEvent event, int historyPos) { InputDevice mInputDevice = event.getDevice(); float x = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_X, historyPos); float y = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_Y, historyPos); float z = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_Z, historyPos); float rz = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_RZ, historyPos); float l = getTriggerValue(event, mInputDevice, MotionEvent.AXIS_LTRIGGER, historyPos); float r = getTriggerValue(event, mInputDevice, MotionEvent.AXIS_RTRIGGER, historyPos); if (lStickCache[0] != x || lStickCache[1] != y) { fragment.LeftStick.setPosition(x, y); lStickCache[0] = x;// w w w . j ava2 s. c o m lStickCache[1] = y; } if (rStickCache[0] != z || rStickCache[1] != rz) { fragment.RightStick.setPosition(z, rz); rStickCache[0] = z; rStickCache[1] = rz; } if (0f != l || 0f != r) { int range = fragment.throttle.getMax(); float throttle = (float) fragment.throttle.getProgress() / range; if (l > 0) { if (l > triggerCache[0]) { throttle += (l - triggerCache[0]) / 2f; } } else { if (r > triggerCache[1]) { throttle -= (r - triggerCache[1]) / 2f; } } fragment.throttle.setProgress((int) (throttle * (float) range)); fragment.throttle.invalidate(); } triggerCache[0] = l; triggerCache[1] = r; }
From source file:com.vladstirbu.cordova.Gamepad.java
/** * @param cordova The context of the main Activity. * @param webView The associated CordovaWebView. *///from w w w .j av a2s. co m @Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.map.put("KEYCODE_BUTTON_A", 0); this.map.put("KEYCODE_BUTTON_B", 1); this.map.put("KEYCODE_BUTTON_Y", 3); this.map.put("KEYCODE_BUTTON_X", 2); this.map.put("KEYCODE_BUTTON_L1", 4); this.map.put("KEYCODE_BUTTON_R1", 5); this.map.put("KEYCODE_BUTTON_L2", 6); this.map.put("KEYCODE_BUTTON_R2", 7); this.map.put("KEYCODE_SPACE", 8); this.map.put("KEYCODE_SELECT", 8); this.map.put("KEYCODE_ENTER", 9); this.map.put("KEYCODE_START", 9); this.map.put("KEYCODE_BUTTON_THUMBL", 10); this.map.put("KEYCODE_BUTTON_THUMBR", 11); this.map.put("KEYCODE_DPAD_UP", 12); this.map.put("KEYCODE_DPAD_DOWN", 13); this.map.put("KEYCODE_DPAD_LEFT", 14); this.map.put("KEYCODE_DPAD_RIGHT", 15); this.map.put("KEYCODE_BACK", 16); this.map.put("KEYCODE_BUTTON_MODE", 16); this.webView.setFocusable(true); this.webView.setFocusableInTouchMode(true); this.webView.requestFocus(); this.webView.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { //Log.v("Keyboards", String.valueOf(InputDevice.getDeviceIds().length)); //Log.v("Input", InputDevice.getDevice(1).getName()); //Log.v("Input", String.valueOf(InputDevice.getDevice(1).getSources())); //Log.v("Device id", String.valueOf(event.getDeviceId())); //Log.v("Source id", String.valueOf(event.getSource())); //Log.v("Input device", String.valueOf(InputDevice.getDevice(event.getDeviceId()).getName())); Log.v("KEY", String.valueOf(event.getScanCode())); Log.v("KEY", KeyEvent.keyCodeToString(keyCode)); //Log.v("GamePad", String.valueOf(KeyEvent.isGamepadButton(keyCode))); String jsStr = jsString(keyCode, event); if (!jsStr.isEmpty()) { self.webView.sendJavascript(jsStr); } return true; } }); this.webView.setOnGenericMotionListener(new OnGenericMotionListener() { public boolean onGenericMotion(View v, MotionEvent event) { if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) { if (event.getAction() == MotionEvent.ACTION_MOVE) { // process the joystick movement... JSONObject data = new JSONObject(); JSONArray axes = new JSONArray(); try { axes.put(event.getAxisValue(MotionEvent.AXIS_X)); axes.put(event.getAxisValue(MotionEvent.AXIS_Y)); axes.put(event.getAxisValue(MotionEvent.AXIS_Z)); axes.put(event.getAxisValue(MotionEvent.AXIS_RZ)); data.put("deviceId", event.getDeviceId()); data.put("axes", axes); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); try { data.put("deviceId", event.getDeviceId()); data.put("button", 6); data.put("value", event.getAxisValue(MotionEvent.AXIS_LTRIGGER)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); try { data.put("deviceId", event.getDeviceId()); data.put("button", 7); data.put("value", event.getAxisValue(MotionEvent.AXIS_RTRIGGER)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X); float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y); try { data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 14); data.put("value", hatX < 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 15); data.put("value", hatX > 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); } catch (JSONException e) { } try { data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 12); data.put("value", hatY < 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 13); data.put("value", hatY > 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); } catch (JSONException e) { } } Log.v("MOTION", event.toString()); return true; } return false; } }); Log.v("GamepadButtons", "initialized"); }
From source file:org.gearvrf.controls.Worm.java
public void interactWithDPad() { if (!ScaleWorm.animPlaying) { if (GamepadInput.getCenteredAxis(MotionEvent.AXIS_HAT_X) >= 1 || GamepadInput.getCenteredAxis(MotionEvent.AXIS_X) >= 1 || GamepadInput.getCenteredAxis(MotionEvent.AXIS_RX) >= 1) { rotateAroundCamera(.1f, -5f); rotateWorm(MovementDirection.Right); }//from w w w.jav a 2 s . c o m if (GamepadInput.getCenteredAxis(MotionEvent.AXIS_HAT_X) <= -1 || GamepadInput.getCenteredAxis(MotionEvent.AXIS_X) <= -1 || GamepadInput.getCenteredAxis(MotionEvent.AXIS_RX) <= -1) { rotateAroundCamera(.1f, 5f); rotateWorm(MovementDirection.Left); } if (GamepadInput.getCenteredAxis(MotionEvent.AXIS_HAT_Y) >= 1 || GamepadInput.getCenteredAxis(MotionEvent.AXIS_Y) >= 1 || GamepadInput.getCenteredAxis(MotionEvent.AXIS_RY) >= 1) { moveAlongCameraVector(.1f, -.225f); rotateWorm(MovementDirection.Down); } if (GamepadInput.getCenteredAxis(MotionEvent.AXIS_HAT_Y) <= -1 || GamepadInput.getCenteredAxis(MotionEvent.AXIS_Y) <= -1 || GamepadInput.getCenteredAxis(MotionEvent.AXIS_RY) <= -1) { moveAlongCameraVector(.1f, .225f); rotateWorm(MovementDirection.Up); } } }
From source file:com.amazon.appstream.fireclient.FireClientActivity.java
/** * A "generic motion event" includes joystick and mouse motion * when the mouse button isn't down. In our simple sample, we're * not handling the joystick, but this is where any such code * would live./*from w w w . j av a2 s . c o m*/ * * This will only ever be called in HONEYCOMB_MR1 (12) or later, so I'm marking the * function using \@TargetApi to allow it to call the super. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override public boolean dispatchGenericMotionEvent(MotionEvent event) { if (event.getSource() == InputDevice.SOURCE_MOUSE) { event.getPointerCoords(0, mCoordHolder); switch (event.getAction()) { case MotionEvent.ACTION_HOVER_MOVE: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, 0); break; default: return super.dispatchGenericMotionEvent(event); } return true; } else if (event.getSource() == InputDevice.SOURCE_JOYSTICK) { Log.v(TAG, "Joystick event:" + event.toString()); if (!mInitializedJoystick) { mInitializedJoystick = true; InputDevice joystick = InputDevice.getDevice(event.getDeviceId()); InputDevice.MotionRange lThumbX = joystick.getMotionRange(MotionEvent.AXIS_X, InputDevice.SOURCE_JOYSTICK); InputDevice.MotionRange lThumbY = joystick.getMotionRange(MotionEvent.AXIS_Y, InputDevice.SOURCE_JOYSTICK); InputDevice.MotionRange rThumbX = joystick.getMotionRange(MotionEvent.AXIS_Z); InputDevice.MotionRange rThumbY = joystick.getMotionRange(MotionEvent.AXIS_RZ); InputDevice.MotionRange rTrigger = joystick.getMotionRange(MotionEvent.AXIS_GAS); if (rTrigger == null) { rTrigger = joystick.getMotionRange(MotionEvent.AXIS_RTRIGGER); mRTrigger = MotionEvent.AXIS_RTRIGGER; } InputDevice.MotionRange lTrigger = joystick.getMotionRange(MotionEvent.AXIS_BRAKE); if (lTrigger == null) { lTrigger = joystick.getMotionRange(MotionEvent.AXIS_LTRIGGER); mLTrigger = MotionEvent.AXIS_LTRIGGER; } List<InputDevice.MotionRange> ranges = joystick.getMotionRanges(); InputDevice.MotionRange dPad = null; String name = joystick.getName(); /* The Amazon Fire Game Controller follows the NVidia standard of sending AXIS_HAT_X/AXIS_HAT_Y results when the user hits the D-Pad. Only if we return false from dispatchGenericMotionEvent() will it then send DPAD keycodes. But the most popular Android joystick on the market at this time, the Nyko Playpad Pro, returns AXIS_HAT_X/AXIS_HAT_Y results when the left analog stick hits its extremes, meaning that the analog stick will generate DPAD keys if we return false. The Nyko generates DPAD keys directly for the DPAD controller. So we have two incompatible standards fighting with each other. Probably the safest thing to do would be to ask the user to press on their DPAD and see what messages we get, but that is beyond the scope of this example code. */ if (name.equals("Amazon Fire Game Controler")) { for (int i = 0; i < ranges.size(); ++i) { InputDevice.MotionRange range = ranges.get(i); int axis = range.getAxis(); if (axis == MotionEvent.AXIS_HAT_X || axis == MotionEvent.AXIS_HAT_Y) { dPad = ranges.get(i); break; } } } JoystickHelper.joystickDeadZones(lTrigger, rTrigger, lThumbX, lThumbY, rThumbX, rThumbY, dPad); } float lThumbX = event.getAxisValue(MotionEvent.AXIS_X); float lThumbY = -event.getAxisValue(MotionEvent.AXIS_Y); float rThumbX = event.getAxisValue(MotionEvent.AXIS_Z); float rThumbY = -event.getAxisValue(MotionEvent.AXIS_RZ); float lTrigger = event.getAxisValue(mLTrigger); float rTrigger = event.getAxisValue(mRTrigger); float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X); float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y); JoystickHelper.setJoystickState(lTrigger, rTrigger, lThumbX, lThumbY, rThumbX, rThumbY, hatX, hatY); return true; } return super.dispatchGenericMotionEvent(event); }
From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java
private void processJoystickInput(MotionEvent event, int historyPos) { InputDevice mInputDevice = event.getDevice(); // Calculate the horizontal distance to move by // using the input value from one of these physical controls: // the left control stick, hat axis, or the right control stick. float x = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_X, historyPos); if (x == 0) { x = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_HAT_X, historyPos); }/*from ww w . j a v a 2s. c o m*/ if (x == 0) { x = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_Z, historyPos); } // Calculate the vertical distance to move by // using the input value from one of these physical controls: // the left control stick, hat switch, or the right control stick. float y = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_Y, historyPos); if (y == 0) { y = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_HAT_Y, historyPos); } if (y == 0) { y = getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_RZ, historyPos); } deltaJoystick = ((Math.abs(oldJoystickX - x) >= 0.1) || (Math.abs(oldJoystickY - y) >= 0.1)); JoystickData joystickDataX = new JoystickData("x", x); JoystickData joystickDataY = new JoystickData("y", y); if (deltaJoystick) { mPitch.setText("y is :" + y); oldJoystickX = x; oldJoystickY = y; if (client != null) { try { //client.send("servo01", "moveTo",(roll+90.0)); client.send("joystick", "publishJoystickInput", joystickDataX); client.send("joystick", "publishJoystickInput", joystickDataY); } catch (IOException e) { e.printStackTrace(); } } } }
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 {/*from ww w . j a v a 2 s .c om*/ 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.doubleTwist.drawerlib.ADrawerLayout.java
private boolean canScroll(int axis, float diff) { if (axis == MotionEvent.AXIS_X) { if (mDrawerState.mActiveDrawer == BOTTOM_DRAWER || mDrawerState.mActiveDrawer == TOP_DRAWER) return false; else if (diff < 0) return !(mDrawerState.mActiveDrawer == NO_DRAWER && !isScrollingForSectionEnabled(RIGHT_DRAWER)); else//from www . j a v a 2 s . c o m return !(mDrawerState.mActiveDrawer == NO_DRAWER && !isScrollingForSectionEnabled(LEFT_DRAWER)); } else if (axis == MotionEvent.AXIS_Y) { if (mDrawerState.mActiveDrawer == LEFT_DRAWER || mDrawerState.mActiveDrawer == RIGHT_DRAWER) return false; else if (diff < 0) return !(mDrawerState.mActiveDrawer == NO_DRAWER && !isScrollingForSectionEnabled(BOTTOM_DRAWER)); else return !(mDrawerState.mActiveDrawer == NO_DRAWER && !isScrollingForSectionEnabled(TOP_DRAWER)); } else { throw new IllegalArgumentException(); } }
From source file:com.doubleTwist.drawerlib.ADrawerLayout.java
private int preProcessScrollMotionEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: if (DEBUG_TOUCH) Log.d(TAG, "DOWN: " + ev.getX(0) + "," + ev.getY(0)); if (!mIsScrolling) { mVelocityTracker.clear();//from w w w . jav a2s . c o m mDownEvent.mCoords.x = ev.getX(0); mDownEvent.mCoords.y = ev.getY(0); mDownEvent.mPointerId = ev.getPointerId(0); if (DEBUG_TOUCH) Log.d(TAG, "SAVED: " + ev.getX(0) + "," + ev.getY(0)); } break; case MotionEvent.ACTION_MOVE: { final int ptrIdx = ev.findPointerIndex(mDownEvent.mPointerId); if (ptrIdx < 0 || ptrIdx >= ev.getPointerCount()) return -1; if (DEBUG_TOUCH) Log.d(TAG, "MOVE: " + ev.getX(ptrIdx) + "," + ev.getY(ptrIdx)); if (mIsScrolling) { return mDrawerState.mActiveDrawer; } // If the user has dragged her finger horizontally more than // the touch slop, start the scroll final float xDiff = calculateDistanceX(ev, mDownEvent); final float yDiff = calculateDistanceY(ev, mDownEvent); final float dxAbs = Math.abs(xDiff); final float dyAbs = Math.abs(yDiff); if (DEBUG_TOUCH) { Log.d(TAG, "xDiff: " + xDiff + " -- " + ev.getX(ptrIdx) + " -- " + mDownEvent.mCoords.x); Log.d(TAG, "xDiff/yDiff/dxAbs/dyAbs: " + xDiff + "/" + yDiff + "/" + dxAbs + "/" + dyAbs); Log.d(TAG, "canScrollX/canScrollY: " + canScroll(MotionEvent.AXIS_X, xDiff) + "/" + canScroll(MotionEvent.AXIS_Y, yDiff)); Log.d(TAG, "activeDrawer/scrollState: " + mDrawerState.mActiveDrawer + "/" + mDrawerState.mScrollState); } if (dxAbs > dyAbs && dxAbs > mTouchSlop && canScroll(MotionEvent.AXIS_X, xDiff)) { if (DEBUG_TOUCH) Log.d(TAG, "X axis branch"); int drawer; if (mDrawerState.mActiveDrawer == NO_DRAWER) drawer = xDiff > 0 ? LEFT_DRAWER : RIGHT_DRAWER; else drawer = mDrawerState.mActiveDrawer; if (!isInitialPositionValidForDrawer(mDownEvent, drawer)) drawer = -1; return drawer; } if (dyAbs > dxAbs && dyAbs > mTouchSlop && canScroll(MotionEvent.AXIS_Y, yDiff)) { if (DEBUG_TOUCH) Log.d(TAG, "Y axis branch"); int drawer; if (mDrawerState.mActiveDrawer == NO_DRAWER) drawer = yDiff > 0 ? TOP_DRAWER : BOTTOM_DRAWER; else drawer = mDrawerState.mActiveDrawer; if (!isInitialPositionValidForDrawer(mDownEvent, drawer)) drawer = -1; return drawer; } break; } } return -1; }
From source file:jmri.enginedriver.throttle.java
@Override public boolean dispatchGenericMotionEvent(android.view.MotionEvent event) { //Log.d("Engine_Driver", "dgme " + event.getAction()); // if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { if (!whichGamePadMode.equals(WHICH_GAMEPAD_MODE_NONE)) { // respond to the gamepad and keyboard inputs only if the preference is set boolean acceptEvent = true; // default to assuming that we will respond to the event int action; int whichThrottle; int repeatCnt = 0; int whichGamePadIsEventFrom = findWhichGamePadEventIsFrom(event.getDeviceId(), 0); // dummy eventKeyCode if ((whichGamePadIsEventFrom > -1) && (whichGamePadIsEventFrom < gamePadDeviceIdsTested.length)) { // the event came from a gamepad if (gamePadDeviceIdsTested[getGamePadIndexFromThrottleNo( whichGamePadIsEventFrom)] != GAMEPAD_GOOD) { //if not, testing for this gamepad is not complete or has failed acceptEvent = false;//from www. j a v a 2 s . c o m } } else { acceptEvent = false; } if (acceptEvent) { float xAxis; xAxis = event.getAxisValue(MotionEvent.AXIS_X); float yAxis = event.getAxisValue(MotionEvent.AXIS_Y); float xAxis2 = event.getAxisValue(MotionEvent.AXIS_Z); float yAxis2 = event.getAxisValue(MotionEvent.AXIS_RZ); if ((xAxis != 0) || (yAxis != 0)) { action = ACTION_DOWN; } else { action = ACTION_UP; } if ((usingMultiplePads) && (whichGamePadIsEventFrom >= -1)) { // we have multiple gamepads AND the preference is set to make use of them AND the event came for a gamepad if (whichGamePadIsEventFrom >= 0) { whichThrottle = whichGamePadIsEventFrom; } else { GamepadFeedbackSound(true); return (true); } } else { whichThrottle = whichVolume; // work out which throttle the volume keys are currently set to contol... and use that one } boolean isActive = getConsist(whichThrottle).isActive(); if (action == ACTION_UP) { mGamepadAutoIncrement = false; mGamepadAutoDecrement = false; GamepadFeedbackSoundStop(); } if (yAxis == -1) { // DPAD Up Button performButtonAction(5, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (yAxis == 1) { // DPAD Down Button performButtonAction(7, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (xAxis == -1) { // DPAD Left Button performButtonAction(8, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (xAxis == 1) { // DPAD Right Button performButtonAction(6, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } if (yAxis2 == -1) { // DPAD2 Up Button performButtonAction(5, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (yAxis2 == 1) { // DPAD2 Down Button performButtonAction(7, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (xAxis2 == -1) { // DPAD2 Left Button performButtonAction(8, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } else if (xAxis2 == 1) { // DPAD2 Right Button performButtonAction(6, action, isActive, whichThrottle, whichGamePadIsEventFrom, repeatCnt); return (true); // stop processing this key } } else { // event is from a gamepad that has not finished testing. Ignore it return (true); // stop processing this key } // } } return super.dispatchGenericMotionEvent(event); }