1
1
package com .onesignal ;
2
2
3
- import static android . view . View . SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ;
3
+
4
4
5
5
import android .animation .Animator ;
6
6
import android .animation .AnimatorListenerAdapter ;
18
18
import android .view .Gravity ;
19
19
import android .view .View ;
20
20
import android .view .ViewGroup ;
21
- import android .view .WindowInsets ;
22
21
import android .view .WindowManager ;
23
22
import android .view .animation .Animation ;
24
23
import android .webkit .WebView ;
25
- import android .widget .FrameLayout ;
26
24
import android .widget .PopupWindow ;
27
25
import android .widget .RelativeLayout ;
28
26
@@ -71,10 +69,10 @@ interface InAppMessageViewListener {
71
69
private final Handler handler = new Handler ();
72
70
private int pageWidth ;
73
71
private int pageHeight ;
74
- private int marginPxSizeLeft = 0 ;
75
- private int marginPxSizeRight = 0 ;
76
- private int marginPxSizeTop = 0 ;
77
- private int marginPxSizeBottom = 0 ;
72
+ private int marginPxSizeLeft = dpToPx ( 24 ) ;
73
+ private int marginPxSizeRight = dpToPx ( 24 ) ;
74
+ private int marginPxSizeTop = dpToPx ( 24 ) ;
75
+ private int marginPxSizeBottom = dpToPx ( 24 ) ;
78
76
private double displayDuration ;
79
77
private boolean hasBackground ;
80
78
private boolean shouldDismissWhenActive = false ;
@@ -104,10 +102,10 @@ interface InAppMessageViewListener {
104
102
* @param content in app message content and style
105
103
*/
106
104
private void setMarginsFromContent (OSInAppMessageContent content ) {
107
- this .marginPxSizeTop = 0 ;
108
- this .marginPxSizeBottom = 0 ;
109
- this .marginPxSizeLeft = 0 ;
110
- this .marginPxSizeRight = 0 ;
105
+ this .marginPxSizeTop = content . getUseHeightMargin () ? dpToPx ( 24 ) : 0 ;
106
+ this .marginPxSizeBottom = content . getUseHeightMargin () ? dpToPx ( 24 ) : 0 ;
107
+ this .marginPxSizeLeft = content . getUseWidthMargin () ? dpToPx ( 24 ) : 0 ;
108
+ this .marginPxSizeRight = content . getUseWidthMargin () ? dpToPx ( 24 ) : 0 ;
111
109
}
112
110
113
111
void setWebView (WebView webView ) {
@@ -280,40 +278,19 @@ public void run() {
280
278
private void createPopupWindow (@ NonNull RelativeLayout parentRelativeLayout ) {
281
279
popupWindow = new PopupWindow (
282
280
parentRelativeLayout ,
283
- WindowManager .LayoutParams .FILL_PARENT ,
284
- WindowManager .LayoutParams .FILL_PARENT ,
281
+ hasBackground ? WindowManager .LayoutParams .MATCH_PARENT : pageWidth ,
282
+ hasBackground ? WindowManager .LayoutParams .MATCH_PARENT : WindowManager . LayoutParams . WRAP_CONTENT ,
285
283
true
286
284
);
287
285
popupWindow .setBackgroundDrawable (new ColorDrawable (Color .TRANSPARENT ));
288
286
popupWindow .setTouchable (true );
289
287
// NOTE: This seems like the key to getting fullscreen under notches working?!
290
288
popupWindow .setClippingEnabled (false );
291
289
292
- // popupWindow.setOverlapAnchor(false);
293
-
294
290
View container = (View )popupWindow .getContentView ();
295
291
System .out .println ("container: " + container );
296
292
System .out .println ("container.getClass: " + container .getClass ());
297
293
298
- container .setSystemUiVisibility (
299
- View .SYSTEM_UI_FLAG_IMMERSIVE
300
- // Set the content to appear under the system bars so that the
301
- // content doesn't resize when the system bars hide and show.
302
- | View .SYSTEM_UI_FLAG_LAYOUT_STABLE
303
- | View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
304
- | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
305
- // Hide the nav bar and status bar
306
- | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
307
- | View .SYSTEM_UI_FLAG_FULLSCREEN );
308
-
309
-
310
- // Windows layout
311
- // LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
312
- // LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
313
-
314
- // popupWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
315
- // popupWindow.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
316
-
317
294
int gravity = 0 ;
318
295
if (!hasBackground ) {
319
296
switch (displayLocation ) {
@@ -325,7 +302,7 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) {
325
302
break ;
326
303
case CENTER_MODAL :
327
304
case FULL_SCREEN :
328
- gravity = Gravity .NO_GRAVITY ;
305
+ gravity = Gravity .CENTER_HORIZONTAL ;
329
306
break ;
330
307
}
331
308
}
@@ -343,64 +320,6 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) {
343
320
0 ,
344
321
0
345
322
);
346
-
347
- FrameLayout rootView = (FrameLayout )popupWindow .getContentView ().getRootView ();
348
- System .out .println ("rootView: " + rootView );
349
- System .out .println ("rootView.getClass: " + rootView .getClass ());
350
- // rootView.setFitsSystemWindows(true);
351
-
352
- // crashes, to soon to get insets
353
- // System.out.println("rootView.getRootWindowInsets(): " + rootView.getRootWindowInsets());
354
- // System.out.println("rootView.getRootWindowInsets().top: " + rootView.getRootWindowInsets().getStableInsetTop());
355
-
356
- // rootView.setTop(0);
357
- // rootView.setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
358
-
359
- rootView .setSystemUiVisibility (
360
- View .SYSTEM_UI_FLAG_IMMERSIVE
361
- // Set the content to appear under the system bars so that the
362
- // content doesn't resize when the system bars hide and show.
363
- | View .SYSTEM_UI_FLAG_LAYOUT_STABLE
364
- | View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
365
- | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
366
- // Hide the nav bar and status bar
367
- | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
368
- | View .SYSTEM_UI_FLAG_FULLSCREEN );
369
-
370
-
371
- // rootView.layout(0,0,0,0);
372
- // rootView.forceLayout();
373
-
374
- // rootView.setLayoutParams(new FrameLayout.LayoutParams(9999,9999));
375
-
376
- // rootView.setBackgroundColor(0);
377
-
378
- // int windowLocation[] = new int[2];
379
- // rootView.getLocationInWindow(windowLocation);
380
- // System.out.println("rootView.getLocationInWindow(): " + windowLocation);
381
- //
382
- // int screenLocation[] = new int[2];
383
- // rootView.getLocationOnScreen(screenLocation);
384
- // System.out.println("rootView.getLocationOnScreen(): " + screenLocation);
385
-
386
- // android.widget.PopupWindow$PopupDecorView
387
-
388
- // Seems these are all zero
389
- // rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
390
- // @Override
391
- // public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
392
- // System.out.println("OnApplyWindowInsetsListener: " + insets);
393
- // return null;
394
- // }
395
- // });
396
-
397
-
398
- // popupWindow.showAtLocation(
399
- // currentActivity.getWindow().getDecorView(),
400
- // gravity,
401
- // 0,
402
- // -20
403
- // );
404
323
}
405
324
406
325
private void setUpParentRelativeLayout (Context context ) {
0 commit comments