Skip to content

Commit 9b6c06c

Browse files
committed
Fixing non-fullbleed IAMs by using type dialog instead of panel
Other cleanup as well
1 parent fa4753a commit 9b6c06c

File tree

4 files changed

+18
-34
lines changed

4 files changed

+18
-34
lines changed

Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/activity/MainActivity.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ public class MainActivity extends AppCompatActivity {
1818
protected void onCreate(Bundle savedInstanceState) {
1919
super.onCreate(savedInstanceState);
2020
setContentView(R.layout.main_activity_layout);
21-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
22-
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
23-
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
24-
}
2521

2622
viewModel = new MainActivityViewModel();
2723
OneSignal.addPermissionObserver(viewModel);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ interface InAppMessageViewListener {
7878
private boolean shouldDismissWhenActive = false;
7979
private boolean isDragging = false;
8080
private boolean disableDragDismiss = false;
81+
private OSInAppMessageContent messageContent;
8182
@NonNull private WebViewManager.Position displayLocation;
8283
private WebView webView;
8384
private RelativeLayout parentRelativeLayout;
@@ -93,6 +94,7 @@ interface InAppMessageViewListener {
9394
this.displayDuration = content.getDisplayDuration() == null ? 0 : content.getDisplayDuration();
9495
this.hasBackground = !displayLocation.isBanner();
9596
this.disableDragDismiss = disableDragDismiss;
97+
this.messageContent = content;
9698
setMarginsFromContent(content);
9799
}
98100

@@ -307,11 +309,14 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) {
307309
}
308310
}
309311

310-
// Using this instead of TYPE_APPLICATION_PANEL so the layout background does not get
311-
// cut off in immersive mode.
312+
// Using panel for fullbleed IAMs and dialog for non-fullbleed. The attached dialog type
313+
// does not allow content to bleed under notches but panel does.
314+
int displayType = this.messageContent.isFullScreen() ?
315+
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL :
316+
WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
312317
PopupWindowCompat.setWindowLayoutType(
313318
popupWindow,
314-
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL
319+
displayType
315320
);
316321

317322
popupWindow.showAtLocation(

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,14 @@ void available(@NonNull Activity currentActivity) {
7676
}
7777

7878
static int[] getWindowInsets(@NonNull Activity activity) {
79-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
80-
81-
}
8279
Rect frame = getWindowVisibleDisplayFrame(activity);
8380
View contentView = activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
8481
float topInset = (frame.top - contentView.getTop()) / Resources.getSystem().getDisplayMetrics().density;
85-
float bottomInset = (contentView.getBottom() - frame.bottom) / Resources.getSystem().getDisplayMetrics().density;;
86-
float rightInset = (frame.right - contentView.getRight()) / Resources.getSystem().getDisplayMetrics().density;;
87-
float leftInset = (contentView.getLeft() - frame.left) / Resources.getSystem().getDisplayMetrics().density;;
82+
float bottomInset = (contentView.getBottom() - frame.bottom) / Resources.getSystem().getDisplayMetrics().density;
83+
float rightInset = (frame.right - contentView.getRight()) / Resources.getSystem().getDisplayMetrics().density;
84+
float leftInset = (contentView.getLeft() - frame.left) / Resources.getSystem().getDisplayMetrics().density;
8885
return new int[]{Math.round(topInset), Math.round(bottomInset), Math.round(rightInset), Math.round(leftInset)};
8986
}
90-
/*
91-
Not using this method for now because the bottom value is not correct (we don't cover the bottom buttons)
92-
*/
93-
// Requirement: Ensure DecorView is ready by using OSViewUtils.decorViewReady
94-
@TargetApi(Build.VERSION_CODES.P)
95-
private static int[] getWindowInsetsAPI28Plus(@NonNull Activity activity) {
96-
View decorView = activity.getWindow().getDecorView();
97-
// Use use stable heights as SystemWindowInset subtracts the keyboard
98-
WindowInsets windowInsets = decorView.getRootWindowInsets();
99-
//if windowInsets.getDisplayCutout().
100-
return new int[] {windowInsets.getStableInsetTop(), windowInsets.getStableInsetBottom(),
101-
windowInsets.getStableInsetRight(), windowInsets.getStableInsetLeft()};
102-
}
10387

10488
static int getWindowWidth(@NonNull Activity activity) {
10589
return getWindowVisibleDisplayFrame(activity).width();
@@ -126,8 +110,8 @@ private static int getWindowHeightAPI23Plus(@NonNull Activity activity) {
126110
return decorView.getHeight();
127111

128112
return decorView.getHeight() -
129-
windowInsets.getStableInsetBottom();
130-
// windowInsets.getStableInsetTop();
113+
windowInsets.getStableInsetBottom() -
114+
windowInsets.getStableInsetTop();
131115
}
132116

133117
private static int getWindowHeightLollipop(@NonNull Activity activity) {

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
import android.annotation.SuppressLint;
66
import android.annotation.TargetApi;
77
import android.app.Activity;
8-
import android.graphics.Rect;
98
import android.os.Build;
109
import android.os.Handler;
1110
import android.os.Looper;
1211
import android.util.Base64;
1312
import android.view.View;
14-
import android.view.Window;
15-
import android.view.WindowInsets;
16-
import android.view.WindowManager;
1713
import android.webkit.JavascriptInterface;
1814
import android.webkit.ValueCallback;
1915
import android.webkit.WebView;
@@ -353,7 +349,10 @@ public void run() {
353349
// At time point the webView isn't attached to a view
354350
// Set the WebView to the max screen size then run JS to evaluate the height.
355351
setWebViewToMaxSize(activity);
356-
updateSafeAreaInsets();
352+
if (messageContent.isFullScreen()) {
353+
updateSafeAreaInsets();
354+
}
355+
357356
webView.evaluateJavascript(OSJavaScriptInterface.GET_PAGE_META_DATA_JS_FUNCTION, new ValueCallback<String>() {
358357
@Override
359358
public void onReceiveValue(final String value) {
@@ -509,7 +508,7 @@ private static void enableWebViewRemoteDebugging() {
509508

510509
private int getWebViewMaxSizeX(Activity activity) {
511510
int margin = messageContent.isFullScreen() ? 0 : (MARGIN_PX_SIZE * 2);
512-
return OSViewUtils.getWindowWidth(activity) - margin; //- (MARGIN_PX_SIZE * 2);
511+
return OSViewUtils.getWindowWidth(activity) - margin;
513512
}
514513

515514
private int getWebViewMaxSizeY(Activity activity) {

0 commit comments

Comments
 (0)