瀏覽代碼

Fixed Android lock screen bug

- Fixed Android locking screen bug. OnDestroy() was called when locking
screen.
- Power button input must be handled by OS.
- AndroidManifest.xml is affected by configChanges="screenSize".
- Updated library header for android template.
victorfisac 9 年之前
父節點
當前提交
32508f6db1
共有 3 個文件被更改,包括 37 次插入15 次删除
  1. 11 3
      src/core.c
  2. 1 1
      templates/android_project/AndroidManifest.xml
  3. 25 11
      templates/android_project/jni/include/raylib.h

+ 11 - 3
src/core.c

@@ -1686,11 +1686,19 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
         int32_t keycode = AKeyEvent_getKeyCode(event);
         //int32_t AKeyEvent_getMetaState(event);
         
+        // Save current button and its state
         currentButtonState[keycode] = AKeyEvent_getAction (event);  // Down = 0, Up = 1
 
-        //if (keycode == AKEYCODE_HOME) { }
-        if (keycode == AKEYCODE_POWER) { return 1; }
-        if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
+        if (keycode == AKEYCODE_POWER)
+        {
+            // Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
+            // Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
+            // It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
+            // NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
+            // Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
+            return 0;
+        } 
+        else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
         {
             // Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
             return 1;

+ 1 - 1
templates/android_project/AndroidManifest.xml

@@ -23,7 +23,7 @@
                 android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
         <!-- Our activity is the built-in NativeActivity framework class. -->
         <activity android:name="android.app.NativeActivity"
-                android:configChanges="orientation|keyboardHidden"
+                android:configChanges="orientation|keyboardHidden|screenSize"
                 android:screenOrientation="landscape"
                 android:clearTaskOnLaunch="true" >
                 <!-- android:theme="@android:style/Theme.NoTitleBar.Fullscreen" -->

+ 25 - 11
templates/android_project/jni/include/raylib.h

@@ -186,6 +186,12 @@
 
 // TODO: Review Xbox360 USB Controller Buttons
 
+// Android Physic Buttons
+#define ANDROID_BACK            4
+#define ANDROID_MENU            82
+#define ANDROID_VOLUME_UP       24
+#define ANDROID_VOLUME_DOWN     25
+
 // Some Basic Colors
 // NOTE: Custom raylib color palette for amazing visuals on WHITE background
 #define LIGHTGRAY  (Color){ 200, 200, 200, 255 }   // Light Gray
@@ -540,6 +546,9 @@ bool IsFileDropped(void);                                   // Check if a file h
 char **GetDroppedFiles(int *count);                         // Retrieve dropped files into window
 void ClearDroppedFiles(void);                               // Clear dropped files paths buffer
 
+void StorageSaveValue(int position, int value);             // Storage save integer value (to defined position)
+int StorageLoadValue(int position);                         // Storage load integer value (from defined position)
+
 //------------------------------------------------------------------------------------
 // Input Handling Functions (Module: core)
 //------------------------------------------------------------------------------------
@@ -578,6 +587,9 @@ bool IsGamepadButtonUp(int gamepad, int button);        // Detect if a gamepad b
 int GetTouchX(void);                                    // Returns touch position X (relative to screen size)
 int GetTouchY(void);                                    // Returns touch position Y (relative to screen size)
 Vector2 GetTouchPosition(void);                         // Returns touch position XY (relative to screen size)
+bool IsButtonPressed(int button);                       // Detect if an android physic button has been pressed
+bool IsButtonDown(int button);                          // Detect if an android physic button is being pressed
+bool IsButtonReleased(int button);                      // Detect if an android physic button has been released    
 
 //------------------------------------------------------------------------------------
 // Gestures and Touch Handling Functions (Module: gestures)
@@ -793,21 +805,23 @@ void SetMaterialNormalDepth(Material *material, float depth);           // Set n
 //----------------------------------------------------------------------------------
 // Physics System Functions (engine-module: physics)
 //----------------------------------------------------------------------------------
-void InitPhysics();                                                     // Initialize all internal physics values
-void SetPhysics(Physics settings);                                      // Set physics settings values using Physics data type to overwrite internal physics settings
+void InitPhysics();                                                         // Initialize all internal physics values
+void SetPhysics(Physics settings);                                          // Set physics settings values using Physics data type to overwrite internal physics settings
 
-void AddRigidbody(int index, Rigidbody rigidbody);                      // Initialize a new rigidbody with parameters to internal index slot
-void AddCollider(int index, Collider collider);                         // Initialize a new Collider with parameters to internal index slot
+void AddRigidbody(int index, Rigidbody rigidbody);                          // Initialize a new rigidbody with parameters to internal index slot
+void AddCollider(int index, Collider collider);                             // Initialize a new Collider with parameters to internal index slot
 
-void ApplyPhysics(int index, Vector2 *position);                        // Apply physics to internal rigidbody, physics calculations are applied to position pointer parameter
-void SetRigidbodyEnabled(int index, bool state);                        // Set enabled state to a defined rigidbody
-void SetRigidbodyVelocity(int index, Vector2 velocity);                 // Set velocity of rigidbody (without considering of mass value)
-void AddRigidbodyForce(int index, Vector2 force);                       // Set rigidbody force (considering mass value)
+void ApplyPhysics(int index, Vector2 *position);                            // Apply physics to internal rigidbody, physics calculations are applied to position pointer parameter
+void SetRigidbodyEnabled(int index, bool state);                            // Set enabled state to a defined rigidbody
+void SetRigidbodyVelocity(int index, Vector2 velocity);                     // Set velocity of rigidbody (without considering of mass value)
+void SetRigidbodyAcceleration(int index, Vector2 acceleration);             // Set acceleration of rigidbody (without considering of mass value)
+void AddRigidbodyForce(int index, Vector2 force);                           // Set rigidbody force (considering mass value)
+void AddForceAtPosition(Vector2 position, float intensity, float radius);   // Add a force to all enabled rigidbodies at a position
 
-void SetColliderEnabled(int index, bool state);                         // Set enabled state to a defined collider
+void SetColliderEnabled(int index, bool state);                             // Set enabled state to a defined collider
 
-Rigidbody GetRigidbody(int index);                                      // Returns the internal rigidbody data defined by index parameter
-Collider GetCollider(int index);                                        // Returns the internal collider data defined by index parameter
+Rigidbody GetRigidbody(int index);                                          // Returns the internal rigidbody data defined by index parameter
+Collider GetCollider(int index);                                            // Returns the internal collider data defined by index parameter
 
 //------------------------------------------------------------------------------------
 // Audio Loading and Playing Functions (Module: audio)