39
39
import android .content .res .AssetManager ;
40
40
import android .graphics .*;
41
41
import android .net .Uri ;
42
+ import android .os .Build ;
42
43
import android .os .Bundle ;
43
44
import android .support .v4 .content .ContextCompat ;
44
45
import android .view .LayoutInflater ;
47
48
import android .view .SurfaceView ;
48
49
import android .view .View ;
49
50
import android .view .ViewGroup ;
51
+ import android .view .ViewTreeObserver ;
50
52
import android .view .inputmethod .InputMethodManager ;
51
53
import processing .a2d .PGraphicsAndroid2D ;
52
54
import processing .android .AppComponent ;
@@ -73,7 +75,8 @@ public class PApplet extends Object implements PConstants {
73
75
static final public boolean DEBUG = false ;
74
76
75
77
// 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
+
77
80
// static final public int SDK = Build.VERSION_CODES.ICE_CREAM_SANDWICH; // Forcing older SDK for testing
78
81
79
82
/**
@@ -108,8 +111,8 @@ public class PApplet extends Object implements PConstants {
108
111
// static final boolean THREAD_DEBUG = false;
109
112
110
113
/** 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 ;
113
116
114
117
/**
115
118
* Minimum dimensions for the window holding an applet.
@@ -490,10 +493,18 @@ public void initSurface(LayoutInflater inflater, ViewGroup container,
490
493
491
494
handleSettings ();
492
495
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 ;
497
508
}
498
509
499
510
String rendererName = sketchRenderer ();
@@ -514,8 +525,27 @@ public void initSurface(LayoutInflater inflater, ViewGroup container,
514
525
setFullScreenVisibility ();
515
526
surface .initView (width , height );
516
527
} 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
+ */
519
549
}
520
550
521
551
finished = false ; // just for clarity
@@ -626,7 +656,7 @@ public void onPermissionsGranted() {
626
656
627
657
628
658
/**
629
- * @param method "size" or "fullScreen "
659
+ * @param method "size", "fullScreen", or "layout "
630
660
* @param args parameters passed to the function so we can show the user
631
661
* @return true if safely inside the settings() method
632
662
*/
@@ -1280,6 +1310,26 @@ public void size(int iwidth, int iheight, String irenderer) {
1280
1310
}
1281
1311
1282
1312
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
+
1283
1333
//. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1284
1334
1285
1335
0 commit comments