Преглед на файлове

Android: Moved some code from onPause/onResume to loseFocus/gainFocus to address issues/patches 593, 566, 564. Users can now override loseFocus/gainFocus in MainActivity if they do not want to pause/resume the app based on Android's lifecycle methods onPause/onResume.
https://code.google.com/p/jmonkeyengine/issues/detail?id=593
https://code.google.com/p/jmonkeyengine/issues/detail?id=564
https://code.google.com/p/jmonkeyengine/issues/detail?id=566
(Yes, there were 3 patch requests for the same thing)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10607 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

iwg..om преди 12 години
родител
ревизия
0ff86728d8
променени са 1 файла, в които са добавени 57 реда и са изтрити 52 реда
  1. 57 52
      engine/src/android/com/jme3/app/AndroidHarness.java

+ 57 - 52
engine/src/android/com/jme3/app/AndroidHarness.java

@@ -243,67 +243,16 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
     protected void onResume() {
         logger.fine("onResume");
         super.onResume();
-        if (view != null) {
-            view.onResume();
-        }
-        if (app != null) {
-            //resume the audio
-            AudioRenderer result = app.getAudioRenderer();
-            if (result != null) {
-                if (result instanceof AndroidAudioRenderer) {
-                    AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
-                    renderer.resumeAll();
-                }
-            }
-            //resume the sensors (aka joysticks)
-            if (app.getContext() != null) {
-                JoyInput joyInput = app.getContext().getJoyInput();
-                if (joyInput != null) {
-                    if (joyInput instanceof AndroidSensorJoyInput) {
-                        AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput;
-                        androidJoyInput.resumeSensors();
-                    }
-                }
-            }
-        }
-
-        isGLThreadPaused = false;
 
         gainFocus();
     }
 
     @Override
     protected void onPause() {
+        logger.fine("onPause");
         loseFocus();
 
-        logger.fine("onPause");
         super.onPause();
-        if (view != null) {
-            view.onPause();
-        }
-
-        if (app != null) {
-            //pause the audio
-            AudioRenderer result = app.getAudioRenderer();
-            if (result != null) {
-                logger.log(Level.FINE, "pause: {0}", result.getClass().getSimpleName());
-                if (result instanceof AndroidAudioRenderer) {
-                    AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
-                    renderer.pauseAll();
-                }
-            }
-            //pause the sensors (aka joysticks)
-            if (app.getContext() != null) {
-                JoyInput joyInput = app.getContext().getJoyInput();
-                if (joyInput != null) {
-                    if (joyInput instanceof AndroidSensorJoyInput) {
-                        AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput;
-                        androidJoyInput.pauseSensors();
-                    }
-                }
-            }
-        }
-        isGLThreadPaused = true;
     }
 
     @Override
@@ -524,14 +473,70 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
     }
 
     public void gainFocus() {
+        logger.fine("gainFocus");
+        if (view != null) {
+            view.onResume();
+        }
+
+        if (app != null) {
+            //resume the audio
+            AudioRenderer result = app.getAudioRenderer();
+            if (result != null) {
+                if (result instanceof AndroidAudioRenderer) {
+                    AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
+                    renderer.resumeAll();
+                }
+            }
+            //resume the sensors (aka joysticks)
+            if (app.getContext() != null) {
+                JoyInput joyInput = app.getContext().getJoyInput();
+                if (joyInput != null) {
+                    if (joyInput instanceof AndroidSensorJoyInput) {
+                        AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput;
+                        androidJoyInput.resumeSensors();
+                    }
+                }
+            }
+        }
+
+        isGLThreadPaused = false;
+
         if (app != null) {
             app.gainFocus();
         }
     }
 
     public void loseFocus() {
+        logger.fine("loseFocus");
         if (app != null) {
             app.loseFocus();
         }
+
+        if (view != null) {
+            view.onPause();
+        }
+
+        if (app != null) {
+            //pause the audio
+            AudioRenderer result = app.getAudioRenderer();
+            if (result != null) {
+                logger.log(Level.FINE, "pause: {0}", result.getClass().getSimpleName());
+                if (result instanceof AndroidAudioRenderer) {
+                    AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
+                    renderer.pauseAll();
+                }
+            }
+            //pause the sensors (aka joysticks)
+            if (app.getContext() != null) {
+                JoyInput joyInput = app.getContext().getJoyInput();
+                if (joyInput != null) {
+                    if (joyInput instanceof AndroidSensorJoyInput) {
+                        AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput;
+                        androidJoyInput.pauseSensors();
+                    }
+                }
+            }
+        }
+        isGLThreadPaused = true;
     }
 }