Skip to content

Commit 6ae45c9

Browse files
committed
reworked size setting logic
1 parent 7a0e2f2 commit 6ae45c9

File tree

2 files changed

+61
-39
lines changed

2 files changed

+61
-39
lines changed

core/src/processing/core/PApplet.java

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import android.graphics.*;
4141
import android.net.Uri;
4242
import android.opengl.GLSurfaceView;
43+
import android.os.Build;
4344
import android.os.Bundle;
4445
import android.os.Handler;
4546
import android.text.format.Time;
@@ -72,6 +73,10 @@ public class PApplet extends Fragment implements PConstants, Runnable {
7273
// static final public boolean DEBUG = true;
7374
static final public boolean DEBUG = false;
7475

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+
7580
/** The frame containing this applet (if any) */
7681
// public Frame frame;
7782

@@ -454,36 +459,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
454459
activity = getActivity();
455460
View rootView;
456461

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-
487462
// Get renderer name and class
488463
String rendererName = sketchRenderer();
489464
Class<?> rendererClass = null;
@@ -495,6 +470,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
495470
throw new RuntimeException(message, exception);
496471
}
497472

473+
// Dummy values for initialization, setSize() will be called later onSurfaceChanged()
474+
int sw = 0;
475+
int sh = 0;
498476
if (rendererName.equals(JAVA2D)) {
499477
// JAVA2D renderer
500478
surfaceView = new SketchSurfaceView(activity, sw, sh,
@@ -510,6 +488,40 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
510488
throw new RuntimeException(message);
511489
}
512490

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+
513525
//set smooth level
514526
if (smooth == 0) {
515527
g.noSmooth();
@@ -536,7 +548,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
536548
// new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
537549
// RelativeLayout.LayoutParams.FILL_PARENT);
538550

539-
if (sw == displayWidth && sh == displayHeight) {
551+
if (width == displayWidth && height == displayHeight) {
540552
// If using the full screen, don't embed inside other layouts
541553
// window.setContentView(surfaceView);
542554
rootView = surfaceView;
@@ -554,6 +566,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
554566
LinearLayout layout = new LinearLayout(activity);
555567
layout.addView(surfaceView, sketchWidth(), sketchHeight());
556568
overallLayout.addView(layout, lp);
569+
overallLayout.setBackgroundColor(sketchWindowColor());
557570
// window.setContentView(overallLayout);
558571
rootView = overallLayout;
559572
}
@@ -793,7 +806,7 @@ public SketchSurfaceView(Context context, int wide, int high,
793806
}
794807

795808
// Set semi-arbitrary size; will be set properly when surfaceChanged() called
796-
g2.setSize(wide, high);
809+
// g2.setSize(wide, high);
797810
// newGraphics.setSize(getWidth(), getHeight());
798811
g2.setParent(PApplet.this);
799812
g2.setPrimary(true);
@@ -832,11 +845,10 @@ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
832845
System.out.println("SketchSurfaceView2D.surfaceChanged() " + w + " " + h);
833846
}
834847
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());
840852
}
841853

842854

@@ -849,6 +861,10 @@ public void onWindowFocusChanged(boolean hasFocus) {
849861

850862
@Override
851863
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+
}
852868
return surfaceTouchEvent(event);
853869
}
854870

@@ -928,7 +944,7 @@ public SketchSurfaceViewGL(Context context, int wide, int high,
928944
g3.setParent(PApplet.this);
929945
g3.setPrimary(true);
930946
// Set semi-arbitrary size; will be set properly when surfaceChanged() called
931-
g3.setSize(wide, high);
947+
// g3.setSize(wide, high);
932948

933949
// Tells the default EGLContextFactory and EGLConfigChooser to create an GLES2 context.
934950
setEGLContextClientVersion(2);
@@ -1027,6 +1043,10 @@ public void onWindowFocusChanged(boolean hasFocus) {
10271043

10281044
@Override
10291045
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+
}
10301050
return surfaceTouchEvent(event);
10311051
}
10321052

core/src/processing/opengl/PGLES.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ public void onSurfaceChanged(GL10 igl, int iwidth, int iheight) {
285285
// Here is where we should initialize native libs...
286286
// lib.init(iwidth, iheight);
287287

288-
graphics.setSize(iwidth, iheight);
288+
sketch.displayHeight = iwidth;
289+
sketch.displayHeight = iheight;
290+
graphics.setSize(sketch.sketchWidth(), sketch.sketchHeight());
289291
}
290292

291293
public void onSurfaceCreated(GL10 igl, EGLConfig config) {

0 commit comments

Comments
 (0)