40
40
import android .graphics .*;
41
41
import android .net .Uri ;
42
42
import android .opengl .GLSurfaceView ;
43
+ import android .os .Build ;
43
44
import android .os .Bundle ;
44
45
import android .os .Handler ;
45
46
import android .text .format .Time ;
@@ -72,6 +73,10 @@ public class PApplet extends Fragment implements PConstants, Runnable {
72
73
// static final public boolean DEBUG = true;
73
74
static final public boolean DEBUG = false ;
74
75
76
+ // Convenience public constant holding the SDK version, akin to platform in Java mode
77
+ static final public int SDK = android .os .Build .VERSION .SDK_INT ;
78
+ // static final public int SDK = Build.VERSION_CODES.ICE_CREAM_SANDWICH; // Forcing older SDK for testing
79
+
75
80
/** The frame containing this applet (if any) */
76
81
// public Frame frame;
77
82
@@ -454,36 +459,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
454
459
activity = getActivity ();
455
460
View rootView ;
456
461
457
- DisplayMetrics dm = new DisplayMetrics ();
458
- activity .getWindowManager ().getDefaultDisplay ().getMetrics (dm );
459
- displayWidth = dm .widthPixels ;
460
- displayHeight = dm .heightPixels ;
461
-
462
- //Setting the default height and width to be fullscreen
463
- width = displayWidth ;
464
- height = displayHeight ;
465
- // println("density is " + dm.density);
466
- // println("densityDpi is " + dm.densityDpi);
467
- if (DEBUG ) println ("display metrics: " + dm );
468
-
469
- //println("screen size is " + screenWidth + "x" + screenHeight);
470
-
471
- // LinearLayout layout = new LinearLayout(this);
472
- // layout.setOrientation(LinearLayout.VERTICAL | LinearLayout.HORIZONTAL);
473
- // viewGroup = new ViewGroup();
474
- // surfaceView.setLayoutParams();
475
- // viewGroup.setLayoutParams(LayoutParams.)
476
- // RelativeLayout layout = new RelativeLayout(this);
477
- // RelativeLayout overallLayout = new RelativeLayout(this);
478
- // RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
479
- //lp.addRule(RelativeLayout.RIGHT_OF, tv1.getId());
480
- // layout.setGravity(RelativeLayout.CENTER_IN_PARENT);
481
-
482
- handleSettings ();
483
-
484
- int sw = sketchWidth ();
485
- int sh = sketchHeight ();
486
-
487
462
// Get renderer name and class
488
463
String rendererName = sketchRenderer ();
489
464
Class <?> rendererClass = null ;
@@ -495,6 +470,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
495
470
throw new RuntimeException (message , exception );
496
471
}
497
472
473
+ // Dummy values for initialization, setSize() will be called later onSurfaceChanged()
474
+ int sw = 0 ;
475
+ int sh = 0 ;
498
476
if (rendererName .equals (JAVA2D )) {
499
477
// JAVA2D renderer
500
478
surfaceView = new SketchSurfaceView (activity , sw , sh ,
@@ -510,6 +488,40 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
510
488
throw new RuntimeException (message );
511
489
}
512
490
491
+ handleSettings ();
492
+
493
+ if (fullScreen ) {
494
+ int visibility ;
495
+ if (SDK < android .os .Build .VERSION_CODES .KITKAT ) {
496
+ // Pre-4.4
497
+ visibility = View .SYSTEM_UI_FLAG_HIDE_NAVIGATION ;
498
+ } else {
499
+ // 4.4 and higher. Equivalent to:
500
+ // View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
501
+ // View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
502
+ // View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE
503
+ // so this line can be build with SDK < 4.4
504
+ visibility = 256 | 512 | 1024 | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION | 4 | 2048 ;
505
+ }
506
+ surfaceView .setSystemUiVisibility (visibility );
507
+ }
508
+
509
+ // Getting the display metrics only after setting fullscreen mode
510
+ DisplayMetrics dm = new DisplayMetrics ();
511
+ activity .getWindowManager ().getDefaultDisplay ().getMetrics (dm );
512
+ displayWidth = dm .widthPixels ;
513
+ displayHeight = dm .heightPixels ;
514
+ // println("density is " + dm.density);
515
+ // println("densityDpi is " + dm.densityDpi);
516
+ if (DEBUG ) println ("display metrics: " + dm );
517
+
518
+ if (fullScreen ) {
519
+ // Setting the default height and width to be fullscreen
520
+ width = displayWidth ;
521
+ height = displayHeight ;
522
+ }
523
+
524
+
513
525
//set smooth level
514
526
if (smooth == 0 ) {
515
527
g .noSmooth ();
@@ -536,7 +548,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
536
548
// new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
537
549
// RelativeLayout.LayoutParams.FILL_PARENT);
538
550
539
- if (sw == displayWidth && sh == displayHeight ) {
551
+ if (width == displayWidth && height == displayHeight ) {
540
552
// If using the full screen, don't embed inside other layouts
541
553
// window.setContentView(surfaceView);
542
554
rootView = surfaceView ;
@@ -554,6 +566,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
554
566
LinearLayout layout = new LinearLayout (activity );
555
567
layout .addView (surfaceView , sketchWidth (), sketchHeight ());
556
568
overallLayout .addView (layout , lp );
569
+ overallLayout .setBackgroundColor (sketchWindowColor ());
557
570
// window.setContentView(overallLayout);
558
571
rootView = overallLayout ;
559
572
}
@@ -793,7 +806,7 @@ public SketchSurfaceView(Context context, int wide, int high,
793
806
}
794
807
795
808
// Set semi-arbitrary size; will be set properly when surfaceChanged() called
796
- g2 .setSize (wide , high );
809
+ // g2.setSize(wide, high);
797
810
// newGraphics.setSize(getWidth(), getHeight());
798
811
g2 .setParent (PApplet .this );
799
812
g2 .setPrimary (true );
@@ -832,11 +845,10 @@ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
832
845
System .out .println ("SketchSurfaceView2D.surfaceChanged() " + w + " " + h );
833
846
}
834
847
surfaceChanged = true ;
835
-
836
- // width = w;
837
- // height = h;
838
- //
839
- // g.setSize(w, h);
848
+ // Display width/height migth change if the orientation changes.
849
+ displayHeight = w ;
850
+ displayHeight = h ;
851
+ g .setSize (sketchWidth (), sketchHeight ());
840
852
}
841
853
842
854
@@ -849,6 +861,10 @@ public void onWindowFocusChanged(boolean hasFocus) {
849
861
850
862
@ Override
851
863
public boolean onTouchEvent (MotionEvent event ) {
864
+ if (fullScreen && SDK < android .os .Build .VERSION_CODES .KITKAT ) {
865
+ // The best we can do pre-KitKat to keep the navigation bar hidden
866
+ surfaceView .setSystemUiVisibility (View .SYSTEM_UI_FLAG_HIDE_NAVIGATION );
867
+ }
852
868
return surfaceTouchEvent (event );
853
869
}
854
870
@@ -928,7 +944,7 @@ public SketchSurfaceViewGL(Context context, int wide, int high,
928
944
g3 .setParent (PApplet .this );
929
945
g3 .setPrimary (true );
930
946
// Set semi-arbitrary size; will be set properly when surfaceChanged() called
931
- g3 .setSize (wide , high );
947
+ // g3.setSize(wide, high);
932
948
933
949
// Tells the default EGLContextFactory and EGLConfigChooser to create an GLES2 context.
934
950
setEGLContextClientVersion (2 );
@@ -1027,6 +1043,10 @@ public void onWindowFocusChanged(boolean hasFocus) {
1027
1043
1028
1044
@ Override
1029
1045
public boolean onTouchEvent (MotionEvent event ) {
1046
+ if (fullScreen && SDK < android .os .Build .VERSION_CODES .KITKAT ) {
1047
+ // The best we can do pre-KitKat to keep the navigation bar hidden
1048
+ surfaceView .setSystemUiVisibility (View .SYSTEM_UI_FLAG_HIDE_NAVIGATION );
1049
+ }
1030
1050
return surfaceTouchEvent (event );
1031
1051
}
1032
1052
0 commit comments