3939import android .content .res .AssetManager ;
4040import android .graphics .*;
4141import android .net .Uri ;
42+ import android .os .Build ;
4243import android .os .Bundle ;
4344import android .support .v4 .content .ContextCompat ;
4445import android .view .LayoutInflater ;
4748import android .view .SurfaceView ;
4849import android .view .View ;
4950import android .view .ViewGroup ;
51+ import android .view .ViewTreeObserver ;
5052import android .view .inputmethod .InputMethodManager ;
5153import processing .a2d .PGraphicsAndroid2D ;
5254import processing .android .AppComponent ;
@@ -73,7 +75,8 @@ public class PApplet extends Object implements PConstants {
7375 static final public boolean DEBUG = false ;
7476
7577 // Convenience public constant holding the SDK version, akin to platform in Java mode
76- static final public int SDK = android .os .Build .VERSION .SDK_INT ;
78+ static final public int SDK = Build .VERSION .SDK_INT ;
79+
7780// static final public int SDK = Build.VERSION_CODES.ICE_CREAM_SANDWICH; // Forcing older SDK for testing
7881
7982 /**
@@ -108,8 +111,8 @@ public class PApplet extends Object implements PConstants {
108111// static final boolean THREAD_DEBUG = false;
109112
110113 /** Default width and height for applet when not specified */
111- static public final int DEFAULT_WIDTH = 100 ;
112- static public final int DEFAULT_HEIGHT = 100 ;
114+ static public final int DEFAULT_WIDTH = - 1 ;
115+ static public final int DEFAULT_HEIGHT = - 1 ;
113116
114117 /**
115118 * Minimum dimensions for the window holding an applet.
@@ -490,10 +493,18 @@ public void initSurface(LayoutInflater inflater, ViewGroup container,
490493
491494 handleSettings ();
492495
493- if (fullScreen && parentLayout == -1 ) {
494- // Setting the default height and width to be fullscreen
495- width = displayWidth ;
496- height = displayHeight ;
496+ if (parentLayout == -1 ) {
497+ if (fullScreen || width == -1 || height == -1 ) {
498+ // Either sketch explicitly set to full-screen mode, or not
499+ // size/fullScreen provided, so sketch uses the entire display
500+ width = displayWidth ;
501+ height = displayHeight ;
502+ }
503+ } else {
504+ // Dummy weight and height to initialize the PGraphics, will be resized
505+ // when the view associated to the parent layout is created
506+ width = 100 ;
507+ height = 100 ;
497508 }
498509
499510 String rendererName = sketchRenderer ();
@@ -514,8 +525,27 @@ public void initSurface(LayoutInflater inflater, ViewGroup container,
514525 setFullScreenVisibility ();
515526 surface .initView (width , height );
516527 } else {
517- surface .initView (inflater , container , savedInstanceState ,
518- fullScreen , width , height );
528+ surface .initView (inflater , container , savedInstanceState );
529+
530+ /*
531+ final View parent = surface.getRootView();
532+ parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
533+ @SuppressWarnings("deprecation")
534+ @Override
535+ public void onGlobalLayout() {
536+ int availableWidth = parent.getMeasuredWidth();
537+ int availableHeight = parent.getMeasuredHeight();
538+ if (availableHeight > 0 && availableWidth > 0) {
539+ System.err.println(availableWidth + " " + availableHeight);
540+ if (SDK < Build.VERSION_CODES.JELLY_BEAN) {
541+ parent.getViewTreeObserver().removeGlobalOnLayoutListener(this);
542+ } else {
543+ parent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
544+ }
545+ }
546+ }
547+ });
548+ */
519549 }
520550
521551 finished = false ; // just for clarity
@@ -626,7 +656,7 @@ public void onPermissionsGranted() {
626656
627657
628658 /**
629- * @param method "size" or "fullScreen "
659+ * @param method "size", "fullScreen", or "layout "
630660 * @param args parameters passed to the function so we can show the user
631661 * @return true if safely inside the settings() method
632662 */
@@ -1280,6 +1310,26 @@ public void size(int iwidth, int iheight, String irenderer) {
12801310 }
12811311
12821312
1313+ public void layout (int ilayout ) {
1314+ if (ilayout != this .parentLayout ) {
1315+ if (insideSettings ("layout" , ilayout )) {
1316+ this .parentLayout = ilayout ;
1317+ }
1318+ }
1319+ }
1320+
1321+
1322+ public void layout (int ilayout , String irenderer ) {
1323+ if (ilayout != this .parentLayout ||
1324+ !this .renderer .equals (irenderer )) {
1325+ if (insideSettings ("layout" , ilayout , irenderer )) {
1326+ this .parentLayout = ilayout ;
1327+ this .renderer = irenderer ;
1328+ }
1329+ }
1330+ }
1331+
1332+
12831333//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12841334
12851335
0 commit comments