OSDN Git Service

fixed Nate's fuck up, cause he's just a minion
authorMario Zechner <contact@badlogicgames.com>
Sun, 6 Jan 2013 16:24:33 +0000 (17:24 +0100)
committerMario Zechner <contact@badlogicgames.com>
Sun, 6 Jan 2013 16:24:33 +0000 (17:24 +0100)
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplication.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidDaydream.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInput.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInputFactory.java [new file with mode: 0755]
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInputThreePlus.java [new file with mode: 0755]
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidLiveWallpaper.java
demos/superjumper/superjumper-android/res/values/strings.xml

index e05aeda..817b5bc 100644 (file)
@@ -100,7 +100,7 @@ public class AndroidApplication extends Activity implements Application {
        public void initialize (ApplicationListener listener, AndroidApplicationConfiguration config) {\r
                graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy()\r
                        : config.resolutionStrategy);\r
-               input = new AndroidInput(this, this, graphics.view, config);\r
+               input = AndroidInputFactory.newAndroidInput(this, this, graphics.view, config);\r
                audio = new AndroidAudio(this, config);\r
                files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());\r
                net = new AndroidNet(this);\r
@@ -188,7 +188,7 @@ public class AndroidApplication extends Activity implements Application {
        public View initializeForView (ApplicationListener listener, AndroidApplicationConfiguration config) {\r
                graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy()\r
                        : config.resolutionStrategy);\r
-               input = new AndroidInput(this, this, graphics.view, config);\r
+               input = AndroidInputFactory.newAndroidInput(this, this, graphics.view, config);\r
                audio = new AndroidAudio(this, config);\r
                files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());\r
                net = new AndroidNet(this);\r
index 625d09a..6867798 100644 (file)
@@ -99,7 +99,7 @@ public class AndroidDaydream extends DreamService implements Application {
        public void initialize (ApplicationListener listener, AndroidApplicationConfiguration config) {
                graphics = new AndroidGraphicsDaydream(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy()
                        : config.resolutionStrategy);
-               input = new AndroidInput(this, this, graphics.view, config);
+               input = AndroidInputFactory.newAndroidInput(this, this, graphics.view, config);
                audio = new AndroidAudio(this, config);
                files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());
 //             net = new AndroidNet(this);
@@ -182,7 +182,7 @@ public class AndroidDaydream extends DreamService implements Application {
        public View initializeForView (ApplicationListener listener, AndroidApplicationConfiguration config) {
                graphics = new AndroidGraphicsDaydream(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy()
                        : config.resolutionStrategy);
-               input = new AndroidInput(this, this, graphics.view, config);
+               input = AndroidInputFactory.newAndroidInput(this, this, graphics.view, config);
                audio = new AndroidAudio(this, config);
                files = new AndroidFiles(this.getAssets(), this.getFilesDir().getAbsolutePath());
 //             net = new AndroidNet(this);
index 2fa2a9e..5d82e45 100644 (file)
@@ -34,7 +34,6 @@ import android.view.MotionEvent;
 import android.view.Surface;\r
 import android.view.View;\r
 import android.view.WindowManager;\r
-import android.view.View.OnGenericMotionListener;\r
 import android.view.View.OnKeyListener;\r
 import android.view.View.OnTouchListener;\r
 import android.view.inputmethod.InputMethodManager;\r
@@ -53,7 +52,7 @@ import com.badlogic.gdx.utils.Pool;
  * \r
  * @author mzechner */\r
 /** @author jshapcot */\r
-public class AndroidInput implements Input, OnKeyListener, OnTouchListener, OnGenericMotionListener {\r
+public class AndroidInput implements Input, OnKeyListener, OnTouchListener {\r
        static class KeyEvent {\r
                static final int KEY_DOWN = 0;\r
                static final int KEY_UP = 1;\r
@@ -89,8 +88,7 @@ public class AndroidInput implements Input, OnKeyListener, OnTouchListener, OnGe
                }\r
        };\r
 \r
-       ArrayList<OnKeyListener> keyListeners = new ArrayList();\r
-       ArrayList<OnGenericMotionListener> genericMotionListeners = new ArrayList();\r
+       ArrayList<OnKeyListener> keyListeners = new ArrayList();        \r
        ArrayList<KeyEvent> keyEvents = new ArrayList();\r
        ArrayList<TouchEvent> touchEvents = new ArrayList();\r
        int[] touchX = new int[20];\r
@@ -137,8 +135,7 @@ public class AndroidInput implements Input, OnKeyListener, OnTouchListener, OnGe
                if (view instanceof View) {\r
                        View v = (View)view;\r
                        v.setOnKeyListener(this);\r
-                       v.setOnTouchListener(this);\r
-                       v.setOnGenericMotionListener(this);\r
+                       v.setOnTouchListener(this);                     \r
                        v.setFocusable(true);\r
                        v.setFocusableInTouchMode(true);\r
                        v.requestFocus();\r
@@ -395,13 +392,6 @@ public class AndroidInput implements Input, OnKeyListener, OnTouchListener, OnGe
        boolean requestFocus = true;\r
 \r
        @Override\r
-       public boolean onGenericMotion (View view, MotionEvent event) {\r
-               for (int i = 0, n = genericMotionListeners.size(); i < n; i++)\r
-                       if (genericMotionListeners.get(i).onGenericMotion(view, event)) return true;\r
-               return false;\r
-       }\r
-\r
-       @Override\r
        public boolean onTouch (View view, MotionEvent event) {\r
                if (requestFocus && view != null) {\r
                        view.requestFocus();\r
@@ -776,10 +766,6 @@ public class AndroidInput implements Input, OnKeyListener, OnTouchListener, OnGe
                keyListeners.add(listener);\r
        }\r
 \r
-       public void addGenericMotionListener (OnGenericMotionListener listener) {\r
-               genericMotionListeners.add(listener);\r
-       }\r
-\r
        /** Our implementation of SensorEventListener. Because Android doesn't like it when we register more than one Sensor to a single\r
         * SensorEventListener, we add one of these for each Sensor. Could use an anonymous class, but I don't see any harm in\r
         * explicitly defining it here. Correct me if I am wrong. */\r
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInputFactory.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInputFactory.java
new file mode 100755 (executable)
index 0000000..aa3807c
--- /dev/null
@@ -0,0 +1,35 @@
+package com.badlogic.gdx.backends.android;\r
+\r
+import java.lang.reflect.Constructor;\r
+\r
+import android.content.Context;\r
+\r
+import com.badlogic.gdx.Application;\r
+\r
+/**\r
+ * Class that instantiates AndroidInput or AndroidInputThreePlus\r
+ * depending on the SDK level, via reflection.\r
+ * @author mzechner\r
+ *\r
+ */\r
+public class AndroidInputFactory {\r
+       public static AndroidInput newAndroidInput(Application activity, Context context, Object view, AndroidApplicationConfiguration config) {\r
+               try {\r
+                       Class<?> clazz = null;\r
+                       AndroidInput input = null;\r
+                       \r
+                       int sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK);\r
+                       if (sdkVersion >= 12) {\r
+                               clazz = Class.forName("com.badlogic.gdx.backends.android.AndroidInputThreePlus");\r
+                       } else {\r
+                               clazz = Class.forName("com.badlogic.gdx.backends.android.AndroidInput");\r
+                       }\r
+                       \r
+                       Constructor<?> constructor = clazz.getConstructor(Application.class, Context.class, Object.class, AndroidApplicationConfiguration.class);\r
+                       input = (AndroidInput)constructor.newInstance(activity, context, view, config);\r
+                       return input;\r
+               } catch(Exception e) {\r
+                       throw new RuntimeException("Couldn't construct AndroidInput, this should never happen", e);\r
+               }\r
+       }\r
+}\r
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInputThreePlus.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInputThreePlus.java
new file mode 100755 (executable)
index 0000000..d37b2a6
--- /dev/null
@@ -0,0 +1,41 @@
+package com.badlogic.gdx.backends.android;\r
+\r
+import java.util.ArrayList;\r
+\r
+import android.content.Context;\r
+import android.view.MotionEvent;\r
+import android.view.View;\r
+import android.view.View.OnGenericMotionListener;\r
+\r
+import com.badlogic.gdx.Application;\r
+\r
+/**\r
+ * Subclass of AndroidInput, used on Androd +3.x to get generic motion events for \r
+ * things like gampads/joysticks and so on.\r
+ * @author mzechner\r
+ *\r
+ */\r
+public class AndroidInputThreePlus extends AndroidInput implements OnGenericMotionListener {\r
+       ArrayList<OnGenericMotionListener> genericMotionListeners = new ArrayList();\r
+       \r
+       public AndroidInputThreePlus (Application activity, Context context, Object view, AndroidApplicationConfiguration config) {\r
+               super(activity, context, view, config);\r
+               // we hook into View, for LWPs we call onTouch below directly from\r
+               // within the AndroidLivewallpaperEngine#onTouchEvent() method.\r
+               if (view instanceof View) {\r
+                       View v = (View)view;\r
+                       v.setOnGenericMotionListener(this);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public boolean onGenericMotion (View view, MotionEvent event) {\r
+               for (int i = 0, n = genericMotionListeners.size(); i < n; i++)\r
+                       if (genericMotionListeners.get(i).onGenericMotion(view, event)) return true;\r
+               return false;\r
+       }\r
+       \r
+       public void addGenericMotionListener (OnGenericMotionListener listener) {\r
+               genericMotionListeners.add(listener);\r
+       }\r
+}\r
index 925503b..4ca39bd 100755 (executable)
@@ -81,7 +81,7 @@ class AndroidLiveWallpaper implements Application {
        \r
        public void initialize(ApplicationListener listener, AndroidApplicationConfiguration config) {\r
                graphics = new AndroidGraphicsLiveWallpaper(this, config.useGL20, config.resolutionStrategy==null?new FillResolutionStrategy():config.resolutionStrategy);\r
-               input = new AndroidInput(this, this.getService(), null, config);\r
+               input = AndroidInputFactory.newAndroidInput(this, this.getService(), null, config);\r
                audio = new AndroidAudio(this.getService(), config);\r
                files = new AndroidFiles(this.getService().getAssets());\r
                this.listener = listener;\r
index ed0f9a5..8c5d919 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <string name="hello">Hello World, SuperJumperAndroid!</string>
-    <string name="app_name">Pax Britannica</string>
+    <string name="app_name">Super Jumper</string>
 </resources>