Main repository of MikuMikuStudio
Revision | f4c9690e81f1be68fc5e489944449fb80e16aa1c (tree) |
---|---|
Time | 2013-05-11 12:53:09 |
Author | iwgeric@gmail.com <iwgeric@gmai...> |
Commiter | iwgeric@gmail.com |
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: http://jmonkeyengine.googlecode.com/svn/trunk@10607 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -243,67 +243,16 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt | ||
243 | 243 | protected void onResume() { |
244 | 244 | logger.fine("onResume"); |
245 | 245 | super.onResume(); |
246 | - if (view != null) { | |
247 | - view.onResume(); | |
248 | - } | |
249 | - if (app != null) { | |
250 | - //resume the audio | |
251 | - AudioRenderer result = app.getAudioRenderer(); | |
252 | - if (result != null) { | |
253 | - if (result instanceof AndroidAudioRenderer) { | |
254 | - AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; | |
255 | - renderer.resumeAll(); | |
256 | - } | |
257 | - } | |
258 | - //resume the sensors (aka joysticks) | |
259 | - if (app.getContext() != null) { | |
260 | - JoyInput joyInput = app.getContext().getJoyInput(); | |
261 | - if (joyInput != null) { | |
262 | - if (joyInput instanceof AndroidSensorJoyInput) { | |
263 | - AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; | |
264 | - androidJoyInput.resumeSensors(); | |
265 | - } | |
266 | - } | |
267 | - } | |
268 | - } | |
269 | - | |
270 | - isGLThreadPaused = false; | |
271 | 246 | |
272 | 247 | gainFocus(); |
273 | 248 | } |
274 | 249 | |
275 | 250 | @Override |
276 | 251 | protected void onPause() { |
252 | + logger.fine("onPause"); | |
277 | 253 | loseFocus(); |
278 | 254 | |
279 | - logger.fine("onPause"); | |
280 | 255 | super.onPause(); |
281 | - if (view != null) { | |
282 | - view.onPause(); | |
283 | - } | |
284 | - | |
285 | - if (app != null) { | |
286 | - //pause the audio | |
287 | - AudioRenderer result = app.getAudioRenderer(); | |
288 | - if (result != null) { | |
289 | - logger.log(Level.FINE, "pause: {0}", result.getClass().getSimpleName()); | |
290 | - if (result instanceof AndroidAudioRenderer) { | |
291 | - AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; | |
292 | - renderer.pauseAll(); | |
293 | - } | |
294 | - } | |
295 | - //pause the sensors (aka joysticks) | |
296 | - if (app.getContext() != null) { | |
297 | - JoyInput joyInput = app.getContext().getJoyInput(); | |
298 | - if (joyInput != null) { | |
299 | - if (joyInput instanceof AndroidSensorJoyInput) { | |
300 | - AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; | |
301 | - androidJoyInput.pauseSensors(); | |
302 | - } | |
303 | - } | |
304 | - } | |
305 | - } | |
306 | - isGLThreadPaused = true; | |
307 | 256 | } |
308 | 257 | |
309 | 258 | @Override |
@@ -524,14 +473,70 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt | ||
524 | 473 | } |
525 | 474 | |
526 | 475 | public void gainFocus() { |
476 | + logger.fine("gainFocus"); | |
477 | + if (view != null) { | |
478 | + view.onResume(); | |
479 | + } | |
480 | + | |
481 | + if (app != null) { | |
482 | + //resume the audio | |
483 | + AudioRenderer result = app.getAudioRenderer(); | |
484 | + if (result != null) { | |
485 | + if (result instanceof AndroidAudioRenderer) { | |
486 | + AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; | |
487 | + renderer.resumeAll(); | |
488 | + } | |
489 | + } | |
490 | + //resume the sensors (aka joysticks) | |
491 | + if (app.getContext() != null) { | |
492 | + JoyInput joyInput = app.getContext().getJoyInput(); | |
493 | + if (joyInput != null) { | |
494 | + if (joyInput instanceof AndroidSensorJoyInput) { | |
495 | + AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; | |
496 | + androidJoyInput.resumeSensors(); | |
497 | + } | |
498 | + } | |
499 | + } | |
500 | + } | |
501 | + | |
502 | + isGLThreadPaused = false; | |
503 | + | |
527 | 504 | if (app != null) { |
528 | 505 | app.gainFocus(); |
529 | 506 | } |
530 | 507 | } |
531 | 508 | |
532 | 509 | public void loseFocus() { |
510 | + logger.fine("loseFocus"); | |
533 | 511 | if (app != null) { |
534 | 512 | app.loseFocus(); |
535 | 513 | } |
514 | + | |
515 | + if (view != null) { | |
516 | + view.onPause(); | |
517 | + } | |
518 | + | |
519 | + if (app != null) { | |
520 | + //pause the audio | |
521 | + AudioRenderer result = app.getAudioRenderer(); | |
522 | + if (result != null) { | |
523 | + logger.log(Level.FINE, "pause: {0}", result.getClass().getSimpleName()); | |
524 | + if (result instanceof AndroidAudioRenderer) { | |
525 | + AndroidAudioRenderer renderer = (AndroidAudioRenderer) result; | |
526 | + renderer.pauseAll(); | |
527 | + } | |
528 | + } | |
529 | + //pause the sensors (aka joysticks) | |
530 | + if (app.getContext() != null) { | |
531 | + JoyInput joyInput = app.getContext().getJoyInput(); | |
532 | + if (joyInput != null) { | |
533 | + if (joyInput instanceof AndroidSensorJoyInput) { | |
534 | + AndroidSensorJoyInput androidJoyInput = (AndroidSensorJoyInput) joyInput; | |
535 | + androidJoyInput.pauseSensors(); | |
536 | + } | |
537 | + } | |
538 | + } | |
539 | + } | |
540 | + isGLThreadPaused = true; | |
536 | 541 | } |
537 | 542 | } |