+/*******************************************************************************\r
+ * Copyright 2011 See AUTHORS file.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ ******************************************************************************/
+
package com.badlogic.gdx.controllers.android;\r
\r
-import java.util.List;\r
-\r
import android.view.InputDevice;\r
-import android.view.InputDevice.MotionRange;\r
import android.view.KeyEvent;\r
import android.view.MotionEvent;\r
import android.view.View;\r
import android.view.View.OnKeyListener;\r
\r
import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.LifecycleListener;\r
import com.badlogic.gdx.backends.android.AndroidInput;\r
-import com.badlogic.gdx.backends.android.AndroidInput.PauseResumeListener;\r
import com.badlogic.gdx.backends.android.AndroidInputThreePlus;\r
import com.badlogic.gdx.controllers.Controller;\r
import com.badlogic.gdx.controllers.ControllerListener;\r
import com.badlogic.gdx.utils.IntMap.Entry;\r
import com.badlogic.gdx.utils.Pool;\r
\r
-public class AndroidControllers implements PauseResumeListener, ControllerManager, OnKeyListener, OnGenericMotionListener {\r
+public class AndroidControllers implements LifecycleListener, ControllerManager, OnKeyListener, OnGenericMotionListener {\r
private final static String TAG = "AndroidControllers";\r
private final IntMap<AndroidController> controllerMap = new IntMap<AndroidController>();\r
private final Array<Controller> controllers = new Array<Controller>();\r
};\r
\r
public AndroidControllers() {\r
- ((AndroidInput)Gdx.input).addPauseResumeListener(this);\r
+ Gdx.app.addLifecycleListener(this);\r
gatherControllers(false);\r
setupEventQueue();\r
((AndroidInput)Gdx.input).addKeyListener(this);\r
public boolean onKey (View view, int keyCode, KeyEvent keyEvent) {\r
AndroidController controller = controllerMap.get(keyEvent.getDeviceId());\r
if(controller != null) {\r
- if(keyEvent.getRepeatCount() == 0) {\r
- synchronized(eventQueue) {\r
- AndroidControllerEvent event = eventPool.obtain();\r
- event.controller = controller;\r
- if(keyEvent.getAction() == KeyEvent.ACTION_DOWN) {\r
- event.type = AndroidControllerEvent.BUTTON_DOWN;\r
- } else {\r
- event.type = AndroidControllerEvent.BUTTON_UP;\r
- }\r
- event.code = keyCode;\r
- eventQueue.add(event);\r
+ if(controller.getButton(keyCode) && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {\r
+ return true;\r
+ }\r
+ synchronized(eventQueue) {\r
+ AndroidControllerEvent event = eventPool.obtain();\r
+ event.controller = controller;\r
+ if(keyEvent.getAction() == KeyEvent.ACTION_DOWN) {\r
+ event.type = AndroidControllerEvent.BUTTON_DOWN;\r
+ } else {\r
+ event.type = AndroidControllerEvent.BUTTON_UP;\r
}\r
+ event.code = keyCode;\r
+ eventQueue.add(event);\r
}\r
return true;\r
} else {\r
gatherControllers(true);\r
Gdx.app.log(TAG, "controllers resumed"); \r
}\r
-}\r
+\r
+ @Override\r
+ public void dispose () {\r
+ }\r
+}
\ No newline at end of file