Java 类android.hardware.input.InputManager 实例源码

项目:bimdroid    文件:BmwIBusService.java   
@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);
    }
}
项目:GravityBox    文件:PieController.java   
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;
    }
}
项目:GravityBox    文件:ModHwKeys.java   
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);
            }
        }
    });
}
项目:Android-Game-Programming    文件:GameFragment.java   
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();
}
项目:Android-Game-Programming    文件:GameFragment.java   
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);
        }
    }
项目:Android-Game-Programming    文件:GameFragment.java   
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();
}
项目:Android-Game-Programming    文件:GameFragment.java   
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();
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
            }
        }
    });
}
项目:atmosphere-uiautomator-bridge    文件:MotionEventSender.java   
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();
    }

}
项目:BalloonsGame    文件:GameFragment.java   
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);
    }
项目:cordova-android-tv    文件:CordovaPluginGamepad.java   
@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);
        }
    });
}
项目:cordova-android-tv    文件:CordovaPluginGamepad.java   
@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);
        }
    });
}
项目:ApkLauncher    文件:GameControllerInput.java   
@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);
        }
    });
}
项目:ApiDemos    文件:GameControllerInput.java   
@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);
        }
    });
}
项目:AndroidDemoProjects    文件:GameView.java   
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();
}
项目:RemoteDroid    文件:EventInput.java   
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});
}
项目:XposedMenuBeGone    文件:Main.java   
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);

}
项目:moonlight-android    文件:Game.java   
@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();
}
项目:felix-on-android    文件:GameControllerInput.java   
@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);
        }
    });
}
项目:MEng    文件:GameControllerInput.java   
@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);
        }
    });
}
项目:deview-2013-samples    文件:GameControllerInput.java   
@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);
        }
    });
}
项目:GravityBox    文件:KeyButtonView.java   
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);
    }
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
                }
            }
        });
    }
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
    }
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
    }
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
                }
            }
        });
    }
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
    }
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
    }
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
    }
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
    }
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
                }
            }
        });
    }
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
    }
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
    }
}
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
                }
            }
        });
    }
项目:Android-Game-Programming    文件:GameFragment.java   
@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);
    }
}
项目:BalloonsGame    文件:GameFragment.java   
@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);
    }
}
项目:cordova-android-tv    文件:CordovaPluginGamepad.java   
@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);
    }
}
项目:cordova-android-tv    文件:CordovaPluginGamepad.java   
@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);
    }
}
项目:365browser    文件:GamepadList.java   
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);
    }
}
项目:mc_backup    文件:AndroidGamepadManager.java   
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;
}