59
59
import com .jme3 .system .*;
60
60
import com .jme3 .util .BufferAllocatorFactory ;
61
61
import com .jme3 .util .PrimitiveAllocator ;
62
-
63
62
import java .util .concurrent .atomic .AtomicBoolean ;
64
63
import java .util .logging .Level ;
65
64
import java .util .logging .Logger ;
@@ -79,7 +78,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
79
78
protected SystemListener listener ;
80
79
protected boolean autoFlush = true ;
81
80
protected AndroidInputHandler androidInput ;
82
- protected long minFrameDuration = 0 ; // No FPS cap
81
+ protected long minFrameDuration = 0 ; // No FPS cap
83
82
protected long lastUpdateTime = 0 ;
84
83
85
84
static {
@@ -90,8 +89,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
90
89
}
91
90
}
92
91
93
- public OGLESContext () {
94
- }
92
+ public OGLESContext () {}
95
93
96
94
@ Override
97
95
public Type getType () {
@@ -115,9 +113,11 @@ public GLSurfaceView createView(Context context) {
115
113
if (Build .VERSION .SDK_INT < Build .VERSION_CODES .ICE_CREAM_SANDWICH ) {
116
114
// below 4.0, check OpenGL ES 2.0 support.
117
115
if (info .reqGlEsVersion < 0x20000 ) {
118
- throw new UnsupportedOperationException ("OpenGL ES 2.0 or better is not supported on this device" );
116
+ throw new UnsupportedOperationException (
117
+ "OpenGL ES 2.0 or better is not supported on this device"
118
+ );
119
119
}
120
- } else if (Build .VERSION .SDK_INT < 9 ){
120
+ } else if (Build .VERSION .SDK_INT < 9 ) {
121
121
throw new UnsupportedOperationException ("jME3 requires Android 2.3 or later" );
122
122
}
123
123
@@ -127,7 +127,7 @@ public GLSurfaceView createView(Context context) {
127
127
if (androidInput == null ) {
128
128
if (Build .VERSION .SDK_INT >= 14 ) {
129
129
androidInput = new AndroidInputHandler14 ();
130
- } else if (Build .VERSION .SDK_INT >= 9 ){
130
+ } else if (Build .VERSION .SDK_INT >= 9 ) {
131
131
androidInput = new AndroidInputHandler ();
132
132
}
133
133
}
@@ -137,7 +137,7 @@ public GLSurfaceView createView(Context context) {
137
137
// setEGLContextClientVersion must be set before calling setRenderer
138
138
// this means it cannot be set in AndroidConfigChooser (too late)
139
139
// use proper openGL ES version
140
- view .setEGLContextClientVersion (info .reqGlEsVersion >> 16 );
140
+ view .setEGLContextClientVersion (info .reqGlEsVersion >> 16 );
141
141
142
142
view .setFocusableInTouchMode (true );
143
143
view .setFocusable (true );
@@ -200,22 +200,35 @@ protected void initInThread() {
200
200
logger .log (Level .FINE , "Running on thread: {0}" , Thread .currentThread ().getName ());
201
201
202
202
// Setup unhandled Exception Handler
203
- Thread .currentThread ().setUncaughtExceptionHandler (new Thread .UncaughtExceptionHandler () {
204
- @ Override
205
- public void uncaughtException (Thread thread , Throwable thrown ) {
206
- listener .handleError ("Exception thrown in " + thread .toString (), thrown );
207
- }
208
- });
203
+ Thread
204
+ .currentThread ()
205
+ .setUncaughtExceptionHandler (
206
+ new Thread .UncaughtExceptionHandler () {
207
+ @ Override
208
+ public void uncaughtException (Thread thread , Throwable thrown ) {
209
+ listener .handleError ("Exception thrown in " + thread .toString (), thrown );
210
+ }
211
+ }
212
+ );
209
213
210
214
timer = new NanoTimer ();
211
215
GL gl = new AndroidGL ();
212
216
if (settings .getBoolean ("GraphicsDebug" )) {
213
- gl = (GL ) GLDebug .createProxy (gl , gl , GL .class , GL2 .class , GLES_30 .class , GLFbo .class , GLExt .class );
217
+ gl =
218
+ (GL ) GLDebug .createProxy (
219
+ gl ,
220
+ gl ,
221
+ GL .class ,
222
+ GL2 .class ,
223
+ GLES_30 .class ,
224
+ GLFbo .class ,
225
+ GLExt .class
226
+ );
214
227
}
215
228
if (settings .getBoolean ("GraphicsTrace" )) {
216
- gl = (GL )GLTracer .createGlesTracer (gl , GL .class , GLES_30 .class , GLFbo .class , GLExt .class );
229
+ gl = (GL ) GLTracer .createGlesTracer (gl , GL .class , GLES_30 .class , GLFbo .class , GLExt .class );
217
230
}
218
- renderer = new GLRenderer (gl , (GLExt )gl , (GLFbo )gl );
231
+ renderer = new GLRenderer (gl , (GLExt ) gl , (GLFbo ) gl );
219
232
renderer .initialize ();
220
233
221
234
JmeSystem .setSoftTextDialogInput (this );
@@ -254,7 +267,7 @@ public void setSettings(AppSettings settings) {
254
267
}
255
268
256
269
if (settings .getFrameRate () > 0 ) {
257
- minFrameDuration = (long )(1000d / settings .getFrameRate ()); // ms
270
+ minFrameDuration = (long ) (1000d / settings .getFrameRate ()); // ms
258
271
logger .log (Level .FINE , "Setting min tpf: {0}ms" , minFrameDuration );
259
272
} else {
260
273
minFrameDuration = 0 ;
@@ -312,8 +325,7 @@ public Timer getTimer() {
312
325
}
313
326
314
327
@ Override
315
- public void setTitle (String title ) {
316
- }
328
+ public void setTitle (String title ) {}
317
329
318
330
@ Override
319
331
public boolean isCreated () {
@@ -329,7 +341,11 @@ public void setAutoFlushFrames(boolean enabled) {
329
341
@ Override
330
342
public void onSurfaceChanged (GL10 gl , int width , int height ) {
331
343
if (logger .isLoggable (Level .FINE )) {
332
- logger .log (Level .FINE , "GL Surface changed, width: {0} height: {1}" , new Object []{width , height });
344
+ logger .log (
345
+ Level .FINE ,
346
+ "GL Surface changed, width: {0} height: {1}" ,
347
+ new Object [] { width , height }
348
+ );
333
349
}
334
350
// update the application settings with the new resolution
335
351
settings .setResolution (width , height );
@@ -372,16 +388,14 @@ public void onDrawFrame(GL10 gl) {
372
388
373
389
// Enforce a FPS cap
374
390
if (updateDelta < minFrameDuration ) {
375
- // logger.log(Level.INFO, "lastUpdateTime: {0}, updateDelta: {1}, minTimePerFrame: {2}",
376
- // new Object[]{lastUpdateTime, updateDelta, minTimePerFrame});
391
+ // logger.log(Level.INFO, "lastUpdateTime: {0}, updateDelta: {1}, minTimePerFrame: {2}",
392
+ // new Object[]{lastUpdateTime, updateDelta, minTimePerFrame});
377
393
try {
378
394
Thread .sleep (minFrameDuration - updateDelta );
379
- } catch (InterruptedException e ) {
380
- }
395
+ } catch (InterruptedException e ) {}
381
396
}
382
397
383
398
lastUpdateTime = System .currentTimeMillis ();
384
-
385
399
}
386
400
}
387
401
@@ -402,8 +416,7 @@ public void create() {
402
416
}
403
417
404
418
@ Override
405
- public void restart () {
406
- }
419
+ public void restart () {}
407
420
408
421
@ Override
409
422
public void destroy (boolean waitFor ) {
@@ -421,76 +434,99 @@ protected void waitFor(boolean createdVal) {
421
434
while (renderable .get () != createdVal ) {
422
435
try {
423
436
Thread .sleep (10 );
424
- } catch (InterruptedException ex ) {
425
- }
437
+ } catch (InterruptedException ex ) {}
426
438
}
427
439
}
428
440
429
441
@ Override
430
- public void requestDialog (final int id , final String title , final String initialValue , final SoftTextDialogInputListener listener ) {
442
+ public void requestDialog (
443
+ final int id ,
444
+ final String title ,
445
+ final String initialValue ,
446
+ final SoftTextDialogInputListener listener
447
+ ) {
431
448
if (logger .isLoggable (Level .FINE )) {
432
- logger .log (Level .FINE , "requestDialog: title: {0}, initialValue: {1}" ,
433
- new Object []{title , initialValue });
449
+ logger .log (
450
+ Level .FINE ,
451
+ "requestDialog: title: {0}, initialValue: {1}" ,
452
+ new Object [] { title , initialValue }
453
+ );
434
454
}
435
455
436
456
final View view = JmeAndroidSystem .getView ();
437
- view .getHandler ().post (new Runnable () {
438
- @ Override
439
- public void run () {
440
-
441
- final FrameLayout layoutTextDialogInput = new FrameLayout (view .getContext ());
442
- final EditText editTextDialogInput = new EditText (view .getContext ());
443
- editTextDialogInput .setWidth (LayoutParams .FILL_PARENT );
444
- editTextDialogInput .setHeight (LayoutParams .FILL_PARENT );
445
- editTextDialogInput .setPadding (20 , 20 , 20 , 20 );
446
- editTextDialogInput .setGravity (Gravity .FILL_HORIZONTAL );
447
- //editTextDialogInput.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
448
-
449
- editTextDialogInput .setText (initialValue );
450
-
451
- switch (id ) {
452
- case SoftTextDialogInput .TEXT_ENTRY_DIALOG :
453
-
454
- editTextDialogInput .setInputType (InputType .TYPE_CLASS_TEXT );
455
- break ;
456
-
457
- case SoftTextDialogInput .NUMERIC_ENTRY_DIALOG :
458
-
459
- editTextDialogInput .setInputType (InputType .TYPE_CLASS_NUMBER | InputType .TYPE_NUMBER_FLAG_DECIMAL | InputType .TYPE_NUMBER_FLAG_SIGNED );
460
- break ;
461
-
462
- case SoftTextDialogInput .NUMERIC_KEYPAD_DIALOG :
463
-
464
- editTextDialogInput .setInputType (InputType .TYPE_CLASS_PHONE );
465
- break ;
466
-
467
- default :
468
- break ;
457
+ view
458
+ .getHandler ()
459
+ .post (
460
+ new Runnable () {
461
+ @ Override
462
+ public void run () {
463
+ final FrameLayout layoutTextDialogInput = new FrameLayout (view .getContext ());
464
+ final EditText editTextDialogInput = new EditText (view .getContext ());
465
+ editTextDialogInput .setWidth (LayoutParams .FILL_PARENT );
466
+ editTextDialogInput .setHeight (LayoutParams .FILL_PARENT );
467
+ editTextDialogInput .setPadding (20 , 20 , 20 , 20 );
468
+ editTextDialogInput .setGravity (Gravity .FILL_HORIZONTAL );
469
+ //editTextDialogInput.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
470
+
471
+ editTextDialogInput .setText (initialValue );
472
+
473
+ switch (id ) {
474
+ case SoftTextDialogInput .TEXT_ENTRY_DIALOG :
475
+ editTextDialogInput .setInputType (InputType .TYPE_CLASS_TEXT );
476
+ break ;
477
+ case SoftTextDialogInput .NUMERIC_ENTRY_DIALOG :
478
+ editTextDialogInput .setInputType (
479
+ InputType .TYPE_CLASS_NUMBER |
480
+ InputType .TYPE_NUMBER_FLAG_DECIMAL |
481
+ InputType .TYPE_NUMBER_FLAG_SIGNED
482
+ );
483
+ break ;
484
+ case SoftTextDialogInput .NUMERIC_KEYPAD_DIALOG :
485
+ editTextDialogInput .setInputType (InputType .TYPE_CLASS_PHONE );
486
+ break ;
487
+ default :
488
+ break ;
489
+ }
490
+
491
+ layoutTextDialogInput .addView (editTextDialogInput );
492
+
493
+ AlertDialog dialogTextInput = new AlertDialog .Builder (view .getContext ())
494
+ .setTitle (title )
495
+ .setView (layoutTextDialogInput )
496
+ .setPositiveButton (
497
+ "OK" ,
498
+ new DialogInterface .OnClickListener () {
499
+ @ Override
500
+ public void onClick (DialogInterface dialog , int whichButton ) {
501
+ /* User clicked OK, send COMPLETE action
502
+ * and text */
503
+ listener .onSoftText (
504
+ SoftTextDialogInputListener .COMPLETE ,
505
+ editTextDialogInput .getText ().toString ()
506
+ );
507
+ }
508
+ }
509
+ )
510
+ .setNegativeButton (
511
+ "Cancel" ,
512
+ new DialogInterface .OnClickListener () {
513
+ @ Override
514
+ public void onClick (DialogInterface dialog , int whichButton ) {
515
+ /* User clicked CANCEL, send CANCEL action
516
+ * and text */
517
+ listener .onSoftText (
518
+ SoftTextDialogInputListener .CANCEL ,
519
+ editTextDialogInput .getText ().toString ()
520
+ );
521
+ }
522
+ }
523
+ )
524
+ .create ();
525
+
526
+ dialogTextInput .show ();
527
+ }
469
528
}
470
-
471
- layoutTextDialogInput .addView (editTextDialogInput );
472
-
473
- AlertDialog dialogTextInput = new AlertDialog .Builder (view .getContext ()).setTitle (title ).setView (layoutTextDialogInput ).setPositiveButton ("OK" ,
474
- new DialogInterface .OnClickListener () {
475
- @ Override
476
- public void onClick (DialogInterface dialog , int whichButton ) {
477
- /* User clicked OK, send COMPLETE action
478
- * and text */
479
- listener .onSoftText (SoftTextDialogInputListener .COMPLETE , editTextDialogInput .getText ().toString ());
480
- }
481
- }).setNegativeButton ("Cancel" ,
482
- new DialogInterface .OnClickListener () {
483
- @ Override
484
- public void onClick (DialogInterface dialog , int whichButton ) {
485
- /* User clicked CANCEL, send CANCEL action
486
- * and text */
487
- listener .onSoftText (SoftTextDialogInputListener .CANCEL , editTextDialogInput .getText ().toString ());
488
- }
489
- }).create ();
490
-
491
- dialogTextInput .show ();
492
- }
493
- });
529
+ );
494
530
}
495
531
496
532
@ Override
@@ -542,11 +578,11 @@ public int getWindowXPosition() {
542
578
public int getWindowYPosition () {
543
579
throw new UnsupportedOperationException ("not implemented yet" );
544
580
}
545
-
581
+
546
582
/**
547
583
* Retrieves the dimensions of the input surface. Note: do not modify the
548
584
* returned object.
549
- *
585
+ *
550
586
* @return the dimensions (in pixels, left and top are 0)
551
587
*/
552
588
private Rect getSurfaceFrame () {
@@ -555,4 +591,16 @@ private Rect getSurfaceFrame() {
555
591
Rect result = holder .getSurfaceFrame ();
556
592
return result ;
557
593
}
594
+
595
+ @ Override
596
+ public Displays getDisplays () {
597
+ // TODO Auto-generated method stub
598
+ return null ;
599
+ }
600
+
601
+ @ Override
602
+ public int getPrimaryDisplay () {
603
+ // TODO Auto-generated method stub
604
+ return 0 ;
605
+ }
558
606
}
0 commit comments