List of usage examples for android.view MotionEvent getSource
@Override public final int getSource()
From source file:foam.jellyfish.StarwispActivity.java
@Override public boolean onGenericMotionEvent(final MotionEvent event) { //Get the player # int player = OuyaController.getPlayerNumByDeviceId(event.getDeviceId()); Log.i("starwisp", "ogme"); // Joystick//from ww w. j a va 2s . co m if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { //Get all the axis for the event float LS_X = event.getAxisValue(OuyaController.AXIS_LS_X); float LS_Y = event.getAxisValue(OuyaController.AXIS_LS_Y); float RS_X = event.getAxisValue(OuyaController.AXIS_RS_X); float RS_Y = event.getAxisValue(OuyaController.AXIS_RS_Y); float L2 = event.getAxisValue(OuyaController.AXIS_L2); float R2 = event.getAxisValue(OuyaController.AXIS_R2); Log.i("starwisp", "controller " + LS_X + " " + LS_Y + RS_X + " " + RS_Y + L2 + " " + R2); Scheme.eval("(on-fling " + LS_X * -500 + " " + LS_Y * -500 + ")"); } //Touchpad if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { //Print the pixel coordinates of the cursor Log.i("starwisp", "Cursor X: " + event.getX() + "Cursor Y: " + event.getY()); } return true; }
From source file:com.example.android.visualgamecontroller.FullscreenActivity.java
/** * Get centered position for axis input by considering flat area. * // w w w . jav a2 s .c o m * @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; }
From source file:com.afayear.android.client.view.TabPageIndicator.java
@Override public boolean onGenericMotionEvent(final MotionEvent event) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) return false; if (mTabProvider == null) return false; 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) { if (mCurrentItem + 1 < mTabProvider.getCount()) { setCurrentItem(mCurrentItem + 1); }/* w w w .j a va 2s.co m*/ } else if (vscroll > 0) { if (mCurrentItem - 1 >= 0) { setCurrentItem(mCurrentItem - 1); } } } } } return true; }
From source file:com.amazon.appstream.sampleclient.SampleClientActivity.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./* ww w .j av a2s .co 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; } return super.dispatchGenericMotionEvent(event); }
From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java
public boolean onGenericMotionEvent(MotionEvent 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(event, i); }/* ww w. j a va 2 s . co m*/ // Process the current movement sample in the batch (position -1) processJoystickInput(event, -1); return true; } return super.onGenericMotionEvent(event); }
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./* w ww . ja v a2s.c om*/ * * 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.amazon.appstream.fireclient.FireClientActivity.java
/** * A "touch event" includes mouse motion when the mouse button * is down./*from ww w. ja v a2 s .c om*/ */ @Override public boolean dispatchTouchEvent(MotionEvent event) { if (mKeyboardActive) { if (mGestureDetector.onTouchEvent(event)) { return true; } } if (super.dispatchTouchEvent(event)) return true; int flags = 0; if (event.getSource() == InputDevice.SOURCE_TOUCHSCREEN) { flags = AppStreamInterface.CET_TOUCH_FLAG; } event.getPointerCoords(0, mCoordHolder); switch (event.getAction()) { case MotionEvent.ACTION_MOVE: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, flags); break; case MotionEvent.ACTION_DOWN: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_DOWN | flags); break; case MotionEvent.ACTION_UP: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_UP | flags); break; } return true; }
From source file:org.protocoderrunner.apprunner.AppRunnerActivity.java
@Override public boolean onGenericMotionEvent(MotionEvent event) { int action = event.getAction(); int actionCode = event.getActionMasked(); ArrayList<PPadView.TouchEvent> t = new ArrayList<PPadView.TouchEvent>(); // check finger if down or up if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) { }//from ww w.j av a 2 s. c o m if (event.getSource() == MotionEvent.TOOL_TYPE_MOUSE) { // if (event.getButtonState() == ac) { // } } // get positions per finger for (int i = 0; i < event.getPointerCount(); i++) { // TouchEvent o = new TouchEvent("finger", event.getPointerId(i), // action, (int) event.getX(), // (int) event.getY()); // t.add(o); } // // FINGER 1 UP x y // FINGER 2 MOVE x y // MOUSE 3 MOVE x y // return touching; return super.onGenericMotionEvent(event); }
From source file:com.undatech.opaque.RemoteCanvasActivity.java
@Override public boolean onGenericMotionEvent(MotionEvent event) { // Ignore TOOL_TYPE_FINGER events that come from the touchscreen with y == 0.0 // which cause pointer jumping trouble for some users. if (!(event.getY() == 0.0f && event.getSource() == InputDevice.SOURCE_TOUCHSCREEN && event.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER)) { try {//from ww w . j a v a2 s . c o m return inputHandler.onTouchEvent(event); } catch (NullPointerException e) { } } return super.onGenericMotionEvent(event); }
From source file:com.goodhustle.ouyaunitybridge.OuyaUnityActivity.java
@Override public boolean onGenericMotionEvent(MotionEvent event) { // Pass to OuyaController first, then process. boolean handled = false; int playerNum = OuyaController.getPlayerNumByDeviceId(event.getDeviceId()); // Add the additional conditional that this must be a joystick event (not a pointer event). if (playerNum != DEVICE_NOT_OUYACONTROLLER_COMPATIBLE && ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0)) { handled = OuyaController.onGenericMotionEvent(event); if (mPaused) return handled || super.onGenericMotionEvent(event); // Check if this was a joystick or touch hover event try {/*from w ww . j a va 2 s . com*/ ControllerState data = playerStates[playerNum]; OuyaController c = OuyaController.getControllerByPlayer(playerNum); if (data != null) { data.AxisLSX = c.getAxisValue(OuyaController.AXIS_LS_X); data.AxisLSY = c.getAxisValue(OuyaController.AXIS_LS_Y); data.AxisRSX = c.getAxisValue(OuyaController.AXIS_RS_X); data.AxisRSY = c.getAxisValue(OuyaController.AXIS_RS_Y); data.AxisLT = c.getAxisValue(OuyaController.AXIS_L2); data.AxisRT = c.getAxisValue(OuyaController.AXIS_R2); } } catch (Exception e) { Log.i(LOG_TAG, "Exception occurred getting controller state for player " + playerNum + ": " + e.toString()); } } return handled || super.onGenericMotionEvent(event); }