@Override public void onCreate() { super.onCreate(); if (DEBUG) Log.d(TAG, "onCreate"); mUsbManager = (UsbManager) getBaseContext().getSystemService(Context.USB_SERVICE); mAudioManager = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE); mPowerManager = (PowerManager) getBaseContext().getSystemService(Context.POWER_SERVICE); mInputManager = (InputManager) getBaseContext().getSystemService(Context.INPUT_SERVICE); ConfigStorage.SerialPortIdentifier portIdentifier = ConfigStorage.readDefaultPort(getBaseContext()); if (DEBUG) Log.d(TAG, "onCreate, portIdentifier: " + portIdentifier); if (portIdentifier != null) { UsbSerialPort port = findUsbSerialPort(portIdentifier); if (port == null) { Log.w(TAG, "Unable to find usb serial port, make sure device is connected: " + portIdentifier); return; } onUsbSerialPortChanged(port); } }
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); } } }); }
private void prepareAndStartGame() { GameView gameView = (GameView) getView().findViewById(R.id.gameView); mGameEngine = new GameEngine(getActivity(), gameView, 4); mGameEngine.setInputController(new CompositeInputController(getView(), getYassActivity())); mGameEngine.setSoundManager(getYassActivity().getSoundManager()); new ParallaxBackground(mGameEngine, 20, R.drawable.seamless_space_0).addToGameEngine(mGameEngine, 0); new GameController(mGameEngine, GameFragment.this).addToGameEngine(mGameEngine, 2); new FPSCounter(mGameEngine).addToGameEngine(mGameEngine, 2); new ScoreGameObject(this, getView(), R.id.score_value).addToGameEngine(mGameEngine, 0); new LivesCounter(getView(), R.id.lives_value).addToGameEngine(mGameEngine, 0); mGameEngine.startGame(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { InputManager inputManager = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE); inputManager.registerInputDeviceListener(GameFragment.this, null); } gameView.postInvalidate(); }
private void prepareAndStartGame() { GameView gameView = (GameView) getView().findViewById(R.id.gameView); mGameEngine = new GameEngine(getActivity(), gameView, 4); mGameEngine.setInputController(new CompositeInputController(getView(), getYassActivity())); mGameEngine.setSoundManager(getYassActivity().getSoundManager()); new ParallaxBackground(mGameEngine, 20, R.drawable.seamless_space_0).addToGameEngine(mGameEngine, 0); // mGameEngine.addGameObject(new ParallaxBackground(mGameEngine, 30, R.drawable.parallax60), 0); new GameController(mGameEngine, GameFragment.this).addToGameEngine(mGameEngine, 2); new FPSCounter(mGameEngine).addToGameEngine(mGameEngine, 2); new ScoreGameObject(getView(), R.id.score_value).addToGameEngine(mGameEngine, 0); new LivesCounter(getView(), R.id.lives_value).addToGameEngine(mGameEngine, 0); mGameEngine.startGame(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { InputManager inputManager = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE); inputManager.registerInputDeviceListener(GameFragment.this, null); } }
private void prepareAndStartGame() { GameView gameView = (GameView) getView().findViewById(R.id.gameView); mGameEngine = new GameEngine(getActivity(), gameView, 4); mGameEngine.setInputController(new CompositeInputController(getView(), getYassActivity())); mGameEngine.setSoundManager(getYassActivity().getSoundManager()); new ParallaxBackground(mGameEngine, 20, R.drawable.seamless_space_0).addToGameEngine(mGameEngine, 0); new GameController(mGameEngine, GameFragment.this).addToGameEngine(mGameEngine, 2); new FPSCounter(mGameEngine).addToGameEngine(mGameEngine, 2); new ScoreGameObject(getView(), R.id.score_value).addToGameEngine(mGameEngine, 0); new LivesCounter(getView(), R.id.lives_value).addToGameEngine(mGameEngine, 0); mGameEngine.startGame(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { InputManager inputManager = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE); inputManager.registerInputDeviceListener(GameFragment.this, null); } gameView.postInvalidate(); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); view.findViewById(R.id.btn_play_pause).setOnClickListener(this); final ViewTreeObserver obs = view.getViewTreeObserver(); obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { obs.removeGlobalOnLayoutListener(this); } else { obs.removeOnGlobalLayoutListener(this); } mGameEngine = new GameEngine(getActivity()); mGameEngine.setInputController(new CompositeInputController(getView(), getYassActivity())); mGameEngine.addGameObject(new Player(getView())); mGameEngine.startGame(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { InputManager inputManager = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE); inputManager.registerInputDeviceListener(GameFragment.this, null); } } }); }
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(); } }
private void prepareAndStartGame() { GameView gameView = (GameView) getView().findViewById(R.id.gameView); mGameEngine = new GameEngine(getActivity(), gameView, 4); mGameEngine.setSoundManager(getMainActivity().getSoundManager()); new GameController(mGameEngine, GameFragment.this).addToGameEngine(mGameEngine, 2); // new FPSCounter(mGameEngine).addToGameEngine(mGameEngine, 2); new BackgroundImage(mGameEngine, R.drawable.background).addToGameEngine(mGameEngine, 0); mGameEngine.startGame(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { InputManager inputManager = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE); inputManager.registerInputDeviceListener(GameFragment.this, null); } gameView.postInvalidate(); for (int i=0; i<DUMMY_OBJECT_POOL_SIZE; i++) { mDummyObjectPool.add(new DummyObject(mGameEngine)); } getView().findViewById(R.id.gameView).setOnTouchListener(this); }
@Override public void onDestroy() { this.webView.setOnGenericMotionListener(null); this.webView.setOnKeyListener(null); usedIndices = null; buttonsToJustProcessActionDown = null; eventArgument = null; gamepads = null; this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { InputManager inputManager = (InputManager) cordova.getActivity() .getSystemService(Context.INPUT_SERVICE); inputManager.unregisterInputDeviceListener(CordovaPluginGamepad.this); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mInputManager = (InputManager)getSystemService(Context.INPUT_SERVICE); mInputDeviceStates = new SparseArray<InputDeviceState>(); mSummaryAdapter = new SummaryAdapter(this, getResources()); setContentView(R.layout.game_controller_input); mGame = (GameView) findViewById(R.id.game); mSummaryList = (ListView) findViewById(R.id.summary); mSummaryList.setAdapter(mSummaryAdapter); mSummaryList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mSummaryAdapter.onItemClick(position); } }); }
public GameView(Context context) { super( context ); setEGLContextClientVersion( 2 ); this.setRenderer( this ); this.requestFocus(); mInstance = this; mLastUpdateTimeMillis = System.currentTimeMillis(); mShip = new Ship(); InputManager inputManager = (InputManager) context.getSystemService( Context.INPUT_SERVICE ); inputManager.registerInputDeviceListener( this, null ); mAsteroids = new ArrayList<Asteroid>(); mBullets = new ArrayList<Bullet>(); initLevel(); }
public EventInput() throws Exception { //Get the instance of InputManager class using reflection String methodName = "getInstance"; Object[] objArr = new Object[0]; im = (InputManager) InputManager.class.getDeclaredMethod(methodName, new Class[0]) .invoke(null, objArr); //Make MotionEvent.obtain() method accessible methodName = "obtain"; MotionEvent.class.getDeclaredMethod(methodName, new Class[0]).setAccessible(true); //Get the reference to injectInputEvent method methodName = "injectInputEvent"; injectInputEventMethod = InputManager.class.getMethod( methodName, new Class[]{InputEvent.class, Integer.TYPE}); }
protected void injectKey(int keycode) { InputManager inputManager = (InputManager) XposedHelpers .callStaticMethod(InputManager.class, "getInstance"); long now = SystemClock.uptimeMillis(); final KeyEvent downEvent = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keycode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, InputDevice.SOURCE_KEYBOARD); final KeyEvent upEvent = KeyEvent.changeAction(downEvent, KeyEvent.ACTION_UP); Integer INJECT_INPUT_EVENT_MODE_ASYNC = XposedHelpers .getStaticIntField(InputManager.class, "INJECT_INPUT_EVENT_MODE_ASYNC"); XposedHelpers.callMethod(inputManager, "injectInputEvent", downEvent, INJECT_INPUT_EVENT_MODE_ASYNC); XposedHelpers.callMethod(inputManager, "injectInputEvent", upEvent, INJECT_INPUT_EVENT_MODE_ASYNC); }
@Override protected void onDestroy() { super.onDestroy(); if (controllerHandler != null) { InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE); inputManager.unregisterInputDeviceListener(controllerHandler); } wifiLock.release(); if (connectedToUsbDriverService) { // Unbind from the discovery service unbindService(usbDriverServiceConnection); } // Destroy the capture provider inputCaptureProvider.destroy(); }
void sendEvent(int action, int flags, long when, boolean applyDefaultFlags) { try { final int repeatCount = (flags & KeyEvent.FLAG_LONG_PRESS) != 0 ? 1 : 0; if (applyDefaultFlags) { flags |= KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY; } final KeyEvent ev = new KeyEvent(mDownTime, when, action, mCode, repeatCount, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, flags, InputDevice.SOURCE_KEYBOARD); final Object inputManager = XposedHelpers.callStaticMethod(InputManager.class, "getInstance"); XposedHelpers.callMethod(inputManager, "injectInputEvent", ev, 0); } catch (Throwable t) { XposedBridge.log(t); } }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); view.findViewById(R.id.btn_play_pause).setOnClickListener(this); final ViewTreeObserver obs = view.getViewTreeObserver(); obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { obs.removeGlobalOnLayoutListener(this); } else { obs.removeOnGlobalLayoutListener(this); } GameView gameView = (GameView) getView().findViewById(R.id.gameView); mGameEngine = new GameEngine(getActivity(), gameView, 4); mGameEngine.setInputController(new CompositeInputController(getView(), getYassActivity())); new ParallaxBackground(mGameEngine, 20, R.drawable.seamless_space_0).addToGameEngine(mGameEngine, 0); // mGameEngine.addGameObject(new ParallaxBackground(mGameEngine, 30, R.drawable.parallax60), 0); new GameController(mGameEngine).addToGameEngine(mGameEngine, 2); new Player(mGameEngine).addToGameEngine(mGameEngine, 3); new FPSCounter(mGameEngine).addToGameEngine(mGameEngine, 2); mGameEngine.startGame(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { InputManager inputManager = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE); inputManager.registerInputDeviceListener(GameFragment.this, null); } } }); }
@Override public void onDestroy() { super.onDestroy(); mGameEngine.stopGame(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { InputManager inputManager = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE); inputManager.unregisterInputDeviceListener(this); } }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); view.findViewById(R.id.btn_play_pause).setOnClickListener(this); final ViewTreeObserver obs = view.getViewTreeObserver(); obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { obs.removeGlobalOnLayoutListener(this); } else { obs.removeOnGlobalLayoutListener(this); } GameView gameView = (GameView) getView().findViewById(R.id.gameView); mGameEngine = new GameEngine(getActivity(), gameView, 4); mGameEngine.setInputController(new CompositeInputController(getView(), getYassActivity())); mGameEngine.addGameObject(new ParallaxBackground(mGameEngine, 20, R.drawable.seamless_space_0), 0); // mGameEngine.addGameObject(new ParallaxBackground(mGameEngine, 30, R.drawable.parallax60), 0); mGameEngine.addGameObject(new GameController(mGameEngine), 2); mGameEngine.addGameObject(new Player(mGameEngine), 3); mGameEngine.addGameObject(new FPSCounter(mGameEngine), 2); mGameEngine.startGame(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { InputManager inputManager = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE); inputManager.registerInputDeviceListener(GameFragment.this, null); } } }); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); view.findViewById(R.id.btn_play_pause).setOnClickListener(this); final ViewTreeObserver obs = view.getViewTreeObserver(); obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { obs.removeGlobalOnLayoutListener(this); } else { obs.removeOnGlobalLayoutListener(this); } GameView gameView = (GameView) getView().findViewById(R.id.gameView); mGameEngine = new GameEngine(getActivity(), gameView, 4); mGameEngine.setInputController(new CompositeInputController(getView(), getYassActivity())); mGameEngine.setSoundManager(getYassActivity().getSoundManager()); new ParallaxBackground(mGameEngine, 20, R.drawable.seamless_space_0).addToGameEngine(mGameEngine, 0); // mGameEngine.addGameObject(new ParallaxBackground(mGameEngine, 30, R.drawable.parallax60), 0); new GameController(mGameEngine).addToGameEngine(mGameEngine, 2); new Player(mGameEngine).addToGameEngine(mGameEngine, 3); new FPSCounter(mGameEngine).addToGameEngine(mGameEngine, 2); mGameEngine.startGame(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { InputManager inputManager = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE); inputManager.registerInputDeviceListener(GameFragment.this, null); } } }); }
@Override public void initialize(final CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); try { usedIndices = new ArrayList<Boolean>(); deviceIdToIndex = new HashMap<Integer, Long>(); buttonsToJustProcessActionDown = new ArrayList<ButtonToJustProcessActionDown>(); eventArgument = new JSONObject(); gamepadConnectedCallbackContext = null; gamepadDisconnectedCallbackContext = null; refreshGamepads(); initialTimeMillis = System.currentTimeMillis(); webView.setOnGenericMotionListener(this); webView.setOnKeyListener(this); cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { InputManager inputManager = (InputManager) cordova.getActivity() .getSystemService(Context.INPUT_SERVICE); inputManager.registerInputDeviceListener(CordovaPluginGamepad.this, null); } }); } catch (JSONException e) { // TODO: Notify an error throw new RuntimeException(e); } }
private void attachedToWindow(Context context) { if (mAttachedToWindowCounter++ == 0) { mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE); synchronized (mLock) { initializeDevices(); } // Register an input device listener. mInputManager.registerInputDeviceListener(mInputDeviceListener, null); } }
private static void removeDeviceListener() { if (Versions.preJB) { if (sPollTimer != null) { sPollTimer.cancel(); sPollTimer = null; } return; } ((InputManager)GeckoAppShell.getContext().getSystemService(Context.INPUT_SERVICE)).unregisterInputDeviceListener(sListener); sListener = null; }