Java Code Examples for android.view.MotionEvent#getAxisValue()
The following examples show how to use
android.view.MotionEvent#getAxisValue() .
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: StackView.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: { final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); if (vscroll < 0) { pacedScroll(false); return true; } else if (vscroll > 0) { pacedScroll(true); return true; } } } } return super.onGenericMotionEvent(event); }
Example 2
Source File: AbsHListView.java From Klyph with MIT License | 6 votes |
@TargetApi(12) @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 hscroll = event.getAxisValue( MotionEvent.AXIS_HSCROLL ); if ( hscroll != 0 ) { final int delta = (int) ( hscroll * getHorizontalScrollFactor() ); if ( !trackMotionScroll( delta, delta ) ) { return true; } } } } } } return super.onGenericMotionEvent( event ); }
Example 3
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 4
Source File: FullscreenActivity.java From androidtv-VisualGameController with Apache License 2.0 | 6 votes |
/** * Get centered position for axis input by considering flat area. * * @param event * @param device * @param axis * @return */ private float getCenteredAxis(MotionEvent event, InputDevice device, int axis) { InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); // A joystick at rest does not always report an absolute position of // (0,0). Use the getFlat() method to determine the range of values // bounding the joystick axis center. if (range != null) { float flat = range.getFlat(); float value = event.getAxisValue(axis); // Ignore axis values that are within the 'flat' region of the // joystick axis center. if (Math.abs(value) > flat) { return value; } } return 0; }
Example 5
Source File: HdrViewfinderActivity.java From android-HdrViewfinder with Apache License 2.0 | 6 votes |
@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (mRenderMode == ViewfinderProcessor.MODE_NORMAL) return false; float xPosition = e1.getAxisValue(MotionEvent.AXIS_X); float width = mPreviewView.getWidth(); float height = mPreviewView.getHeight(); float xPosNorm = xPosition / width; float yDistNorm = distanceY / height; final float ACCELERATION_FACTOR = 8; double scaleFactor = Math.pow(2.f, yDistNorm * ACCELERATION_FACTOR); // Even on left, odd on right if (xPosNorm > 0.5) { mOddExposure *= scaleFactor; } else { mEvenExposure *= scaleFactor; } setHdrBurst(); return true; }
Example 6
Source File: MyView.java From mil-sym-android with Apache License 2.0 | 6 votes |
/** * assumes utility extents have been set before call * @param event */ private static void displayGeo(MotionEvent event) { double sizeSquare = Math.abs(utility.rightLongitude - utility.leftLongitude); if (sizeSquare > 180) { sizeSquare = 360 - sizeSquare; } double scale = 541463 * sizeSquare; Point2D ptPixels = null; Point2D ptGeo = null; IPointConversion converter = null; converter = new PointConverter(utility.leftLongitude, utility.upperLatitude, scale); Point pt=new Point((int) event.getAxisValue(MotionEvent.AXIS_X), (int) event.getAxisValue(MotionEvent.AXIS_Y)); Point2D pt2d=new Point2D.Double(pt.x,pt.y); ptGeo=converter.PixelsToGeo(pt2d); int n = Log.i("onTouchEvent", "longitude = " + Double.toString(ptGeo.getX())); }
Example 7
Source File: GamepadController.java From crazyflie-android-client with GNU General Public License v2.0 | 6 votes |
public void dealWithMotionEvent(MotionEvent event){ //Log.i(LOG_TAG, "Input device: " + event.getDevice().getName()); /*if axis has a range of 1 (0 -> 1) instead of 2 (-1 -> 0) do not invert axis value, this is necessary for analog R1 (Brake) or analog R2 (Gas) shoulder buttons on PS3 controller*/ if (event != null) { InputDevice device = event.getDevice(); if (device != null) { mRightAnalogYAxisInvertFactor = (device.getMotionRange(mRightAnalogYAxis).getRange() == 1) ? 1 : -1; mLeftAnalogYAxisInvertFactor = (device.getMotionRange(mLeftAnalogYAxis).getRange() == 1) ? 1 : -1; } else { Log.w(LOG_TAG, "event.getDevice() == null! => event.getClass(): " + event.getClass()); } // default axis are set to work with PS3 controller mControls.setRightAnalogX((float) event.getAxisValue(mRightAnalogXAxis)); mControls.setRightAnalogY((float) (event.getAxisValue(mRightAnalogYAxis)) * mRightAnalogYAxisInvertFactor); mControls.setLeftAnalogX((float) event.getAxisValue(mLeftAnalogXAxis)); mControls.setLeftAnalogY((float) (event.getAxisValue(mLeftAnalogYAxis)) * mLeftAnalogYAxisInvertFactor); mSplit_axis_yaw_right = (float) event.getAxisValue(mSplitAxisYawRightAxis); mSplit_axis_yaw_left = (float) event.getAxisValue(mSplitAxisYawLeftAxis); } else { Log.w(LOG_TAG, "event == null!"); } }
Example 8
Source File: PlaybackActivity.java From tv-samples with Apache License 2.0 | 6 votes |
@Override public boolean onGenericMotionEvent(MotionEvent event) { // This method will handle gamepad events. if (event.getAxisValue(MotionEvent.AXIS_LTRIGGER) > GAMEPAD_TRIGGER_INTENSITY_ON && !gamepadTriggerPressed) { mPlaybackFragment.rewind(); gamepadTriggerPressed = true; } else if (event.getAxisValue(MotionEvent.AXIS_RTRIGGER) > GAMEPAD_TRIGGER_INTENSITY_ON && !gamepadTriggerPressed) { mPlaybackFragment.fastForward(); gamepadTriggerPressed = true; } else if (event.getAxisValue(MotionEvent.AXIS_LTRIGGER) < GAMEPAD_TRIGGER_INTENSITY_OFF && event.getAxisValue(MotionEvent.AXIS_RTRIGGER) < GAMEPAD_TRIGGER_INTENSITY_OFF) { gamepadTriggerPressed = false; } return super.onGenericMotionEvent(event); }
Example 9
Source File: PlaybackActivity.java From androidtv-Leanback with Apache License 2.0 | 6 votes |
@Override public boolean onGenericMotionEvent(MotionEvent event) { // This method will handle gamepad events. if (event.getAxisValue(MotionEvent.AXIS_LTRIGGER) > GAMEPAD_TRIGGER_INTENSITY_ON && !gamepadTriggerPressed) { mPlaybackFragment.rewind(); gamepadTriggerPressed = true; } else if (event.getAxisValue(MotionEvent.AXIS_RTRIGGER) > GAMEPAD_TRIGGER_INTENSITY_ON && !gamepadTriggerPressed) { mPlaybackFragment.fastForward(); gamepadTriggerPressed = true; } else if (event.getAxisValue(MotionEvent.AXIS_LTRIGGER) < GAMEPAD_TRIGGER_INTENSITY_OFF && event.getAxisValue(MotionEvent.AXIS_RTRIGGER) < GAMEPAD_TRIGGER_INTENSITY_OFF) { gamepadTriggerPressed = false; } return super.onGenericMotionEvent(event); }
Example 10
Source File: AndroidJoystickJoyInput14.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public boolean onGenericMotion(MotionEvent event) { boolean consumed = false; // logger.log(Level.INFO, "onGenericMotion event: {0}", event); event.getDeviceId(); event.getSource(); // logger.log(Level.INFO, "deviceId: {0}, source: {1}", new Object[]{event.getDeviceId(), event.getSource()}); AndroidJoystick joystick = joystickIndex.get(event.getDeviceId()); if (joystick != null) { for (int androidAxis: joystick.getAndroidAxes()) { String axisName = MotionEvent.axisToString(androidAxis); float value = event.getAxisValue(androidAxis); int action = event.getAction(); if (action == MotionEvent.ACTION_MOVE) { // logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}", // new Object[]{androidAxis, axisName, value}); JoystickAxis axis = joystick.getAxis(androidAxis); if (axis != null) { // logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}, deadzone: {3}", // new Object[]{androidAxis, axisName, value, axis.getDeadZone()}); JoyAxisEvent axisEvent = new JoyAxisEvent(axis, value); joyInput.addEvent(axisEvent); consumed = true; } else { // logger.log(Level.INFO, "axis was null for axisName: {0}", axisName); } } else { // logger.log(Level.INFO, "action: {0}", action); } } } return consumed; }
Example 11
Source File: ServoPanZoomController.java From FirefoxReality with Mozilla Public License 2.0 | 5 votes |
private boolean handleScrollEvent(MotionEvent event) { if (!mAttached) { mQueuedEvents.add(new Pair(EVENT_SOURCE_SCROLL, event)); return false; } if (event.getPointerCount() <= 0) { return false; } final MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords(); event.getPointerCoords(0, coords); mSession.getSurfaceBounds(mTempRect); final float x = coords.x - mTempRect.left; final float y = coords.y - mTempRect.top; final float hScroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL) * mPointerScrollFactor; final float vScroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL) * mPointerScrollFactor; if (!mIsScrolling) { mSession.scrollStart((int) hScroll, (int) vScroll, (int) x, (int) y); } else { mSession.scroll((int) hScroll, (int) vScroll, (int) x, (int) y); } mIsScrolling = true; return true; }
Example 12
Source File: GamepadController.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
/** * Updates the tracked state values of this controller in response to a motion input event. */ public void handleMotionEvent(MotionEvent motionEvent) { mJoystickPositions[JOYSTICK_1][AXIS_X] = motionEvent.getAxisValue(MotionEvent.AXIS_X); mJoystickPositions[JOYSTICK_1][AXIS_Y] = motionEvent.getAxisValue(MotionEvent.AXIS_Y); // The X and Y axes of the second joystick on a controller are mapped to the // MotionEvent AXIS_Z and AXIS_RZ values, respectively. mJoystickPositions[JOYSTICK_2][AXIS_X] = motionEvent.getAxisValue(MotionEvent.AXIS_Z); mJoystickPositions[JOYSTICK_2][AXIS_Y] = motionEvent.getAxisValue(MotionEvent.AXIS_RZ); }
Example 13
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 14
Source File: GamepadDevice.java From 365browser with Apache License 2.0 | 5 votes |
/** * Handles motion event from the gamepad device. * @return True if the motion event from the gamepad device has been consumed. */ public boolean handleMotionEvent(MotionEvent event) { // Ignore event if it is not a standard gamepad motion event. if (!GamepadList.isGamepadEvent(event)) return false; // Update axes values. for (int i = 0; i < mAxes.length; i++) { int axis = mAxes[i]; mRawAxes[axis] = event.getAxisValue(axis); } mTimestamp = event.getEventTime(); return true; }
Example 15
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 16
Source File: ContentViewCore.java From 365browser with Apache License 2.0 | 5 votes |
/** * Removes noise from joystick motion events. */ private static float getFilteredAxisValue(MotionEvent event, int axis) { final float kJoystickScrollDeadzone = 0.2f; float axisValWithNoise = event.getAxisValue(axis); if (Math.abs(axisValWithNoise) > kJoystickScrollDeadzone) return axisValWithNoise; return 0f; }
Example 17
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 18
Source File: ApiWrapper.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
static public float getAxisValue ( MotionEvent event , int axis) { return event.getAxisValue(axis); }
Example 19
Source File: ChooseTime.java From zidoorecorder with Apache License 2.0 | 4 votes |
@Override public boolean onGenericMotion(View v, MotionEvent event) { // TODO Auto-generated method stub getCurr(); final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL); System.out.println("vscroll=== "+vscroll); if(v==btn6){ if(vscroll==up){ upDay(); } if(vscroll==down){ downDay(); } } if(v==btn3){ if(vscroll==up){ upHour(); } if(vscroll==down){ downHour(); } } if(v==btn4){ if(vscroll==up){ upMinute(); } if(vscroll==down){ downMinute(); } } if(v==btn5){ if(vscroll==up){ upSecond(); } if(vscroll==down){ downSecond(); } } return false; }
Example 20
Source File: VideoPlayerActivity.java From VCL-Android with Apache License 2.0 | 4 votes |
@TargetApi(12) //only active for Android 3.1+ public boolean dispatchGenericMotionEvent(MotionEvent event){ if (mIsLoading) return false; //Check for a joystick event if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != InputDevice.SOURCE_JOYSTICK || event.getAction() != MotionEvent.ACTION_MOVE) return false; InputDevice mInputDevice = event.getDevice(); float dpadx = event.getAxisValue(MotionEvent.AXIS_HAT_X); float dpady = event.getAxisValue(MotionEvent.AXIS_HAT_Y); if (mInputDevice == null || Math.abs(dpadx) == 1.0f || Math.abs(dpady) == 1.0f) return false; float x = AndroidDevices.getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_X); float y = AndroidDevices.getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_Y); float rz = AndroidDevices.getCenteredAxis(event, mInputDevice, MotionEvent.AXIS_RZ); if (System.currentTimeMillis() - mLastMove > JOYSTICK_INPUT_DELAY){ if (Math.abs(x) > 0.3){ if (BuildConfig.tv) { navigateDvdMenu(x > 0.0f ? KeyEvent.KEYCODE_DPAD_RIGHT : KeyEvent.KEYCODE_DPAD_LEFT); } else seekDelta(x > 0.0f ? 10000 : -10000); } else if (Math.abs(y) > 0.3){ if (BuildConfig.tv) navigateDvdMenu(x > 0.0f ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DPAD_DOWN); else { if (mIsFirstBrightnessGesture) initBrightnessTouch(); changeBrightness(-y / 10f); } } else if (Math.abs(rz) > 0.3){ mVol = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); int delta = -(int) ((rz / 7) * mAudioMax); int vol = (int) Math.min(Math.max(mVol + delta, 0), mAudioMax); setAudioVolume(vol); } mLastMove = System.currentTimeMillis(); } return true; }