Skip to content

Commit fa4753a

Browse files
committed
cleaning up InAppMessageView
1 parent 68589b3 commit fa4753a

File tree

1 file changed

+12
-93
lines changed

1 file changed

+12
-93
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/InAppMessageView.java

Lines changed: 12 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.onesignal;
22

3-
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
3+
44

55
import android.animation.Animator;
66
import android.animation.AnimatorListenerAdapter;
@@ -18,11 +18,9 @@
1818
import android.view.Gravity;
1919
import android.view.View;
2020
import android.view.ViewGroup;
21-
import android.view.WindowInsets;
2221
import android.view.WindowManager;
2322
import android.view.animation.Animation;
2423
import android.webkit.WebView;
25-
import android.widget.FrameLayout;
2624
import android.widget.PopupWindow;
2725
import android.widget.RelativeLayout;
2826

@@ -71,10 +69,10 @@ interface InAppMessageViewListener {
7169
private final Handler handler = new Handler();
7270
private int pageWidth;
7371
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);
7876
private double displayDuration;
7977
private boolean hasBackground;
8078
private boolean shouldDismissWhenActive = false;
@@ -104,10 +102,10 @@ interface InAppMessageViewListener {
104102
* @param content in app message content and style
105103
*/
106104
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;
111109
}
112110

113111
void setWebView(WebView webView) {
@@ -280,40 +278,19 @@ public void run() {
280278
private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) {
281279
popupWindow = new PopupWindow(
282280
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,
285283
true
286284
);
287285
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
288286
popupWindow.setTouchable(true);
289287
// NOTE: This seems like the key to getting fullscreen under notches working?!
290288
popupWindow.setClippingEnabled(false);
291289

292-
// popupWindow.setOverlapAnchor(false);
293-
294290
View container = (View)popupWindow.getContentView();
295291
System.out.println("container: " + container);
296292
System.out.println("container.getClass: " + container.getClass());
297293

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-
317294
int gravity = 0;
318295
if (!hasBackground) {
319296
switch (displayLocation) {
@@ -325,7 +302,7 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) {
325302
break;
326303
case CENTER_MODAL:
327304
case FULL_SCREEN:
328-
gravity = Gravity.NO_GRAVITY;
305+
gravity = Gravity.CENTER_HORIZONTAL;
329306
break;
330307
}
331308
}
@@ -343,64 +320,6 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) {
343320
0,
344321
0
345322
);
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-
// );
404323
}
405324

406325
private void setUpParentRelativeLayout(Context context) {

0 commit comments

Comments
 (0)