Просмотр исходного кода

More changes for Android gamepad support

setaylor 11 лет назад
Родитель
Сommit
fde7592c3c

+ 4 - 22
gameplay/android/build.xml

@@ -3,10 +3,10 @@
 
     <property file="local.properties" />
     <property file="ant.properties" />
-    
+   
     <loadproperties srcFile="project.properties" />
     
-    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" unless="sdk.dir" />
+    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project -t 1 -p . -s'" unless="sdk.dir" />
     <fail message="OS not supported. Supported platforms: Windows, MacOS X or Linux.">
         <condition>
             <not>
@@ -20,26 +20,8 @@
     <macrodef name="build-native">
         <attribute name="location"/>
         <sequential>
-            <exec osfamily="unix" dir="@{location}/android" executable="android">
-                <arg value="update"/>
-                <arg value="project"/>
-                <arg value="-t"/>
-                <arg value="1"/>
-                <arg value="-p"/>
-                <arg value="."/>
-                <arg value="-s"/>
-            </exec>
-            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build"/>
-            <exec osfamily="windows" dir="@{location}/android" executable="cmd">
-                <arg value="/c"/>
-                <arg value="android.bat"/>
-                <arg value="update"/>
-                <arg value="project"/>
-                <arg value="-t"/>
-                <arg value="1"/>
-                <arg value="-p"/>
-                <arg value="."/>
-                <arg value="-s"/>
+            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build">
+                <arg value="-j4"/>
             </exec>
             <exec osfamily="windows" dir="@{location}/android" executable="cmd">
                 <arg value="/c"/>

+ 2 - 9
gameplay/src/Platform.cpp

@@ -44,49 +44,42 @@ bool Platform::mouseEventInternal(Mouse::MouseEvent evt, int x, int y, int wheel
 
 void Platform::gestureSwipeEventInternal(int x, int y, int direction)
 {
-    // TODO: Add support to Form for gestures
     Game::getInstance()->gestureSwipeEvent(x, y, direction);
     Game::getInstance()->getScriptController()->gestureSwipeEvent(x, y, direction);
 }
 
 void Platform::gesturePinchEventInternal(int x, int y, float scale)
 {
-    // TODO: Add support to Form for gestures
     Game::getInstance()->gesturePinchEvent(x, y, scale);
     Game::getInstance()->getScriptController()->gesturePinchEvent(x, y, scale);
 }
 
 void Platform::gestureTapEventInternal(int x, int y)
 {
-    // TODO: Add support to Form for gestures
     Game::getInstance()->gestureTapEvent(x, y);
     Game::getInstance()->getScriptController()->gestureTapEvent(x, y);
 }
 
 void Platform::gestureLongTapEventInternal(int x, int y, float duration)
 {
-    // TODO: Add support to Form for gestures
 	Game::getInstance()->gestureLongTapEvent(x, y, duration);
 	Game::getInstance()->getScriptController()->gestureLongTapEvent(x, y, duration);
 }
 
 void Platform::gestureDragEventInternal(int x, int y)
 {
-    // TODO: Add support to Form for gestures
 	Game::getInstance()->gestureDragEvent(x, y);
 	Game::getInstance()->getScriptController()->gestureDragEvent(x, y);
 }
 
 void Platform::gestureDropEventInternal(int x, int y)
 {
-    // TODO: Add support to Form for gestures
 	Game::getInstance()->gestureDropEvent(x, y);
 	Game::getInstance()->getScriptController()->gestureDropEvent(x, y);
 }
 
 void Platform::resizeEventInternal(unsigned int width, unsigned int height)
 {
-    // Update the width and height of the game
     Game* game = Game::getInstance();
     if (game->_width != width || game->_height != height)
     {
@@ -112,7 +105,7 @@ void Platform::gamepadEventDisconnectedInternal(GamepadHandle handle)
 void Platform::gamepadButtonPressedEventInternal(GamepadHandle handle, Gamepad::ButtonMapping mapping)
 {
     Gamepad* gamepad = Gamepad::getGamepad(handle);
-    unsigned int newButtons = gamepad->_buttons | (1 >> mapping);
+    unsigned int newButtons = gamepad->_buttons | (1 << mapping);
     gamepad->setButtons(newButtons);
     Form::gamepadButtonEventInternal(gamepad);
 }
@@ -120,7 +113,7 @@ void Platform::gamepadButtonPressedEventInternal(GamepadHandle handle, Gamepad::
 void Platform::gamepadButtonReleasedEventInternal(GamepadHandle handle, Gamepad::ButtonMapping mapping)
 {
     Gamepad* gamepad = Gamepad::getGamepad(handle);
-    unsigned int newButtons = gamepad->_buttons & ~(1 >> mapping);
+    unsigned int newButtons = gamepad->_buttons & ~(1 << mapping);
     gamepad->setButtons(newButtons);
     Form::gamepadButtonEventInternal(gamepad);
 }

+ 4 - 4
gameplay/src/Platform.h

@@ -403,10 +403,10 @@ public:
     static void gamepadTriggerChangedEventInternal(GamepadHandle handle, unsigned int index, float value);
 
     /**
-    * Internal method used only from static code in various platform implementation.
-    *
-    * @script{ignore}
-    */
+     * Internal method used only from static code in various platform implementation.
+     *
+     * @script{ignore}
+     */
     static void gamepadJoystickChangedEventInternal(GamepadHandle handle, unsigned int index, float x, float y);
 
     /**

+ 390 - 346
gameplay/src/PlatformAndroid.cpp

@@ -702,9 +702,62 @@ static int getUnicode(int keycode, int metastate)
     }
 }
 
+Gamepad::ButtonMapping getGamepadButtonMapping(jint keycode)
+{
+    switch (keycode)
+    {
+    case AKEYCODE_BUTTON_X:
+        return Gamepad::BUTTON_X;
+    case AKEYCODE_BUTTON_Y:
+        return Gamepad::BUTTON_Y;
+    case AKEYCODE_BUTTON_Z:
+        return Gamepad::BUTTON_Z;
+    case AKEYCODE_BUTTON_A:
+    case AKEYCODE_DPAD_CENTER:
+        return Gamepad::BUTTON_A;
+    case AKEYCODE_BUTTON_B:
+        return Gamepad::BUTTON_B;
+    case AKEYCODE_BUTTON_C:
+        return Gamepad::BUTTON_C;
+    case AKEYCODE_BUTTON_L1:
+        return Gamepad::BUTTON_L1;
+    case AKEYCODE_BUTTON_L2:
+        return Gamepad::BUTTON_L2;
+    case AKEYCODE_BUTTON_THUMBL:
+        return Gamepad::BUTTON_L3;
+    case AKEYCODE_BUTTON_R1:
+        return Gamepad::BUTTON_R1;
+    case AKEYCODE_BUTTON_R2:
+        return Gamepad::BUTTON_R2;
+    case AKEYCODE_BUTTON_THUMBR:
+        return Gamepad::BUTTON_R3;
+    case AKEYCODE_BUTTON_SELECT:
+    case AKEYCODE_BACK:
+        return Gamepad::BUTTON_MENU1;
+    case AKEYCODE_BUTTON_START:
+        return Gamepad::BUTTON_MENU2;
+    case AKEYCODE_BUTTON_MODE:
+        return Gamepad::BUTTON_MENU3;
+    case AKEYCODE_DPAD_UP:
+        return Gamepad::BUTTON_UP;
+    case AKEYCODE_DPAD_DOWN:
+        return Gamepad::BUTTON_DOWN;
+    case AKEYCODE_DPAD_LEFT:
+        return Gamepad::BUTTON_LEFT;
+    case AKEYCODE_DPAD_RIGHT:
+        return Gamepad::BUTTON_RIGHT;
+    default:
+        break;
+    }
+    return Gamepad::BUTTON_MENU4;
+}
+
 // Process the next input event.
 static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
 {
+    int32_t deviceId = AInputEvent_getDeviceId(event);
+    int32_t source = AInputEvent_getSource(event);
+
     if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
     {
         int32_t action = AMotionEvent_getAction(event);
@@ -714,305 +767,356 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
         int x;
         int y;
         
-        switch (action & AMOTION_EVENT_ACTION_MASK)
+        if (source & AINPUT_SOURCE_JOYSTICK)
+        {            
+            // DPAD (axis hats)
+            float xaxis = AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_HAT_X, 0);
+            float yaxis = AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_HAT_Y, 0);        
+            if (xaxis == -1.0f)
+            {
+                gameplay::Platform::gamepadButtonPressedEventInternal(deviceId, gameplay::Gamepad::BUTTON_LEFT);
+            }
+            else if(xaxis == 1.0f)
+            {
+                gameplay::Platform::gamepadButtonPressedEventInternal(deviceId, gameplay::Gamepad::BUTTON_RIGHT);
+            }
+            else if (xaxis == 0.0f)
+            {
+                gameplay::Platform::gamepadButtonReleasedEventInternal(deviceId, gameplay::Gamepad::BUTTON_LEFT);
+                gameplay::Platform::gamepadButtonReleasedEventInternal(deviceId, gameplay::Gamepad::BUTTON_RIGHT);
+            }
+            
+            if(yaxis == -1.0f)
+            {
+                gameplay::Platform::gamepadButtonPressedEventInternal(deviceId, gameplay::Gamepad::BUTTON_UP);
+            }
+            else if(yaxis == 1.0f)
+            {
+                gameplay::Platform::gamepadButtonPressedEventInternal(deviceId, gameplay::Gamepad::BUTTON_DOWN);
+            }
+            else if (yaxis == 0.0f)
+            {
+                gameplay::Platform::gamepadButtonReleasedEventInternal(deviceId, gameplay::Gamepad::BUTTON_UP);
+                gameplay::Platform::gamepadButtonReleasedEventInternal(deviceId, gameplay::Gamepad::BUTTON_DOWN);
+            }         
+            
+            /* TRIGGERS
+            float leftTrigger = AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_BRAKE, 0);
+                gameplay::Platform::gamepadTriggerChangedEventInternal(deviceId, 0, leftTrigger);
+            float rightTrigger = AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_GAS, 1);
+                gameplay::Platform::gamepadTriggerChangedEventInternal(deviceId, 0, rightTrigger);
+            */
+        }
+        else
         {
-            case AMOTION_EVENT_ACTION_DOWN:
-                {
-                    pointerId = AMotionEvent_getPointerId(event, 0);
-                    x = AMotionEvent_getX(event, 0);
-                    y = AMotionEvent_getY(event, 0);
-
-                    // Gesture handling
-                    if ( __gestureEventsProcessed.test(Gesture::GESTURE_TAP) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_SWIPE) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_DRAG) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_DROP) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_PINCH) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_LONG_TAP))
+            switch (action & AMOTION_EVENT_ACTION_MASK)
+            {
+                case AMOTION_EVENT_ACTION_DOWN:
                     {
-                        __pointer0.pressed = true;
-                        __pointer0.time = Game::getInstance()->getAbsoluteTime();
-                        __pointer0.pointerId = pointerId;
-                        __pointer0.x = x;
-                        __pointer0.y = y;
-						__gesturePointer0CurrentPosition = __gesturePointer0LastPosition = std::pair<int, int>(x, y);
-                    }
+                        pointerId = AMotionEvent_getPointerId(event, 0);
+                        x = AMotionEvent_getX(event, 0);
+                        y = AMotionEvent_getY(event, 0);
+
+                        // Gesture handling
+                        if ( __gestureEventsProcessed.test(Gesture::GESTURE_TAP) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_SWIPE) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_DRAG) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_DROP) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_PINCH) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_LONG_TAP))
+                        {
+                            __pointer0.pressed = true;
+                            __pointer0.time = Game::getInstance()->getAbsoluteTime();
+                            __pointer0.pointerId = pointerId;
+                            __pointer0.x = x;
+                            __pointer0.y = y;
+						    __gesturePointer0CurrentPosition = __gesturePointer0LastPosition = std::pair<int, int>(x, y);
+                        }
 
-                    // Primary pointer down.
-                    gameplay::Platform::touchEventInternal(Touch::TOUCH_PRESS, x, y, pointerId);
-                    __primaryTouchId = pointerId;
-                }
-                break;
+                        // Primary pointer down.
+                        gameplay::Platform::touchEventInternal(Touch::TOUCH_PRESS, x, y, pointerId);
+                        __primaryTouchId = pointerId;
+                    }
+                    break;
 
-            case AMOTION_EVENT_ACTION_UP:
-                {
-                    pointerId = AMotionEvent_getPointerId(event, 0);
-                    x = AMotionEvent_getX(event, 0);
-                    y = AMotionEvent_getY(event, 0);
-                    
-                    // Gestures
-                    bool gestureDetected = false;
-					if (__pointer0.pressed &&  __pointer0.pointerId == pointerId)
+                case AMOTION_EVENT_ACTION_UP:
                     {
-                        int deltaX = x - __pointer0.x;
-                        int deltaY = y - __pointer0.y;
-						
-                        // Test for drop
-                      	if (__gesturePinching)
-						{
-							__gesturePinching = false;
-							gestureDetected = true;
-						}
-						else if (__gestureDraging)
+                        pointerId = AMotionEvent_getPointerId(event, 0);
+                        x = AMotionEvent_getX(event, 0);
+                        y = AMotionEvent_getY(event, 0);
+                        
+                        // Gestures
+                        bool gestureDetected = false;
+					    if (__pointer0.pressed &&  __pointer0.pointerId == pointerId)
                         {
-                            if (__gestureEventsProcessed.test(Gesture::GESTURE_DROP))
+                            int deltaX = x - __pointer0.x;
+                            int deltaY = y - __pointer0.y;
+						
+                            // Test for drop
+                          	if (__gesturePinching)
+						    {
+							    __gesturePinching = false;
+							    gestureDetected = true;
+						    }
+						    else if (__gestureDraging)
                             {
-                                gameplay::Platform::gestureDropEventInternal(x, y);
-                                gestureDetected = true;
+                                if (__gestureEventsProcessed.test(Gesture::GESTURE_DROP))
+                                {
+                                    gameplay::Platform::gestureDropEventInternal(x, y);
+                                    gestureDetected = true;
+                                }
+                                __gestureDraging = false;
                             }
-                            __gestureDraging = false;
-                        }
-                        // Test for swipe
-                        else if (__gestureEventsProcessed.test(Gesture::GESTURE_SWIPE) &&
-                            gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time < GESTURE_SWIPE_DURATION_MAX && 
-                            (abs(deltaX) > GESTURE_SWIPE_DISTANCE_MIN || abs(deltaY) > GESTURE_SWIPE_DISTANCE_MIN) )
-                        {
-                            int direction = 0;
-                            if ( abs(deltaX) > abs(deltaY) )
+                            // Test for swipe
+                            else if (__gestureEventsProcessed.test(Gesture::GESTURE_SWIPE) &&
+                                gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time < GESTURE_SWIPE_DURATION_MAX && 
+                                (abs(deltaX) > GESTURE_SWIPE_DISTANCE_MIN || abs(deltaY) > GESTURE_SWIPE_DISTANCE_MIN) )
                             {
-                                if (deltaX > 0)
-                                    direction = gameplay::Gesture::SWIPE_DIRECTION_RIGHT;
-                                else if (deltaX < 0)
-                                    direction = gameplay::Gesture::SWIPE_DIRECTION_LEFT;
+                                int direction = 0;
+                                if ( abs(deltaX) > abs(deltaY) )
+                                {
+                                    if (deltaX > 0)
+                                        direction = gameplay::Gesture::SWIPE_DIRECTION_RIGHT;
+                                    else if (deltaX < 0)
+                                        direction = gameplay::Gesture::SWIPE_DIRECTION_LEFT;
+                                }
+                                else
+                                {
+                                    if (deltaY > 0)
+                                        direction = gameplay::Gesture::SWIPE_DIRECTION_DOWN;
+                                    else if (deltaY < 0)
+                                        direction = gameplay::Gesture::SWIPE_DIRECTION_UP;
+                                }
+                                gameplay::Platform::gestureSwipeEventInternal(x, y, direction);
+                                gestureDetected = true;
                             }
-                            else
+                            // Test for tap
+                            else if(__gestureEventsProcessed.test(Gesture::GESTURE_TAP) &&
+                                   gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time < GESTURE_TAP_DURATION_MAX)
                             {
-                                if (deltaY > 0)
-                                    direction = gameplay::Gesture::SWIPE_DIRECTION_DOWN;
-                                else if (deltaY < 0)
-                                    direction = gameplay::Gesture::SWIPE_DIRECTION_UP;
+                                gameplay::Platform::gestureTapEventInternal(x, y);
+                                gestureDetected = true;
                             }
-                            gameplay::Platform::gestureSwipeEventInternal(x, y, direction);
-                            gestureDetected = true;
+                            // Test for long tap
+                            else if(__gestureEventsProcessed.test(Gesture::GESTURE_LONG_TAP) &&
+                                   gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time >= GESTURE_LONG_TAP_DURATION_MIN)
+                            {
+                                gameplay::Platform::gestureLongTapEventInternal(x, y, gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time);
+                                gestureDetected = true;
+                            }    
                         }
-                        // Test for tap
-                        else if(__gestureEventsProcessed.test(Gesture::GESTURE_TAP) &&
-                               gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time < GESTURE_TAP_DURATION_MAX)
+					    __pointer0.pressed = false;
+
+                        if (!gestureDetected && (__multiTouch || __primaryTouchId == pointerId) )
                         {
-                            gameplay::Platform::gestureTapEventInternal(x, y);
-                            gestureDetected = true;
+                            gameplay::Platform::touchEventInternal(Touch::TOUCH_RELEASE, x, y, pointerId);
                         }
-                        // Test for long tap
-                        else if(__gestureEventsProcessed.test(Gesture::GESTURE_LONG_TAP) &&
-                               gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time >= GESTURE_LONG_TAP_DURATION_MIN)
-                        {
-                            gameplay::Platform::gestureLongTapEventInternal(x, y, gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time);
-                            gestureDetected = true;
-                        }    
+                        __primaryTouchId = -1;
                     }
-					__pointer0.pressed = false;
+                    break;
 
-                    if (!gestureDetected && (__multiTouch || __primaryTouchId == pointerId) )
+                case AMOTION_EVENT_ACTION_POINTER_DOWN:
                     {
-                        gameplay::Platform::touchEventInternal(Touch::TOUCH_RELEASE, x, y, pointerId);
+                        pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+                        pointerId = AMotionEvent_getPointerId(event, pointerIndex);
+                        x = AMotionEvent_getX(event, pointerIndex);
+                        y = AMotionEvent_getY(event, pointerIndex);
+
+                        // Gesture handling
+                        if ( __gestureEventsProcessed.test(Gesture::GESTURE_TAP) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_SWIPE) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_DRAG) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_DROP) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_PINCH) ||
+                             __gestureEventsProcessed.test(Gesture::GESTURE_LONG_TAP))
+                        {
+                            __pointer1.pressed = true;
+                            __pointer1.time = Game::getInstance()->getAbsoluteTime();
+                            __pointer1.pointerId = pointerId;
+                            __pointer1.x = x;
+                            __pointer1.y = y;
+                        	__gesturePointer1CurrentPosition = __gesturePointer1LastPosition = std::pair<int, int>(x, y);
+					    }
+
+                        // Non-primary pointer down.
+                        if (__multiTouch)
+                        {
+                            gameplay::Platform::touchEventInternal(Touch::TOUCH_PRESS, 
+                                                                   AMotionEvent_getX(event, pointerIndex), 
+                                                                   AMotionEvent_getY(event, pointerIndex), pointerId);
+                        }
                     }
-                    __primaryTouchId = -1;
-                }
-                break;
+                    break;
 
-            case AMOTION_EVENT_ACTION_POINTER_DOWN:
-                {
-                    pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
-                    pointerId = AMotionEvent_getPointerId(event, pointerIndex);
-                    x = AMotionEvent_getX(event, pointerIndex);
-                    y = AMotionEvent_getY(event, pointerIndex);
-
-                    // Gesture handling
-                    if ( __gestureEventsProcessed.test(Gesture::GESTURE_TAP) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_SWIPE) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_DRAG) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_DROP) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_PINCH) ||
-                         __gestureEventsProcessed.test(Gesture::GESTURE_LONG_TAP))
-                    {
-                        __pointer1.pressed = true;
-                        __pointer1.time = Game::getInstance()->getAbsoluteTime();
-                        __pointer1.pointerId = pointerId;
-                        __pointer1.x = x;
-                        __pointer1.y = y;
-                    	__gesturePointer1CurrentPosition = __gesturePointer1LastPosition = std::pair<int, int>(x, y);
-					}
-
-                    // Non-primary pointer down.
-                    if (__multiTouch)
+                case AMOTION_EVENT_ACTION_POINTER_UP:
                     {
-                        gameplay::Platform::touchEventInternal(Touch::TOUCH_PRESS, AMotionEvent_getX(event, pointerIndex), AMotionEvent_getY(event, pointerIndex), pointerId);
-                    }
-                }
-                break;
-
-            case AMOTION_EVENT_ACTION_POINTER_UP:
-                {
-                    pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
-                    pointerId = AMotionEvent_getPointerId(event, pointerIndex);
-                    x = AMotionEvent_getX(event, pointerIndex);
-                    y = AMotionEvent_getY(event, pointerIndex);
+                        pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+                        pointerId = AMotionEvent_getPointerId(event, pointerIndex);
+                        x = AMotionEvent_getX(event, pointerIndex);
+                        y = AMotionEvent_getY(event, pointerIndex);
 
-                    bool gestureDetected = false;
-                    if (__pointer1.pressed &&  __pointer1.pointerId == pointerId)
-                    {
-                        int deltaX = x - __pointer1.x;
-                        int deltaY = y - __pointer1.y;
-						
-						if (__gesturePinching)
-						{
-							__gesturePinching = false;
-							gestureDetected = true;
-						}
-						// Test for swipe
-						else if (__gestureEventsProcessed.test(Gesture::GESTURE_SWIPE) &&
-                            gameplay::Game::getInstance()->getAbsoluteTime() - __pointer1.time < GESTURE_SWIPE_DURATION_MAX && 
-                            (abs(deltaX) > GESTURE_SWIPE_DISTANCE_MIN || abs(deltaY) > GESTURE_SWIPE_DISTANCE_MIN) )
+                        bool gestureDetected = false;
+                        if (__pointer1.pressed &&  __pointer1.pointerId == pointerId)
                         {
-                            int direction = 0;
-                            if (deltaX > 0)
-                                direction |= gameplay::Gesture::SWIPE_DIRECTION_RIGHT;
-                            else if (deltaX < 0)
-                                direction |= gameplay::Gesture::SWIPE_DIRECTION_LEFT;
-                            
-                            if (deltaY > 0)
-                                direction |= gameplay::Gesture::SWIPE_DIRECTION_DOWN;
-                            else if (deltaY < 0)
-                                direction |= gameplay::Gesture::SWIPE_DIRECTION_UP;
+                            int deltaX = x - __pointer1.x;
+                            int deltaY = y - __pointer1.y;
+						
+						    if (__gesturePinching)
+						    {
+							    __gesturePinching = false;
+							    gestureDetected = true;
+						    }
+						    // Test for swipe
+						    else if (__gestureEventsProcessed.test(Gesture::GESTURE_SWIPE) &&
+                                gameplay::Game::getInstance()->getAbsoluteTime() - __pointer1.time < GESTURE_SWIPE_DURATION_MAX && 
+                                (abs(deltaX) > GESTURE_SWIPE_DISTANCE_MIN || abs(deltaY) > GESTURE_SWIPE_DISTANCE_MIN) )
+                            {
+                                int direction = 0;
+                                if (deltaX > 0)
+                                    direction |= gameplay::Gesture::SWIPE_DIRECTION_RIGHT;
+                                else if (deltaX < 0)
+                                    direction |= gameplay::Gesture::SWIPE_DIRECTION_LEFT;
+                                
+                                if (deltaY > 0)
+                                    direction |= gameplay::Gesture::SWIPE_DIRECTION_DOWN;
+                                else if (deltaY < 0)
+                                    direction |= gameplay::Gesture::SWIPE_DIRECTION_UP;
 
-                            gameplay::Platform::gestureSwipeEventInternal(x, y, direction);
-                            gestureDetected = true;
+                                gameplay::Platform::gestureSwipeEventInternal(x, y, direction);
+                                gestureDetected = true;
+                            }
+                            else if(__gestureEventsProcessed.test(Gesture::GESTURE_TAP) &&
+                                   gameplay::Game::getInstance()->getAbsoluteTime() - __pointer1.time < GESTURE_TAP_DURATION_MAX)
+                            {
+                                gameplay::Platform::gestureTapEventInternal(x, y);
+                                gestureDetected = true;
+                            }
+                            else if(__gestureEventsProcessed.test(Gesture::GESTURE_LONG_TAP) &&
+                                   gameplay::Game::getInstance()->getAbsoluteTime() - __pointer1.time >= GESTURE_LONG_TAP_DURATION_MIN)
+                            {
+                                gameplay::Platform::gestureLongTapEventInternal(x, y, gameplay::Game::getInstance()->getAbsoluteTime() - __pointer1.time);
+                                gestureDetected = true;
+                            }    
                         }
-                        else if(__gestureEventsProcessed.test(Gesture::GESTURE_TAP) &&
-                               gameplay::Game::getInstance()->getAbsoluteTime() - __pointer1.time < GESTURE_TAP_DURATION_MAX)
+					    __pointer1.pressed = false;
+
+                        if (!gestureDetected && (__multiTouch || __primaryTouchId == pointerId) )
                         {
-                            gameplay::Platform::gestureTapEventInternal(x, y);
-                            gestureDetected = true;
+                            gameplay::Platform::touchEventInternal(Touch::TOUCH_RELEASE, 
+                                                                   AMotionEvent_getX(event, pointerIndex), 
+                                                                   AMotionEvent_getY(event, pointerIndex), pointerId);
                         }
-                        else if(__gestureEventsProcessed.test(Gesture::GESTURE_LONG_TAP) &&
-                               gameplay::Game::getInstance()->getAbsoluteTime() - __pointer1.time >= GESTURE_LONG_TAP_DURATION_MIN)
-                        {
-                            gameplay::Platform::gestureLongTapEventInternal(x, y, gameplay::Game::getInstance()->getAbsoluteTime() - __pointer1.time);
-                            gestureDetected = true;
-                        }    
+                        if (__primaryTouchId == pointerId)
+                            __primaryTouchId = -1;
                     }
-					__pointer1.pressed = false;
-
-                    if (!gestureDetected && (__multiTouch || __primaryTouchId == pointerId) )
-                    {
-                        gameplay::Platform::touchEventInternal(Touch::TOUCH_RELEASE, AMotionEvent_getX(event, pointerIndex), AMotionEvent_getY(event, pointerIndex), pointerId);
-                    }
-                    if (__primaryTouchId == pointerId)
-                        __primaryTouchId = -1;
-                }
-                break;
+                    break;
 
-            case AMOTION_EVENT_ACTION_MOVE:
-                {
-                    // ACTION_MOVE events are batched, unlike the other events.
-                    pointerCount = AMotionEvent_getPointerCount(event);
-                    for (size_t i = 0; i < pointerCount; ++i)
+                case AMOTION_EVENT_ACTION_MOVE:
                     {
-                        pointerId = AMotionEvent_getPointerId(event, i);
-                        x = AMotionEvent_getX(event, i);
-                        y = AMotionEvent_getY(event, i);
-                        
-                        bool gestureDetected = false;
-						if (__pointer0.pressed)
-						{
-							//The two pointers are pressed and the event was done by one of it
-							if (__pointer1.pressed && (pointerId == __pointer0.pointerId || pointerId == __pointer1.pointerId))
-							{
-								if (__pointer0.pointerId == __pointer1.pointerId)
-								{
-									__gesturePinching = false;
-									break;
-								}
-								//Test for pinch
-								if (__gestureEventsProcessed.test(Gesture::GESTURE_PINCH))
-								{
-									int pointer0Distance, pointer1Distance;
-
-									if (__pointer0.pointerId == pointerId)
-									{
-										__gesturePointer0LastPosition = __gesturePointer0CurrentPosition;
-										__gesturePointer0CurrentPosition = std::pair<int, int>(x, y);
-										__gesturePointer0Delta = sqrt(pow(static_cast<float>(x - __pointer0.x), 2) +
-																	pow(static_cast<float>(y - __pointer0.y), 2));
-									}
-									else
-									{
-										__gesturePointer1LastPosition = __gesturePointer1CurrentPosition;
-										__gesturePointer1CurrentPosition = std::pair<int, int>(x, y);
-										__gesturePointer1Delta = sqrt(pow(static_cast<float>(x - __pointer1.x), 2) +
-																	pow(static_cast<float>(y - __pointer1.y), 2));
-									}
-									if (!__gesturePinching &&
-										__gesturePointer0Delta >= GESTURE_PINCH_DISTANCE_MIN &&
-										__gesturePointer1Delta >= GESTURE_PINCH_DISTANCE_MIN)
-									{
-										__gesturePinching = true;
-										__gesturePinchCentroid = std::pair<int, int>((__pointer0.x + __pointer1.x) / 2,
-																					(__pointer0.y + __pointer1.y) / 2);
-									}
-									if (__gesturePinching)
-									{
-										int currentDistancePointer0, currentDistancePointer1;
-										int lastDistancePointer0, lastDistancePointer1;
-										float scale;
-
-										currentDistancePointer0 = sqrt(pow(static_cast<float>(__gesturePinchCentroid.first - __gesturePointer0CurrentPosition.first), 2) + pow(static_cast<float>(__gesturePinchCentroid.second - __gesturePointer0CurrentPosition.second), 2));
-										lastDistancePointer0 = sqrt(pow(static_cast<float>(__gesturePinchCentroid.first - __gesturePointer0LastPosition.first), 2) + pow(static_cast<float>(__gesturePinchCentroid.second - __gesturePointer0LastPosition.second), 2));
-										currentDistancePointer1 = sqrt(pow(static_cast<float>(__gesturePinchCentroid.first - __gesturePointer1CurrentPosition.first), 2) + pow(static_cast<float>(__gesturePinchCentroid.second - __gesturePointer1CurrentPosition.second), 2));
-										lastDistancePointer1 = sqrt(pow(static_cast<float>(__gesturePinchCentroid.first - __gesturePointer1LastPosition.first), 2) + pow(static_cast<float>(__gesturePinchCentroid.second - __gesturePointer1LastPosition.second), 2));
-										if (pointerId == __pointer0.pointerId)
-											scale = ((float) currentDistancePointer0) / ((float) lastDistancePointer0);
-										else
-											scale = ((float) currentDistancePointer1) / ((float) lastDistancePointer1);
-										if (((currentDistancePointer0 >= lastDistancePointer0) && (currentDistancePointer1 >= lastDistancePointer1)) ||
-											((currentDistancePointer0 <= lastDistancePointer0) && (currentDistancePointer1 <= lastDistancePointer1)))
-										{
-											gameplay::Platform::gesturePinchEventInternal(__gesturePinchCentroid.first, __gesturePinchCentroid.second, scale);	
-											gestureDetected = true;
-										}
-										else
-											__gesturePinching = false;
-									}
-								}
-							}
-							//Only the primary pointer is done and the event was done by it
-							else if (!gestureDetected && pointerId == __pointer0.pointerId)
-							{
-								//Test for drag
-								if (__gestureEventsProcessed.test(Gesture::GESTURE_DRAG))
-								{
-                            		int delta = sqrt(pow(static_cast<float>(x - __pointer0.x), 2) +
-													pow(static_cast<float>(y - __pointer0.y), 2));
-                            
-                            		if ((__gestureDraging || __gestureEventsProcessed.test(Gesture::GESTURE_DRAG)) &&
-                                 		(gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time >= GESTURE_DRAG_START_DURATION_MIN) &&
-                                		(delta >= GESTURE_DRAG_DISTANCE_MIN))
-                            		{
-                                		gameplay::Platform::gestureDragEventInternal(x, y);
-                                		__gestureDraging = true;
-                                		gestureDetected = true;
-                            		}
-								}
-							}
-						}
-
-                        if (!gestureDetected && (__multiTouch || __primaryTouchId == pointerId))
+                        // ACTION_MOVE events are batched, unlike the other events.
+                        pointerCount = AMotionEvent_getPointerCount(event);
+                        for (size_t i = 0; i < pointerCount; ++i)
                         {
-                            gameplay::Platform::touchEventInternal(Touch::TOUCH_MOVE, AMotionEvent_getX(event, i), AMotionEvent_getY(event, i), pointerId);
-                        }
-                    }
-                }
-                break;
+                            pointerId = AMotionEvent_getPointerId(event, i);
+                            x = AMotionEvent_getX(event, i);
+                            y = AMotionEvent_getY(event, i);
+                            
+                            bool gestureDetected = false;
+						    if (__pointer0.pressed)
+						    {
+							    //The two pointers are pressed and the event was done by one of it
+							    if (__pointer1.pressed && (pointerId == __pointer0.pointerId || pointerId == __pointer1.pointerId))
+							    {
+								    if (__pointer0.pointerId == __pointer1.pointerId)
+								    {
+									    __gesturePinching = false;
+									    break;
+								    }
+								    //Test for pinch
+								    if (__gestureEventsProcessed.test(Gesture::GESTURE_PINCH))
+								    {
+									    int pointer0Distance, pointer1Distance;
+
+									    if (__pointer0.pointerId == pointerId)
+									    {
+										    __gesturePointer0LastPosition = __gesturePointer0CurrentPosition;
+										    __gesturePointer0CurrentPosition = std::pair<int, int>(x, y);
+										    __gesturePointer0Delta = sqrt(pow(static_cast<float>(x - __pointer0.x), 2) +
+																	    pow(static_cast<float>(y - __pointer0.y), 2));
+									    }
+									    else
+									    {
+										    __gesturePointer1LastPosition = __gesturePointer1CurrentPosition;
+										    __gesturePointer1CurrentPosition = std::pair<int, int>(x, y);
+										    __gesturePointer1Delta = sqrt(pow(static_cast<float>(x - __pointer1.x), 2) +
+																	    pow(static_cast<float>(y - __pointer1.y), 2));
+									    }
+									    if (!__gesturePinching &&
+										    __gesturePointer0Delta >= GESTURE_PINCH_DISTANCE_MIN &&
+										    __gesturePointer1Delta >= GESTURE_PINCH_DISTANCE_MIN)
+									    {
+										    __gesturePinching = true;
+										    __gesturePinchCentroid = std::pair<int, int>((__pointer0.x + __pointer1.x) / 2,
+																					    (__pointer0.y + __pointer1.y) / 2);
+									    }
+									    if (__gesturePinching)
+									    {
+										    int currentDistancePointer0, currentDistancePointer1;
+										    int lastDistancePointer0, lastDistancePointer1;
+										    float scale;
+
+										    currentDistancePointer0 = sqrt(pow(static_cast<float>(__gesturePinchCentroid.first - __gesturePointer0CurrentPosition.first), 2) + 
+                                                                           pow(static_cast<float>(__gesturePinchCentroid.second - __gesturePointer0CurrentPosition.second), 2));
+										    lastDistancePointer0 = sqrt(pow(static_cast<float>(__gesturePinchCentroid.first - __gesturePointer0LastPosition.first), 2) + 
+                                                                        pow(static_cast<float>(__gesturePinchCentroid.second - __gesturePointer0LastPosition.second), 2));
+										    currentDistancePointer1 = sqrt(pow(static_cast<float>(__gesturePinchCentroid.first - __gesturePointer1CurrentPosition.first), 2) + 
+                                                                           pow(static_cast<float>(__gesturePinchCentroid.second - __gesturePointer1CurrentPosition.second), 2));
+										    lastDistancePointer1 = sqrt(pow(static_cast<float>(__gesturePinchCentroid.first - __gesturePointer1LastPosition.first), 2) + 
+                                                                        pow(static_cast<float>(__gesturePinchCentroid.second - __gesturePointer1LastPosition.second), 2));
+										    if (pointerId == __pointer0.pointerId)
+											    scale = ((float) currentDistancePointer0) / ((float) lastDistancePointer0);
+										    else
+											    scale = ((float) currentDistancePointer1) / ((float) lastDistancePointer1);
+										    if (((currentDistancePointer0 >= lastDistancePointer0) && (currentDistancePointer1 >= lastDistancePointer1)) ||
+											    ((currentDistancePointer0 <= lastDistancePointer0) && (currentDistancePointer1 <= lastDistancePointer1)))
+										    {
+											    gameplay::Platform::gesturePinchEventInternal(__gesturePinchCentroid.first, __gesturePinchCentroid.second, scale);	
+											    gestureDetected = true;
+										    }
+										    else
+											    __gesturePinching = false;
+									    }
+								    }
+							    }
+							    // Only the primary pointer is done and the event was done by it
+							    else if (!gestureDetected && pointerId == __pointer0.pointerId)
+							    {
+								    //Test for drag
+								    if (__gestureEventsProcessed.test(Gesture::GESTURE_DRAG))
+								    {
+                                		int delta = sqrt(pow(static_cast<float>(x - __pointer0.x), 2) +
+													    pow(static_cast<float>(y - __pointer0.y), 2));
+                                
+                                		if ((__gestureDraging || __gestureEventsProcessed.test(Gesture::GESTURE_DRAG)) &&
+                                     		(gameplay::Game::getInstance()->getAbsoluteTime() - __pointer0.time >= GESTURE_DRAG_START_DURATION_MIN) &&
+                                    		(delta >= GESTURE_DRAG_DISTANCE_MIN))
+                                		{
+                                    		gameplay::Platform::gestureDragEventInternal(x, y);
+                                    		__gestureDraging = true;
+                                    		gestureDetected = true;
+                                		}
+								    }
+							    }
+						    }
+
+                            if (!gestureDetected && (__multiTouch || __primaryTouchId == pointerId))
+                            {
+                                gameplay::Platform::touchEventInternal(Touch::TOUCH_MOVE, AMotionEvent_getX(event, i), AMotionEvent_getY(event, i), pointerId);
+                            }
+                       }
+                   }
+                   break;
+            }
         }
         return 1;
     } 
@@ -1029,17 +1133,27 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
         switch(action)
         {
             case AKEY_EVENT_ACTION_DOWN:
-                gameplay::Platform::keyEventInternal(Keyboard::KEY_PRESS, getKey(keycode, metastate));
-                if (int character = getUnicode(keycode, metastate))
-                    gameplay::Platform::keyEventInternal(Keyboard::KEY_CHAR, character);
-                if (keycode == AKEYCODE_BACK)
-                	return 1;
+                if ((source & AINPUT_SOURCE_GAMEPAD) || (source & AINPUT_SOURCE_JOYSTICK))
+                {
+                    gameplay::Platform::gamepadButtonPressedEventInternal(deviceId, gameplay::getGamepadButtonMapping(keycode));
+                }
+                else
+                {
+                    gameplay::Platform::keyEventInternal(Keyboard::KEY_PRESS, getKey(keycode, metastate));
+                    if (int character = getUnicode(keycode, metastate))
+                        gameplay::Platform::keyEventInternal(Keyboard::KEY_CHAR, character);
+                }
                 break;
                     
             case AKEY_EVENT_ACTION_UP:
-                gameplay::Platform::keyEventInternal(Keyboard::KEY_RELEASE, getKey(keycode, metastate));
-                if (keycode == AKEYCODE_BACK)
-                	return 1;
+                if ((source & AINPUT_SOURCE_GAMEPAD) || (source & AINPUT_SOURCE_JOYSTICK) )
+                {
+                    gameplay::Platform::gamepadButtonReleasedEventInternal(deviceId, gameplay::getGamepadButtonMapping(keycode));
+                }
+                else
+                {
+                    gameplay::Platform::keyEventInternal(Keyboard::KEY_RELEASE, getKey(keycode, metastate));
+                }
                 break;
         }
         return 1;
@@ -1345,8 +1459,6 @@ void Platform::setMultiSampling(bool enabled)
     {
         return;
     }
-
-    // TODO
     __multiSampling = enabled;
 }
 
@@ -1638,54 +1750,6 @@ std::string Platform::displayFileDialog(size_t mode, const char* title, const ch
     return "";
 }
 
-Gamepad::ButtonMapping getGamepadButtonMapping(jint keycode)
-{
-    switch (keycode)
-    {
-    case AKEYCODE_BUTTON_X:
-        return Gamepad::BUTTON_X;
-    case AKEYCODE_BUTTON_Y:
-        return Gamepad::BUTTON_Y;
-    case AKEYCODE_BUTTON_Z:
-        return Gamepad::BUTTON_Z;
-    case AKEYCODE_BUTTON_A:
-        return Gamepad::BUTTON_A;
-    case AKEYCODE_BUTTON_B:
-        return Gamepad::BUTTON_B;
-    case AKEYCODE_BUTTON_C:
-        return Gamepad::BUTTON_C;
-    case AKEYCODE_BUTTON_L1:
-        return Gamepad::BUTTON_L1;
-    case AKEYCODE_BUTTON_L2:
-        return Gamepad::BUTTON_L2;
-    case AKEYCODE_BUTTON_THUMBL:
-        return Gamepad::BUTTON_L3;
-    case AKEYCODE_BUTTON_R1:
-        return Gamepad::BUTTON_R1;
-    case AKEYCODE_BUTTON_R2:
-        return Gamepad::BUTTON_R2;
-    case AKEYCODE_BUTTON_THUMBR:
-        return Gamepad::BUTTON_R3;
-    case AKEYCODE_BUTTON_SELECT:
-        return Gamepad::BUTTON_MENU1;
-    case AKEYCODE_BUTTON_START:
-        return Gamepad::BUTTON_MENU2;
-    case AKEYCODE_BUTTON_MODE:
-        return Gamepad::BUTTON_MENU3;
-    case AKEYCODE_DPAD_UP:
-        return Gamepad::BUTTON_UP;
-    case AKEYCODE_DPAD_DOWN:
-        return Gamepad::BUTTON_DOWN;
-    case AKEYCODE_DPAD_LEFT:
-        return Gamepad::BUTTON_LEFT;
-    case AKEYCODE_DPAD_RIGHT:
-        return Gamepad::BUTTON_RIGHT;
-    default:
-        break;
-    }
-    return Gamepad::BUTTON_X;
-}
-
 }
 
 extern "C"
@@ -1701,26 +1765,6 @@ JNIEXPORT void JNICALL Java_org_gameplay3d_GameNativeActivity_gamepadEventDiscon
 	gameplay::Platform::gamepadEventDisconnectedInternal(deviceId);
 }
 
-JNIEXPORT void JNICALL Java_org_gameplay3d_GameNativeActivity_gamepadEventButtonPressedImpl(JNIEnv* env, jclass clazz, jint deviceId, jint keycode)
-{
-    gameplay::Platform::gamepadButtonPressedEventInternal(deviceId, gameplay::getGamepadButtonMapping(keycode));
-}
-
-JNIEXPORT void JNICALL Java_org_gameplay3d_GameNativeActivity_gamepadEventButtonReleasedImpl(JNIEnv* env, jclass clazz, jint deviceId, jint keycode)
-{
-    gameplay::Platform::gamepadButtonReleasedEventInternal(deviceId, gameplay::getGamepadButtonMapping(keycode));
-}
-
-JNIEXPORT void JNICALL Java_org_gameplay3d_GameNativeActivity_gamepadTriggerChangedEventImpl(JNIEnv* env, jclass clazz, jint deviceId, jint index, jfloat value)
-{
-    gameplay::Platform::gamepadTriggerChangedEventInternal(deviceId, index, value);
-}
-
-JNIEXPORT void JNICALL Java_org_gameplay3d_GameNativeActivity_gamepadJoystickChangedEventImpl(JNIEnv* env, jclass clazz, jint deviceId, jint index, jfloat x, jfloat y)
-{
-    gameplay::Platform::gamepadJoystickChangedEventInternal(deviceId, index, x, y);
-}
-
 }
 
 #endif

+ 16 - 38
gameplay/src/org/gameplay3d/GameNativeActivity.java

@@ -33,20 +33,21 @@ public class GameNativeActivity extends NativeActivity
     
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+        Log.i(TAG, "onCreate");
         super.onCreate(savedInstanceState);
-        
         _gamepadDevices = new SparseArray<InputDevice>();
         _inputManager = (InputManager)getSystemService(Context.INPUT_SERVICE);
 
         View decorView = getWindow().getDecorView();
         int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
         if (Build.VERSION.SDK_INT >= 18) 
-            uiOptions ^= 0x00000800; //View.SYSTEM_UI_FLAG_IMMERSIVE;
+            uiOptions ^= 0x00000800; // View.SYSTEM_UI_FLAG_IMMERSIVE;
         decorView.setSystemUiVisibility(uiOptions);
     }
     
     @Override
     public void onSaveInstanceState(Bundle outState) {
+        Log.i(TAG, "onSaveInstanceState");
         super.onSaveInstanceState(outState);
     }
     
@@ -57,29 +58,32 @@ public class GameNativeActivity extends NativeActivity
     
     @Override
     protected void onResume() {
+        Log.i(TAG, "onResume");
         super.onResume();
         _inputManager.registerInputDeviceListener(this, null);
-        int[] ids = _inputManager.getInputDeviceIds();
+        int[] ids = InputDevice.getDeviceIds();
         for (int i = 0; i < ids.length; i++) {
+            Log.i(TAG, "getGamepadDevice: " + ids[i]);
             getGamepadDevice(ids[i]);
         }
     }
     
     @Override
     protected void onPause() {
+        Log.i(TAG, "onPause");
         _inputManager.unregisterInputDeviceListener(this);
         super.onPause();
     }
     
     @Override
     public void onInputDeviceAdded(int deviceId) {
-        Log.v(TAG, "Input Device added: " + deviceId);
+        Log.i(TAG, "onInputDeviceAdded: " + deviceId);
         getGamepadDevice(deviceId);
     }
 
     @Override
     public void onInputDeviceRemoved(int deviceId) {
-        Log.v(TAG, "Input Device removed: " + deviceId);
+        Log.i(TAG, "onInputDeviceRemoved: " + deviceId);
         InputDevice device = _gamepadDevices.get(deviceId);
         if (device != null) {
             _gamepadDevices.remove(deviceId);
@@ -89,56 +93,30 @@ public class GameNativeActivity extends NativeActivity
     
     @Override
     public void onInputDeviceChanged(int deviceId) {
-        Log.i(TAG, "Input Device changed: " + deviceId);
+        Log.i(TAG, "onInputDeviceChanged: " + deviceId);
     }
     
     private InputDevice getGamepadDevice(int deviceId) {
         InputDevice device = _gamepadDevices.get(deviceId);
         if (device == null) {
-            device = _inputManager.getInputDevice(deviceId);
+            device = InputDevice.getDevice(deviceId);
             if (device == null)
                 return null;
-            if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) != 0) {
+            int sources = device.getSources();
+            if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || 
+                ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
                 _gamepadDevices.put(deviceId, device);
-                gamepadEventConnectedImpl(deviceId, 26, 2, 2, 0, 0, "", "");
-            }
-            if ((device.getSources() & InputDevice.SOURCE_JOYSTICK) != 0) {
-                _gamepadDevices.put(deviceId, device);
-                gamepadEventConnectedImpl(deviceId, 10, 0, 0, 0, 0, "", "");
+                Log.i(TAG, "gamepadEventConnectedImpl: " + device.toString());
+                gamepadEventConnectedImpl(deviceId, 26, 2, 2, 0, 0, "", device.getName());
             }
         }
         return device;
     }
     
-    @Override
-    public boolean dispatchKeyEvent(KeyEvent event) {
-        final int deviceId = event.getDeviceId();
-        final int keyCode = event.getKeyCode();
-        switch (event.getAction()) {
-            case KeyEvent.ACTION_DOWN:
-                gamepadButtonPressedEventImpl(deviceId, keyCode);
-                Log.i(TAG, "dispatchKeyEvent: " + deviceId + "," + keyCode);
-                return true;
-            case KeyEvent.ACTION_UP:
-                gamepadButtonReleasedEventImpl(deviceId, keyCode);
-                Log.i(TAG, "dispatchKeyEvent: " + deviceId + "," + keyCode);
-                return true;
-        }
-        return false;
-    }
-    
-    @Override
-    public boolean dispatchGenericMotionEvent(MotionEvent event) {
-        return false;
-    }
     
     // JNI calls to PlatformAndroid.cpp
     private static native void gamepadEventConnectedImpl(int deviceId, int buttonCount, int joystickCount, int triggerCount, int vendorId, int productId, String vendorString, String productString);
     private static native void gamepadEventDisconnectedImpl(int deviceId);
-    private static native void gamepadButtonPressedEventImpl(int deviceId, int keycode);
-    private static native void gamepadButtonReleasedEventImpl(int deviceId, int keycode);
-    private static native void gamepadTriggerChangedEventImpl(int deviceId, int index, float value);
-    private static native void gamepadJoystickChangedEventImpl(int deviceId, int index, float x, float y);
     
     private InputManager _inputManager;
     private SparseArray<InputDevice> _gamepadDevices;

+ 4 - 22
samples/browser/android/build.xml

@@ -6,7 +6,7 @@
     
     <loadproperties srcFile="project.properties" />
     
-    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" unless="sdk.dir" />
+    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project -t 1 -p . -s'" unless="sdk.dir" />
 	<fail message="OS not supported. Supported platforms: Windows, MacOS X or Linux.">
 	    <condition>
 	      <not>
@@ -20,27 +20,9 @@
 	<macrodef name="build-native">
 		<attribute name="location"/>
 	     <sequential>
-		 	<exec osfamily="unix" dir="@{location}/android" executable="android">
-			    <arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
-			<exec osfamily="unix" dir="@{location}/android" executable="ndk-build"/>
-			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
-				<arg value="/c"/>
-				<arg value="android.bat"/>
-				<arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
+            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build">
+                <arg value="-j4"/>
+            </exec>
 			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
 				<arg value="/c"/>
 				<arg value="ndk-build -j4"/>

+ 4 - 22
samples/character/android/build.xml

@@ -6,7 +6,7 @@
     
     <loadproperties srcFile="project.properties" />
 
-    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" unless="sdk.dir" />
+    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project -t 1 -p . -s'" unless="sdk.dir" />
 	<fail message="OS not supported. Supported platforms: Windows, MacOS X or Linux.">
 	    <condition>
 	      <not>
@@ -20,27 +20,9 @@
 	<macrodef name="build-native">
 		<attribute name="location"/>
 	     <sequential>
-		 	<exec osfamily="unix" dir="@{location}/android" executable="android">
-			    <arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
-			<exec osfamily="unix" dir="@{location}/android" executable="ndk-build"/>
-			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
-				<arg value="/c"/>
-				<arg value="android.bat"/>
-				<arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
+            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build">
+                <arg value="-j4"/>
+            </exec>
 			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
 				<arg value="/c"/>
 				<arg value="ndk-build -j4"/>

+ 4 - 22
samples/lua/android/build.xml

@@ -6,7 +6,7 @@
 
     <loadproperties srcFile="project.properties" />
 
-    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" unless="sdk.dir" />
+    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project -t 1 -p . -s'" unless="sdk.dir" />
 	<fail message="OS not supported. Supported platforms: Windows, MacOS X or Linux.">
 	    <condition>
 	      <not>
@@ -20,27 +20,9 @@
 	<macrodef name="build-native">
 		<attribute name="location"/>
 	     <sequential>
-		 	<exec osfamily="unix" dir="@{location}/android" executable="android">
-			    <arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
-			<exec osfamily="unix" dir="@{location}/android" executable="ndk-build"/>
-			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
-				<arg value="/c"/>
-				<arg value="android.bat"/>
-				<arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
+            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build">
+                <arg value="-j4"/>
+            </exec>
 			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
 				<arg value="/c"/>
 				<arg value="ndk-build -j4"/>

+ 5 - 23
samples/mesh/android/build.xml

@@ -3,10 +3,10 @@
 
     <property file="local.properties" />
     <property file="ant.properties" />
-    
+
     <loadproperties srcFile="project.properties" />
 
-    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" unless="sdk.dir" />
+    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project -t 1 -p . -s'" unless="sdk.dir" />
 	<fail message="OS not supported. Supported platforms: Windows, MacOS X or Linux.">
 	    <condition>
 	      <not>
@@ -20,27 +20,9 @@
 	<macrodef name="build-native">
 		<attribute name="location"/>
 	     <sequential>
-		 	<exec osfamily="unix" dir="@{location}/android" executable="android">
-			    <arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
-			<exec osfamily="unix" dir="@{location}/android" executable="ndk-build"/>
-			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
-				<arg value="/c"/>
-				<arg value="android.bat"/>
-				<arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
+            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build">
+                <arg value="-j4"/>
+            </exec>
 			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
 				<arg value="/c"/>
 				<arg value="ndk-build -j4"/>

+ 4 - 22
samples/particles/android/build.xml

@@ -6,7 +6,7 @@
     
     <loadproperties srcFile="project.properties" />
     
-    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" unless="sdk.dir" />
+    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project -t 1 -p . -s'" unless="sdk.dir" />
 	<fail message="OS not supported. Supported platforms: Windows, MacOS X or Linux.">
 	    <condition>
 	      <not>
@@ -20,27 +20,9 @@
 	<macrodef name="build-native">
 		<attribute name="location"/>
 	     <sequential>
-		 	<exec osfamily="unix" dir="@{location}/android" executable="android">
-			    <arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
-			<exec osfamily="unix" dir="@{location}/android" executable="ndk-build"/>
-			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
-				<arg value="/c"/>
-				<arg value="android.bat"/>
-				<arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
+            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build">
+                <arg value="-j4"/>
+            </exec>
 			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
 				<arg value="/c"/>
 				<arg value="ndk-build -j4"/>

+ 4 - 22
samples/racer/android/build.xml

@@ -6,7 +6,7 @@
     
     <loadproperties srcFile="project.properties" />
     
-    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" unless="sdk.dir" />
+    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project -t 1 -p . -s'" unless="sdk.dir" />
 	<fail message="OS not supported. Supported platforms: Windows, MacOS X or Linux.">
 	    <condition>
 	      <not>
@@ -20,27 +20,9 @@
 	<macrodef name="build-native">
 		<attribute name="location"/>
 	     <sequential>
-		 	<exec osfamily="unix" dir="@{location}/android" executable="android">
-			    <arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
-			<exec osfamily="unix" dir="@{location}/android" executable="ndk-build"/>
-			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
-				<arg value="/c"/>
-				<arg value="android.bat"/>
-				<arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
+            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build">
+                <arg value="-j4"/>
+            </exec>
 			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
 				<arg value="/c"/>
 				<arg value="ndk-build -j4"/>

+ 4 - 22
samples/spaceship/android/build.xml

@@ -6,7 +6,7 @@
     
     <loadproperties srcFile="project.properties" />
     
-    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" unless="sdk.dir" />
+    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project -t 1 -p . -s'" unless="sdk.dir" />
 	<fail message="OS not supported. Supported platforms: Windows, MacOS X or Linux.">
 	    <condition>
 	      <not>
@@ -20,27 +20,9 @@
 	<macrodef name="build-native">
 		<attribute name="location"/>
 	     <sequential>
-		 	<exec osfamily="unix" dir="@{location}/android" executable="android">
-			    <arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
-			<exec osfamily="unix" dir="@{location}/android" executable="ndk-build"/>
-			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
-				<arg value="/c"/>
-				<arg value="android.bat"/>
-				<arg value="update"/>
-				<arg value="project"/>
-				<arg value="-t"/>
-				<arg value="1"/>
-				<arg value="-p"/>
-				<arg value="."/>
-				<arg value="-s"/>
-			</exec>
+            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build">
+                <arg value="-j4"/>
+            </exec>
 			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
 				<arg value="/c"/>
 				<arg value="ndk-build -j4"/>

+ 33 - 5
template/android/build.xml

@@ -6,10 +6,41 @@
     
     <loadproperties srcFile="project.properties" />
 
-    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'" unless="sdk.dir"/>
+    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project -t 1 -p . -s'" unless="sdk.dir"/>
+	<fail message="OS not supported. Supported platforms: Windows, MacOS X or Linux.">
+	    <condition>
+	      <not>
+	        <or>
+	          <os family="unix"/>
+	          <os family="windows"/>
+	        </or>
+	      </not>
+	    </condition>
+	</fail>
+
+	<macrodef name="build-native">
+		<attribute name="location"/>
+	     <sequential>
+            <exec osfamily="unix" dir="@{location}/android" executable="ndk-build">
+                <arg value="-j4"/>
+            </exec>
+			<exec osfamily="windows" dir="@{location}/android" executable="cmd">
+				<arg value="/c"/>
+				<arg value="ndk-build -j4"/>
+			</exec> 
+	    </sequential>
+	</macrodef>
 
     <target name="-pre-build">
-	<mkdir dir="src"/>
+        <build-native location="../GAMEPLAY_PATH/gameplay"/>
+    	<build-native location=".."/>
+        <mkdir dir="../src/org/gameplay3d"/>
+	    <copy todir="../src/org/gameplay3d">
+            <fileset dir="../GAMEPLAY_PATH/gameplay/src/org/gameplay3d"/>
+	    </copy>
+    </target>
+
+    <target name="-post-compile">
         <copy todir="assets/res">
             <fileset dir="../res" />
         </copy>
@@ -21,9 +52,6 @@
        </copy>
     </target>
 
-    <target name="-post-compile">
-    </target>
-
     <!-- version-tag: 1 -->
     <import file="${sdk.dir}/tools/ant/build.xml" />