@@ -298,21 +298,23 @@ private void printConfig(EGL10 egl, EGLDisplay display,
298
298
private EGLConfig mEglConfig = null ;
299
299
300
300
// The user program is not participating in the pause protocol.
301
- public final int PAUSE_NOT_PARTICIPATING = 0 ;
301
+ static int PAUSE_NOT_PARTICIPATING = 0 ;
302
302
303
303
// A pause has not been requested by the OS.
304
- public final int PAUSE_NONE = 1 ;
304
+ static int PAUSE_NONE = 1 ;
305
305
306
306
// A pause has been requested by Android, but the user program has
307
307
// not bothered responding yet.
308
- public final int PAUSE_REQUEST = 2 ;
308
+ static int PAUSE_REQUEST = 2 ;
309
309
310
310
// The user program is waiting in waitForResume.
311
- public final int PAUSE_WAIT_FOR_RESUME = 3 ;
311
+ static int PAUSE_WAIT_FOR_RESUME = 3 ;
312
312
313
- // This stores the state of the pause system.
314
- private int mPause = PAUSE_NOT_PARTICIPATING ;
313
+ static int PAUSE_STOP_REQUEST = 4 ;
314
+ static int PAUSE_STOP_ACK = 5 ;
315
315
316
+ // This stores the state of the pause system.
317
+ static int mPause = PAUSE_NOT_PARTICIPATING ;
316
318
317
319
private PowerManager .WakeLock wakeLock ;
318
320
@@ -330,9 +332,14 @@ private void printConfig(EGL10 egl, EGLDisplay display,
330
332
// The resource manager we use.
331
333
ResourceManager mResourceManager ;
332
334
335
+ // Our own view
336
+ static SDLSurfaceView instance = null ;
337
+
333
338
public SDLSurfaceView (Activity act , String argument ) {
334
339
super (act );
335
340
341
+ SDLSurfaceView .instance = this ;
342
+
336
343
mActivity = act ;
337
344
mResourceManager = new ResourceManager (act );
338
345
@@ -435,18 +442,62 @@ public void onResume() {
435
442
wakeLock .acquire ();
436
443
}
437
444
445
+ public void onDestroy () {
446
+ Log .w (TAG , "onDestroy() called" );
447
+ synchronized (this ) {
448
+ this .notifyAll ();
449
+
450
+ if ( mPause == PAUSE_STOP_ACK ) {
451
+ Log .d (TAG , "onDestroy() app already leaved." );
452
+ return ;
453
+ }
454
+
455
+ // application didn't leave, give 10s before closing.
456
+ // hopefully, this could be enough for launching the on_stop() trigger within the app.
457
+ mPause = PAUSE_STOP_REQUEST ;
458
+ int i = 50 ;
459
+
460
+ Log .d (TAG , "onDestroy() stop requested, wait for an event from the app" );
461
+ for (; i >= 0 && mPause == PAUSE_STOP_REQUEST ; i --) {
462
+ try {
463
+ this .wait (200 );
464
+ } catch (InterruptedException e ) {
465
+ break ;
466
+ }
467
+ }
468
+ Log .d (TAG , "onDestroy() stop finished waiting." );
469
+ }
470
+ }
471
+
472
+ static int checkStop () {
473
+ if (mPause == PAUSE_STOP_REQUEST )
474
+ return 1 ;
475
+ return 0 ;
476
+ }
477
+
478
+ static void ackStop () {
479
+ Log .d (TAG , "ackStop() notify" );
480
+ synchronized (instance ) {
481
+ mPause = PAUSE_STOP_ACK ;
482
+ instance .notifyAll ();
483
+ }
484
+ }
485
+
486
+
438
487
/**
439
488
* This method is part of the SurfaceHolder.Callback interface, and is
440
489
* not normally called or subclassed by clients of GLSurfaceView.
441
490
*/
442
491
public void surfaceCreated (SurfaceHolder holder ) {
492
+ Log .i (TAG , "surfaceCreated() is not handled :|" );
443
493
}
444
494
445
495
/**
446
496
* This method is part of the SurfaceHolder.Callback interface, and is
447
497
* not normally called or subclassed by clients of GLSurfaceView.
448
498
*/
449
499
public void surfaceDestroyed (SurfaceHolder holder ) {
500
+ Log .i (TAG , "surfaceDestroyed() is not handled :|" );
450
501
}
451
502
452
503
/**
@@ -556,10 +607,12 @@ public void run() {
556
607
nativeSetEnv ("PYTHONOPTIMIZE" , "2" );
557
608
nativeSetEnv ("PYTHONHOME" , mFilesDirectory );
558
609
nativeSetEnv ("PYTHONPATH" , mArgument + ":" + mFilesDirectory + "/lib" );
559
- //nativeSetMouseUsed();
560
610
nativeSetMultitouchUsed ();
561
611
nativeInit ();
562
612
613
+ mPause = PAUSE_STOP_ACK ;
614
+
615
+ //Log.i(TAG, "End of native init, stop everything (exit0)");
563
616
System .exit (0 );
564
617
}
565
618
0 commit comments