@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { // Selection may be beginning. Sync the TextView with the buffer. refreshTextFromBuffer(); } // Mouse input is treated differently: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE) { if (onMouseEvent(event, terminalView.bridge)) { return true; } terminalView.viewPager.setPagingEnabled(true); } else { if (terminalView.onTouchEvent(event)) { return true; } } return super.onTouchEvent(event); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @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); }
@Override public boolean onGenericMotionEvent(MotionEvent event) { mInputManager.onGenericMotionEvent(event); // Check that the event came from a joystick or gamepad since a generic // motion event could be almost anything. API level 18 adds the useful // event.isFromSource() helper function. int eventSource = event.getSource(); if ((((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) && event.getAction() == MotionEvent.ACTION_MOVE) { int id = event.getDeviceId(); if (-1 != id) { Ship curShip = getShipForId(id); if (curShip.onGenericMotionEvent(event)) { return true; } } } return super.onGenericMotionEvent(event); }
private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis) : event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the // joystick axis center. // A joystick at rest does not always report an absolute position of // (0,0). if (Math.abs(value) > flat) { return value; } } return 0; }
public void handleMessage(Message m) { switch (m.what) { case MSG_INJECT_KEY: final long eventTime = SystemClock.uptimeMillis(); final InputManager inputManager = (InputManager) XposedHelpers.callStaticMethod(InputManager.class, "getInstance"); int flags = KeyEvent.FLAG_FROM_SYSTEM; XposedHelpers.callMethod(inputManager, "injectInputEvent", new KeyEvent(eventTime - 50, eventTime - 50, KeyEvent.ACTION_DOWN, m.arg1, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0); XposedHelpers.callMethod(inputManager, "injectInputEvent", new KeyEvent(eventTime - 50, eventTime - 25, KeyEvent.ACTION_UP, m.arg1, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0); break; } }
public static void injectKey(final int keyCode) { Handler handler = (Handler) XposedHelpers.getObjectField(mPhoneWindowManager, "mHandler"); if (handler == null) return; handler.post(new Runnable() { @Override public void run() { try { final long eventTime = SystemClock.uptimeMillis(); final InputManager inputManager = (InputManager) mContext.getSystemService(Context.INPUT_SERVICE); int flags = KeyEvent.FLAG_FROM_SYSTEM; XposedHelpers.callMethod(inputManager, "injectInputEvent", new KeyEvent(eventTime - 50, eventTime - 50, KeyEvent.ACTION_DOWN, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0); XposedHelpers.callMethod(inputManager, "injectInputEvent", new KeyEvent(eventTime - 50, eventTime - 25, KeyEvent.ACTION_UP, keyCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_UNKNOWN), 0); } catch (Throwable t) { XposedBridge.log(t); } } }); }
public static void hook(ClassLoader loader) { final Class<?> CLASS_POINTER_EVENT_DISPATCHER = XposedHelpers.findClass(POINTER_EVENT_DISPATCHER_PATH, loader); XposedHelpers.findAndHookMethod(CLASS_POINTER_EVENT_DISPATCHER, "onInputEvent", InputEvent.class, new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { super.afterHookedMethod(param); try { if (param.args[0] instanceof MotionEvent) { MotionEvent event = (MotionEvent) param.args[0]; //XpLog.i("input x "+event.getX()); //XpLog.i("input y "+event.getY()); if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { PhoneWindowManagerHook.gesturesListener.onPointerEvent(event); } } } catch (Exception e) { XpLog.e(e); } } }); }
@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(DBG) Log.d(TAG,"onGenericMotionEvent ACTION_SCROLL vscroll="+vscroll); if (vscroll != 0) { final int index = mLayout.getFrontCoverIndex(); int targetIndex; if (index+vscroll<0) { targetIndex=0; } else if (index+vscroll >= mCovers.size()-1) { targetIndex = mCovers.size()-1; } else { targetIndex = (int)(index+vscroll+0.5); } float targetScroll = mLayout.getScrollingPositionToCenterThisCover(targetIndex); mAnimHandler.startScrollingAnimPosition(targetScroll, AnimHandler.SPEED_FAST); } } } } return super.onGenericMotionEvent(event); }
public void processGenericEvent(final MotionEvent event) { // Joysticks are supported since Honeycomb, but I don't care about it, because very few devices have it if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK ) { // event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, on Nvidia Shield and some other joysticks DemoGLSurfaceView.nativeGamepadAnalogJoystickInput( event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y), event.getAxisValue(MotionEvent.AXIS_Z), event.getAxisValue(MotionEvent.AXIS_RZ), event.getAxisValue(MotionEvent.AXIS_LTRIGGER), event.getAxisValue(MotionEvent.AXIS_RTRIGGER), event.getAxisValue(MotionEvent.AXIS_HAT_X), event.getAxisValue(MotionEvent.AXIS_HAT_Y), processGamepadDeviceId(event.getDevice()) ); return; } // Process mousewheel if( event.getAction() == MotionEvent.ACTION_SCROLL ) { int scrollX = Math.round(event.getAxisValue(MotionEvent.AXIS_HSCROLL)); int scrollY = Math.round(event.getAxisValue(MotionEvent.AXIS_VSCROLL)); DemoGLSurfaceView.nativeMouseWheel(scrollX, scrollY); return; } super.processGenericEvent(event); }
@Override public boolean onKeyDown(int keyCode, final KeyEvent event) { if( keyCode == KeyEvent.KEYCODE_BACK ) { if( (event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE ) { // Stupid Samsung and stupid Acer remaps right mouse button to BACK key nativeMouseButtonsPressed(2, 1); return true; } else if( mClient.isKeyboardWithoutTextInputShown() ) { return true; } } if( nativeKey( keyCode, 1, event.getUnicodeChar(), DifferentTouchInput.processGamepadDeviceId(event.getDevice()) ) == 0 ) return super.onKeyDown(keyCode, event); return true; }
@Override public boolean onKeyUp(int keyCode, final KeyEvent event) { if( keyCode == KeyEvent.KEYCODE_BACK ) { if( (event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE ) { // Stupid Samsung and stupid Acer remaps right mouse button to BACK key nativeMouseButtonsPressed(2, 0); return true; } else if( mClient.isKeyboardWithoutTextInputShown() ) { mClient.showScreenKeyboardWithoutTextInputField(0); // Hide keyboard return true; } } if( nativeKey( keyCode, 0, event.getUnicodeChar(), DifferentTouchInput.processGamepadDeviceId(event.getDevice()) ) == 0 ) return super.onKeyUp(keyCode, event); //if( keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU ) // DimSystemStatusBar.get().dim(mClient._videoLayout); return true; }
/** * Function that returns if any controller is paired/plugged/turned on */ private boolean hasConnectedController(){ /*Get a list of valid input ids and iterate through them*/ for (int deviceId : InputDevice.getDeviceIds()) { InputDevice currentDevice = InputDevice.getDevice(deviceId); /*Device ID of the controller*/ String controllerName = currentDevice.getName().toLowerCase(Locale.ENGLISH); /*Check to see if a known controller is connected*/ if (controllerName.contains("controller") || controllerName.contains("conteroller") || controllerName.contains("contoroller") || controllerName.contains("pad") || controllerName.contains("joystick") || controllerName.contains("nintendo")) { //|| (this.hidDevicesOK && controllerName.equals("hid_device"))){ return true; } } return false; }
/** * Send keys and blocks until the first specified accessibility event. * * Most key presses will cause some UI change to occur. If the device is busy, this will * block until the device begins to process the key press at which point the call returns * and normal wait for idle processing may begin. If no events are detected for the * timeout period specified, the call will return anyway with false. * * @param keyCode * @param metaState * @param eventType * @param timeout * @return true if events is received, otherwise false. */ public boolean sendKeyAndWaitForEvent(final int keyCode, final int metaState, final int eventType, long timeout) { Runnable command = new Runnable() { @Override public void run() { final long eventTime = SystemClock.uptimeMillis(); KeyEvent downEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD); if (injectEventSync(downEvent)) { KeyEvent upEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_UP, keyCode, 0, metaState, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD); injectEventSync(upEvent); } } }; return runAndWaitForEvents(command, new WaitForAnyEventPredicate(eventType), timeout) != null; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @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 && !trackMotionScroll((int) vscroll)) { return true; } } } } } return super.onGenericMotionEvent(event); }
public MotionEventSender() { try { Method imInstanceMethod = InputManager.class.getDeclaredMethod("getInstance"); imInstanceMethod.setAccessible(true); inputManager = (InputManager) imInstanceMethod.invoke(null); injectInputEventMethod = InputManager.class.getDeclaredMethod("injectInputEvent", android.view.InputEvent.class, int.class); int[] deviceIds = InputDevice.getDeviceIds(); for (int inputDeviceId : deviceIds) { InputDevice inputDevice = InputDevice.getDevice(inputDeviceId); int deviceSources = inputDevice.getSources(); if ((deviceSources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { DEVICE_ID = inputDeviceId; break; } } } catch (Exception e) { e.printStackTrace(); exitFailure(); } }
static InputDriver build(Button button, final int keyCode) { final InputDriver inputDriver = new InputDriver.Builder(InputDevice.SOURCE_CLASS_BUTTON) .setName(DRIVER_NAME) .setVersion(DRIVER_VERSION) .setKeys(new int[]{keyCode}) .build(); button.setOnButtonEventListener(new Button.OnButtonEventListener() { @Override public void onButtonEvent(Button b, boolean pressed) { int keyAction = pressed ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP; inputDriver.emit(new KeyEvent[]{ new KeyEvent(keyAction, keyCode) }); } }); return inputDriver; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override public boolean onGenericMotionEvent(MotionEvent event) { if (Build.VERSION.SDK_INT >= 12) { 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; } } } } } } } return super.onGenericMotionEvent(event); }
@Override public void onEyeHitIn(MDHitEvent hitEvent) { super.onEyeHitIn(hitEvent); MDHitPoint point = hitEvent.getHitPoint(); if (point == null || mAttachedView == null) { return; } int action = mTouchStatus == TouchStatus.NOP ? MotionEvent.ACTION_HOVER_ENTER : MotionEvent.ACTION_HOVER_MOVE; float x = mAttachedView.getLeft() + mAttachedView.getWidth() * point.getU(); float y = mAttachedView.getTop() + mAttachedView.getHeight() * point.getV(); MotionEvent motionEvent = MotionEvent.obtain(hitEvent.getTimestamp(), System.currentTimeMillis(), action, x, y, 0); motionEvent.setSource(InputDevice.SOURCE_CLASS_POINTER); mAttachedView.dispatchGenericMotionEvent(motionEvent); motionEvent.recycle(); mTouchStatus = TouchStatus.DOWN; invalidate(); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static void injectTap(int x, int y, UiAutomation uiAutomation, boolean sync) { long downTime = System.currentTimeMillis(); MotionEvent eventDown = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0); eventDown.setSource(InputDevice.SOURCE_TOUCHSCREEN); Log.d(TAG, "Injecting " + eventDown); if (!uiAutomation.injectInputEvent(eventDown, sync)) { Log.d(TAG, "Injection failed"); } MotionEvent eventUp = MotionEvent.obtain(eventDown); eventUp.setAction(MotionEvent.ACTION_UP); Log.d(TAG, "Injecting " + eventUp); if (!uiAutomation.injectInputEvent(eventUp, sync)) { Log.d(TAG, "Injection failed"); } eventDown.recycle(); eventUp.recycle(); }
@Override public boolean onGenericMotionEvent(MotionEvent ev) { if ((ev.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && ev.getAction() == MotionEvent.ACTION_MOVE) { if (rollingSpiderDeviceController != null) { if (mAutoPilotMode) { autoPiloting(ev); } else { normalPiloting(ev); } if (mTrianglePressed) { doTrick(ev); } } } return true; }
@TargetApi(VERSION_CODES.HONEYCOMB_MR1) public static float getCenteredAxis(MotionEvent event, InputDevice device, int axis) { final 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) { final float flat = range.getFlat(); final 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; }
@TargetApi(12) private JSONObject createGamepadForInputDevice(InputDevice inputDevice) throws JSONException { JSONObject gamepad = new JSONObject(); JSONArray axes = new JSONArray(); for (int i = 0; i < NUMBER_OF_AXES; i++) { axes.put(ZERO); } JSONArray buttons = new JSONArray(); for (int i = 0; i < NUMBER_OF_BUTTONS; i++) buttons.put(ZERO); int deviceId = inputDevice.getId(); long index = deviceIdToIndex.containsKey(deviceId) ? deviceIdToIndex .get(deviceId) : getFirstFreeIndex(); deviceIdToIndex.put(deviceId, index); gamepad.put(ID, inputDevice.getName()); gamepad.put(INDEX, index); gamepad.put(CONNECTED, true); gamepad.put(TIME_STAMP, System.currentTimeMillis() - initialTimeMillis); gamepad.put(MAPPING, "standard"); gamepad.put(AXES, axes); gamepad.put(BUTTONS, buttons); return gamepad; }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { return true; } if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { return super.onKeyUp(keyCode, event); }; int source = event.getSource(); if ((source & InputDevice.SOURCE_JOYSTICK) != 0 || (source & InputDevice.SOURCE_DPAD) != 0 || (source & InputDevice.SOURCE_GAMEPAD) != 0) { int button = get_godot_button(keyCode); int device = event.getDeviceId(); GodotLib.joybutton(device, button, false); return true; } else { GodotLib.key(keyCode, event.getUnicodeChar(0), false); }; return super.onKeyUp(keyCode, event); }
public float axis_value(MotionEvent p_event, InputDevice p_device, int p_axis, int p_pos) { final InputDevice.MotionRange range = p_device.getMotionRange(p_axis, p_event.getSource()); if (range == null) return 0; //Log.e(TAG, String.format("axis ranges %f, %f, %f", range.getRange(), range.getMin(), range.getMax())); final float flat = range.getFlat(); final float value = p_pos < 0 ? p_event.getAxisValue(p_axis): p_event.getHistoricalAxisValue(p_axis, p_pos); final float absval = Math.abs(value); if (absval <= flat) { return 0; }; final float ret = (value - range.getMin()) / range.getRange() * 2 - 1.0f; return ret; }
@Override public boolean onGenericMotionEvent(MotionEvent event) { 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 process_axis_state(event, i); } // Process the current movement sample in the batch (position -1) process_axis_state(event, -1); return true; }; return super.onGenericMotionEvent(event); }
public boolean dispatchGenericMotionEvent(MotionEvent event){ //Check for a joystick event if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != InputDevice.SOURCE_JOYSTICK || event.getAction() != MotionEvent.ACTION_MOVE) return false; InputDevice inputDevice = event.getDevice(); float dpadx = event.getAxisValue(MotionEvent.AXIS_HAT_X); float dpady = event.getAxisValue(MotionEvent.AXIS_HAT_Y); if (inputDevice == null || Math.abs(dpadx) == 1.0f || Math.abs(dpady) == 1.0f) return false; float x = AndroidDevices.getCenteredAxis(event, inputDevice, MotionEvent.AXIS_X); if (System.currentTimeMillis() - mLastMove > JOYSTICK_INPUT_DELAY){ if (Math.abs(x) > 0.3){ seek(x > 0.0f ? 10000 : -10000); mLastMove = System.currentTimeMillis(); return true; } } return true; }
@Override public boolean onGenericMotionEvent(MotionEvent event) { final boolean isTouchPad = (event.getSource() & InputDevice.SOURCE_CLASS_POSITION) != 0; if (isTouchPad) { float maxX = event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax(); float maxY = event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax(); View decor = getWindow().getDecorView(); float scaleX = decor.getWidth() / maxX; float scaleY = decor.getHeight() / maxY; float x = event.getX() * scaleX; //x = decor.getWidth() - x; // invert x float y = event.getY() * scaleY; //y = decor.getHeight() - y; // invert y MotionEvent touchEvent = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), x, y, event.getMetaState()); return dispatchTouchEvent(touchEvent); } return super.onGenericMotionEvent(event); }
private List<Integer> getGameControllerIds() { List<Integer> gameControllerDeviceIds = new ArrayList<>(); int[] deviceIds = InputDevice.getDeviceIds(); for (int deviceId : deviceIds) { InputDevice dev = InputDevice.getDevice(deviceId); int sources = dev.getSources(); if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) { if (!gameControllerDeviceIds.contains(deviceId)) { gameControllerDeviceIds.add(deviceId); } } } return gameControllerDeviceIds; }
@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 = MotionEventCompat.getAxisValue(event, MotionEventCompat.AXIS_VSCROLL); if (vscroll != 0) { final int delta = (int) (vscroll * ViewUtils.getVerticalScrollFactor(this)); if (!trackMotionScroll(delta, delta)) { return true; } } } break; } } return super.onGenericMotionEvent(event); }
GamepadDevice(int index, InputDevice inputDevice) { mDeviceIndex = index; mDeviceId = inputDevice.getId(); mDeviceName = inputDevice.getName(); mTimestamp = SystemClock.uptimeMillis(); // Get axis ids and initialize axes values. final List<MotionRange> ranges = inputDevice.getMotionRanges(); mAxes = new int[ranges.size()]; int i = 0; for (MotionRange range : ranges) { if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { int axis = range.getAxis(); assert axis < MAX_RAW_AXIS_VALUES; mAxes[i++] = axis; } } mMappings = GamepadMappings.getMappings(inputDevice, mAxes); }
public Gamepad(int serviceId, int deviceId) { id = serviceId; axes = new float[Axis.values().length]; dpad = new boolean[4]; triggers = new float[2]; InputDevice device = InputDevice.getDevice(deviceId); if (device != null) { // LTRIGGER/RTRIGGER don't seem to be exposed on older // versions of Android. if (device.getMotionRange(MotionEvent.AXIS_LTRIGGER) != null && device.getMotionRange(MotionEvent.AXIS_RTRIGGER) != null) { triggerAxes = new int[]{MotionEvent.AXIS_LTRIGGER, MotionEvent.AXIS_RTRIGGER}; } else if (device.getMotionRange(MotionEvent.AXIS_BRAKE) != null && device.getMotionRange(MotionEvent.AXIS_GAS) != null) { triggerAxes = new int[]{MotionEvent.AXIS_BRAKE, MotionEvent.AXIS_GAS}; } else { triggerAxes = null; } } }
private static void scanForGamepads() { int[] deviceIds = InputDevice.getDeviceIds(); if (deviceIds == null) { return; } for (int i=0; i < deviceIds.length; i++) { InputDevice device = InputDevice.getDevice(deviceIds[i]); if (device == null) { continue; } if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) != InputDevice.SOURCE_GAMEPAD) { continue; } addGamepad(device); } }
/** This function MUST be called on the UI thread */ @Override public boolean onKeyEvent(KeyEvent event) { if (Versions.preHCMR1) { return false; } if ((event.getSource() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD && event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ZOOM_IN: return animatedScale(0.2f); case KeyEvent.KEYCODE_ZOOM_OUT: return animatedScale(-0.2f); } } return false; }
/** This function MUST be called on the UI thread */ @Override public boolean onMotionEvent(MotionEvent event) { if (Versions.preHCMR1) { return false; } switch (event.getSource() & InputDevice.SOURCE_CLASS_MASK) { case InputDevice.SOURCE_CLASS_POINTER: switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_SCROLL: return handlePointerScroll(event); } break; case InputDevice.SOURCE_CLASS_JOYSTICK: switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_MOVE: return handleJoystickNav(event); } break; } return false; }
private static boolean areSonyXperiaGamepadKeysSwapped() { // The cross and circle buttons on Sony Xperia phones are swapped // in different regions // http://developer.sonymobile.com/2011/02/13/xperia-play-game-keys/ final char DEFAULT_O_BUTTON_LABEL = 0x25CB; boolean swapped = false; int[] deviceIds = InputDevice.getDeviceIds(); for (int i= 0; deviceIds != null && i < deviceIds.length; i++) { KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(deviceIds[i]); if (keyCharacterMap != null && DEFAULT_O_BUTTON_LABEL == keyCharacterMap.getDisplayLabel(KeyEvent.KEYCODE_DPAD_CENTER)) { swapped = true; break; } } return swapped; }
/** * Handles generic motion events */ public boolean onGenericMotionEvent(MotionEvent ev) { if ((ev.getSource() & InputDevice.SOURCE_CLASS_POINTER) == InputDevice.SOURCE_CLASS_POINTER) { int action = ev.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_SCROLL: // Find the front most task and scroll the next task to the front float vScroll = ev.getAxisValue(MotionEvent.AXIS_VSCROLL); if (vScroll > 0) { if (mDeckView.ensureFocusedTask()) { mDeckView.focusNextTask(true, false); } } else { if (mDeckView.ensureFocusedTask()) { mDeckView.focusNextTask(false, false); } } return true; } } return false; }