List of usage examples for android.view InputDevice SOURCE_JOYSTICK
int SOURCE_JOYSTICK
To view the source code for android.view InputDevice SOURCE_JOYSTICK.
Click Source Link
From source file:Main.java
@SuppressLint("InlinedApi") public static String getSourcesString(int sources) { List<String> names = new ArrayList<String>(); addString(sources, InputDevice.SOURCE_KEYBOARD, names); addString(sources, InputDevice.SOURCE_DPAD, names); addString(sources, InputDevice.SOURCE_GAMEPAD, names); addString(sources, InputDevice.SOURCE_TOUCHSCREEN, names); addString(sources, InputDevice.SOURCE_MOUSE, names); addString(sources, InputDevice.SOURCE_STYLUS, names); addString(sources, InputDevice.SOURCE_TOUCHPAD, names); addString(sources, InputDevice.SOURCE_JOYSTICK, names); return TextUtils.join(", ", names); }
From source file:Main.java
/** * Gets the name of the source performing an action. * // w ww . java 2 s. c om * @param source A number representing the source. * * @return The name of the source. */ public static String getSourceName(int source) { switch (source) { case InputDevice.SOURCE_CLASS_BUTTON: return "BUTTON"; case InputDevice.SOURCE_CLASS_POINTER: return "POINTER"; case InputDevice.SOURCE_CLASS_TRACKBALL: return "TRACKBALL"; case InputDevice.SOURCE_CLASS_POSITION: return "POSITION"; case InputDevice.SOURCE_CLASS_JOYSTICK: return "JOYSTICK"; case InputDevice.SOURCE_DPAD: return "dpad"; case InputDevice.SOURCE_GAMEPAD: return "gamepad"; case InputDevice.SOURCE_JOYSTICK: return "joystick"; case InputDevice.SOURCE_KEYBOARD: return "keyboard"; case InputDevice.SOURCE_MOUSE: return "mouse"; case InputDevice.SOURCE_STYLUS: return "stylus"; case InputDevice.SOURCE_TOUCHPAD: return "touchpad"; case InputDevice.SOURCE_TOUCHSCREEN: return "touchscreen"; case InputDevice.SOURCE_TRACKBALL: return "trackball"; case InputDevice.SOURCE_UNKNOWN: return "unknown"; default: return "source_" + source; } }
From source file:tv.piratemedia.flightcontroller.ControlActivity.java
@Override public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) { 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. jav a2 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.example.android.visualgamecontroller.FullscreenActivity.java
/** * Check for any game controllers that are connected already. */// w ww . j a v a 2 s .c o m private void checkGameControllers() { Log.d(TAG, "checkGameControllers"); int[] deviceIds = mInputManager.getInputDeviceIds(); for (int deviceId : deviceIds) { InputDevice dev = InputDevice.getDevice(deviceId); int sources = dev.getSources(); // Verify that the device has gamepad buttons, control sticks, or // both. if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) { // This device is a game controller. Store its device ID. if (!mConnectedDevices.contains(deviceId)) { mConnectedDevices.add(deviceId); if (mCurrentDeviceId == -1) { mCurrentDeviceId = deviceId; mControllerView.setCurrentControllerNumber(dev.getControllerNumber()); mControllerView.invalidate(); } } } } }
From source file:info.bartowski.easteregg.MLand.java
public static boolean isGamePad(InputDevice dev) { int sources = dev.getSources(); // Verify that the device has gamepad buttons, control sticks, or both. return (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)); }
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 ww . 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.example.android.visualgamecontroller.FullscreenActivity.java
/** * Utility method to determine if input device is a gamepad. * // w ww .ja v a2 s . c o m * @param device * @return */ private boolean isGamepad(InputDevice device) { if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD || (device.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) { return true; } return false; }
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); }/*from www .java2 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.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 ww w . j a va 2 s . c o m 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); }
From source file:com.google.fpl.voltair.VoltAirActivity.java
private static boolean isGamepadEvent(MotionEvent event) { return (isFromSource(event, InputDevice.SOURCE_JOYSTICK) || isFromSource(event, InputDevice.SOURCE_GAMEPAD)) && event.getActionMasked() == MotionEvent.ACTION_MOVE; }