1 /*******************************************************************************
\r
2 * Copyright 2011 See AUTHORS file.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
15 ******************************************************************************/
17 package com.badlogic.gdx.controllers.android;
\r
19 import android.content.Context;
\r
20 import android.hardware.input.InputManager;
\r
21 import android.hardware.input.InputManager.InputDeviceListener;
\r
23 import com.badlogic.gdx.Gdx;
\r
24 import com.badlogic.gdx.LifecycleListener;
\r
25 import com.badlogic.gdx.backends.android.AndroidApplication;
\r
26 import com.badlogic.gdx.backends.android.AndroidInput;
\r
29 * Used on +4.1 to get events on device connects/disconnects.
\r
33 public class ControllerLifeCycleListener implements LifecycleListener, InputDeviceListener {
\r
34 private static final String TAG = "ControllerLifeCycleListener";
\r
35 private final InputManager inputManager;
\r
36 private final AndroidControllers controllers;
\r
38 public ControllerLifeCycleListener(AndroidControllers controllers) {
\r
39 this.controllers = controllers;
\r
40 this.inputManager = (InputManager)((Context)Gdx.app).getSystemService(Context.INPUT_SERVICE);
\r
41 Gdx.app.addLifecycleListener(this);
\r
42 inputManager.registerInputDeviceListener(this, ((AndroidApplication)Gdx.app).handler);
\r
46 public void resume () {
\r
47 inputManager.registerInputDeviceListener(this, ((AndroidApplication)Gdx.app).handler);
\r
48 Gdx.app.log(TAG, "controller life cycle listener resumed");
\r
52 public void pause () {
\r
53 inputManager.unregisterInputDeviceListener(this);
\r
54 Gdx.app.log(TAG, "controller life cycle listener paused");
\r
58 public void onInputDeviceAdded (int deviceId) {
\r
59 controllers.addController(deviceId, true);
\r
60 Gdx.app.log(TAG, "device " + deviceId + " added");
\r
64 public void onInputDeviceRemoved (int deviceId) {
\r
65 controllers.removeController(deviceId);
\r
66 Gdx.app.log(TAG, "device " + deviceId + " removed");
\r
70 public void onInputDeviceChanged (int deviceId) {
\r
74 public void dispose () {
\r