From e24b91222550d121c2f08a7a07dd9b4edfa46dba Mon Sep 17 00:00:00 2001 From: emawby Date: Tue, 9 Nov 2021 12:47:24 -0800 Subject: [PATCH] Renaming isFullscreen to isFullbleed to avoid confusion --- .../java/com/onesignal/InAppMessageView.java | 12 +-- .../com/onesignal/OSInAppMessageContent.kt | 4 +- .../java/com/onesignal/WebViewManager.java | 17 ++-- .../onesignal/GenerateNotificationRunner.java | 86 +++++++++---------- 4 files changed, 56 insertions(+), 63 deletions(-) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/InAppMessageView.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/InAppMessageView.java index 26c10fb261..d3f3cc741a 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/InAppMessageView.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/InAppMessageView.java @@ -18,7 +18,6 @@ import android.view.Gravity; import android.view.View; import android.view.ViewGroup; -import android.view.WindowInsets; import android.view.WindowManager; import android.view.animation.Animation; import android.webkit.WebView; @@ -287,16 +286,11 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) { true ); - OSViewUtils.getWindowHeight(currentActivity); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); popupWindow.setTouchable(true); - // NOTE: This seems like the key to getting fullscreen under notches working?! + // NOTE: This is required for getting fullscreen under notches working in portrait mode popupWindow.setClippingEnabled(false); - View container = (View)popupWindow.getContentView(); - System.out.println("container: " + container); - System.out.println("container.getClass: " + container.getClass()); - int gravity = 0; if (!hasBackground) { switch (displayLocation) { @@ -315,7 +309,7 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) { // Using panel for fullbleed IAMs and dialog for non-fullbleed. The attached dialog type // does not allow content to bleed under notches but panel does. - int displayType = this.messageContent.isFullScreen() ? + int displayType = this.messageContent.isFullBleed() ? WindowManager.LayoutParams.TYPE_APPLICATION_PANEL : WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; PopupWindowCompat.setWindowLayoutType( @@ -414,7 +408,7 @@ private CardView createCardView(Context context) { cardView.setClipChildren(false); cardView.setClipToPadding(false); cardView.setPreventCornerOverlap(false); - cardView.setBackgroundColor(Color.TRANSPARENT); + cardView.setCardBackgroundColor(Color.TRANSPARENT); return cardView; } diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSInAppMessageContent.kt b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSInAppMessageContent.kt index f6bd5aeabb..ef7fc3a51b 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSInAppMessageContent.kt +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSInAppMessageContent.kt @@ -12,7 +12,7 @@ internal open class OSInAppMessageContent constructor(jsonObject: JSONObject) { var contentHtml: String? = null var useHeightMargin: Boolean = true var useWidthMargin: Boolean = true - var isFullScreen: Boolean = false + var isFullBleed: Boolean = false // The following properties are populated from Javascript events var displayLocation: WebViewManager.Position? = null var displayDuration: Double? = null @@ -24,6 +24,6 @@ internal open class OSInAppMessageContent constructor(jsonObject: JSONObject) { var styles: JSONObject? = jsonObject.optJSONObject(STYLES) useHeightMargin = !(styles?.optBoolean(REMOVE_HEIGHT_MARGIN, false) ?: false) useWidthMargin = !(styles?.optBoolean(REMOVE_WIDTH_MARGIN, false) ?: false) - isFullScreen = !useHeightMargin + isFullBleed = !useHeightMargin } } \ No newline at end of file diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/WebViewManager.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/WebViewManager.java index 1e6b81382c..ac6ca075b0 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/WebViewManager.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/WebViewManager.java @@ -1,6 +1,5 @@ package com.onesignal; - import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.Activity; @@ -145,7 +144,7 @@ private static void setContentSafeAreaInsets(OSInAppMessageContent content, @Non } private static void initInAppMessage(@NonNull final Activity currentActivity, @NonNull OSInAppMessageInternal message, @NonNull final OSInAppMessageContent content) { - if (content.isFullScreen()) { + if (content.isFullBleed()) { setContentSafeAreaInsets(content, currentActivity); } try { @@ -161,7 +160,7 @@ private static void initInAppMessage(@NonNull final Activity currentActivity, @N OSUtils.runOnMainUIThread(new Runnable() { @Override public void run() { - webViewManager.setupWebView(currentActivity, base64Str, content.isFullScreen()); + webViewManager.setupWebView(currentActivity, base64Str, content.isFullBleed()); } }); } catch (UnsupportedEncodingException e) { @@ -229,7 +228,7 @@ public void postMessage(String message) { } private void handleResize() { - if (messageContent.isFullScreen()) { + if (messageContent.isFullBleed()) { updateSafeAreaInsets(); } } @@ -324,8 +323,8 @@ private void calculateHeightAndShowWebViewAfterNewActivity() { if (messageView == null) return; - // Don't need a CSS / HTML height update for fullscreen - if (messageView.getDisplayPosition() == Position.FULL_SCREEN && !messageContent.isFullScreen()) { + // Don't need a CSS / HTML height update for fullscreen unless its fullbleed + if (messageView.getDisplayPosition() == Position.FULL_SCREEN && !messageContent.isFullBleed()) { showMessageView(null); return; } @@ -339,7 +338,7 @@ public void run() { // At time point the webView isn't attached to a view // Set the WebView to the max screen size then run JS to evaluate the height. setWebViewToMaxSize(activity); - if (messageContent.isFullScreen()) { + if (messageContent.isFullBleed()) { updateSafeAreaInsets(); } @@ -502,7 +501,7 @@ private static void enableWebViewRemoteDebugging() { } private int getWebViewMaxSizeX(Activity activity) { - if (messageContent.isFullScreen()) { + if (messageContent.isFullBleed()) { return getFullbleedWindowWidth(activity); } else { @@ -512,7 +511,7 @@ private int getWebViewMaxSizeX(Activity activity) { } private int getWebViewMaxSizeY(Activity activity) { - int margin = messageContent.isFullScreen() ? 0 : (MARGIN_PX_SIZE * 2); + int margin = messageContent.isFullBleed() ? 0 : (MARGIN_PX_SIZE * 2); return OSViewUtils.getWindowHeight(activity) - margin; } diff --git a/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java b/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java index c2dbe7855c..97f320924b 100644 --- a/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java +++ b/OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java @@ -190,7 +190,7 @@ public static void setUpClass() throws Exception { TestHelpers.beforeTestSuite(); StaticResetHelper.saveStaticValues(); } - + @Before // Before each test public void beforeEachTest() throws Exception { blankActivityController = Robolectric.buildActivity(BlankActivity.class).create(); @@ -228,16 +228,16 @@ public static void afterEverything() throws Exception { public void afterEachTest() throws Exception { TestHelpers.afterTestCleanup(); } - + public static Bundle getBaseNotifBundle() { return getBaseNotifBundle("UUID"); } - + public static Bundle getBaseNotifBundle(String id) { Bundle bundle = new Bundle(); bundle.putString("alert", notifMessage); bundle.putString("custom", "{\"i\": \"" + id + "\"}"); - + return bundle; } @@ -246,7 +246,7 @@ private static Intent createOpenIntent(int notifId, Bundle bundle) { .putExtra(BUNDLE_KEY_ANDROID_NOTIFICATION_ID, notifId) .putExtra(BUNDLE_KEY_ONESIGNAL_DATA, OneSignalPackagePrivateHelper.bundleAsJSONObject(bundle).toString()); } - + private Intent createOpenIntent(Bundle bundle) { return createOpenIntent(ShadowRoboNotificationManager.lastNotifId, bundle); } @@ -260,7 +260,7 @@ public void shouldSetTitleCorrectly() throws Exception { threadAndTaskWait(); assertEquals("UnitTestApp", ShadowRoboNotificationManager.getLastShadowNotif().getContentTitle()); - + // Should allow title from FCM payload. bundle = getBaseNotifBundle("UUID2"); bundle.putString("title", "title123"); @@ -269,14 +269,14 @@ public void shouldSetTitleCorrectly() throws Exception { assertEquals("title123", ShadowRoboNotificationManager.getLastShadowNotif().getContentTitle()); } - + @Test @Config (sdk = 22, shadows = { ShadowGenerateNotification.class }) public void shouldProcessRestore() throws Exception { BundleCompat bundle = createInternalPayloadBundle(getBaseNotifBundle()); bundle.putInt("android_notif_id", 0); bundle.putBoolean("is_restoring", true); - + NotificationBundleProcessor_ProcessFromFCMIntentService_NoWrap(blankActivity, bundle); threadAndTaskWait(); @@ -302,7 +302,7 @@ public void shouldNotRestoreActiveNotifs() throws Exception { } private static OSNotificationOpenedResult lastOpenResult; - + @Test @Config(shadows = { ShadowGenerateNotification.class }) public void shouldContainPayloadWhenOldSummaryNotificationIsOpened() throws Exception { @@ -314,25 +314,25 @@ public void notificationOpened(OSNotificationOpenedResult result) { lastOpenResult = result; } }); - + // Display 2 notifications that will be grouped together. Bundle bundle = getBaseNotifBundle("UUID1"); bundle.putString("grp", "test1"); NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, bundle); - + bundle = getBaseNotifBundle("UUID2"); bundle.putString("grp", "test1"); NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, bundle); - + // Go forward 4 weeks time.advanceSystemTimeBy(2_419_202); - + // Display a 3 normal notification. NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, getBaseNotifBundle("UUID3")); threadAndTaskWait(); Map postedNotifs = ShadowRoboNotificationManager.notifications; - + // Open the summary notification Iterator> postedNotifsIterator = postedNotifs.entrySet().iterator(); PostedNotification postedNotification = postedNotifsIterator.next().getValue(); @@ -353,22 +353,22 @@ public void shouldSetCorrectNumberOfButtonsOnSummaryNotification() throws Except OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba"); OneSignal.initWithContext(blankActivity); threadAndTaskWait(); - + // Setup - Display a single notification with a grouped. Bundle bundle = getBaseNotifBundle("UUID1"); bundle.putString("grp", "test1"); bundle.putString("custom", "{\"i\": \"some_UUID\", \"a\": {\"actionButtons\": [{\"text\": \"test\"} ]}}"); NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, bundle); threadAndTaskWait(); - + Map postedNotifs = ShadowRoboNotificationManager.notifications; Iterator> postedNotifsIterator = postedNotifs.entrySet().iterator(); PostedNotification postedSummaryNotification = postedNotifsIterator.next().getValue(); - + assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY); assertEquals(1, postedSummaryNotification.notif.actions.length); } - + @Test @Config(shadows = { ShadowGenerateNotification.class }) public void shouldCancelAllNotificationsPartOfAGroup() throws Exception { @@ -376,7 +376,7 @@ public void shouldCancelAllNotificationsPartOfAGroup() throws Exception { OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba"); OneSignal.initWithContext(blankActivity); threadAndTaskWait(); - + // Setup - Display 3 notifications, 2 of which that will be grouped together. Bundle bundle = getBaseNotifBundle("UUID0"); NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, bundle); @@ -393,7 +393,7 @@ public void shouldCancelAllNotificationsPartOfAGroup() throws Exception { threadAndTaskWait(); assertEquals(4, ShadowRoboNotificationManager.notifications.size()); - + OneSignal.removeGroupedNotifications("test1"); threadAndTaskWait(); @@ -634,7 +634,7 @@ public void shouldCancelNotificationAndUpdateSummary() throws Exception { OneSignal.initWithContext(blankActivity); threadAndTaskWait(); runImplicitServices(); // Flushes out other services, seems to be a roboelectric bug - + // Setup - Display 3 notifications that will be grouped together. Bundle bundle = getBaseNotifBundle("UUID1"); bundle.putString("grp", "test1"); @@ -650,10 +650,10 @@ public void shouldCancelNotificationAndUpdateSummary() throws Exception { bundle.putString("grp", "test1"); NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, bundle); threadAndTaskWait(); - + Map postedNotifs = ShadowRoboNotificationManager.notifications; Iterator> postedNotifsIterator = postedNotifs.entrySet().iterator(); - + // Test - 3 notifis + 1 summary assertEquals(4, postedNotifs.size()); @@ -661,7 +661,7 @@ public void shouldCancelNotificationAndUpdateSummary() throws Exception { PostedNotification postedSummaryNotification = postedNotifsIterator.next().getValue(); assertEquals("3 new messages", postedSummaryNotification.getShadow().getContentText()); assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY); - + // Setup - Let's cancel a child notification. PostedNotification postedNotification = postedNotifsIterator.next().getValue(); OneSignal.removeNotification(postedNotification.id); @@ -674,7 +674,7 @@ public void shouldCancelNotificationAndUpdateSummary() throws Exception { postedSummaryNotification = postedNotifsIterator.next().getValue(); assertEquals("2 new messages", postedSummaryNotification.getShadow().getContentText()); assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY); - + // Setup - Let's cancel a 2nd child notification. postedNotification = postedNotifsIterator.next().getValue(); OneSignal.removeNotification(postedNotification.id); @@ -682,7 +682,7 @@ public void shouldCancelNotificationAndUpdateSummary() throws Exception { runImplicitServices(); Thread.sleep(1_000); // TODO: Service runs AsyncTask. Need to wait for this - + // Test - It should update summary notification to be the text of the last remaining one. postedNotifs = ShadowRoboNotificationManager.notifications; assertEquals(2, postedNotifs.size()); // 1 notifis + 1 summary @@ -690,11 +690,11 @@ public void shouldCancelNotificationAndUpdateSummary() throws Exception { postedSummaryNotification = postedNotifsIterator.next().getValue(); assertEquals(notifMessage, postedSummaryNotification.getShadow().getContentText()); assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY); - + // Test - Let's make sure we will have our last notification too postedNotification = postedNotifsIterator.next().getValue(); assertEquals(notifMessage, postedNotification.getShadow().getContentText()); - + // Setup - Let's cancel our 3rd and last child notification. OneSignal.removeNotification(postedNotification.id); threadAndTaskWait(); @@ -720,7 +720,7 @@ private void runImplicitServices() throws Exception { Robolectric.buildService(serviceClass, intent).create().startCommand(0, 0); } while (true); } - + @Test @Config(shadows = { ShadowGenerateNotification.class }) public void shouldUpdateBadgesWhenDismissingNotification() throws Exception { @@ -729,23 +729,23 @@ public void shouldUpdateBadgesWhenDismissingNotification() throws Exception { threadAndTaskWait(); assertEquals(notifMessage, ShadowRoboNotificationManager.getLastShadowNotif().getContentText()); assertEquals(1, ShadowBadgeCountUpdater.lastCount); - + Map postedNotifs = ShadowRoboNotificationManager.notifications; Iterator> postedNotifsIterator = postedNotifs.entrySet().iterator(); PostedNotification postedNotification = postedNotifsIterator.next().getValue(); Intent intent = Shadows.shadowOf(postedNotification.notif.deleteIntent).getSavedIntent(); NotificationOpenedProcessor_processFromContext(blankActivity, intent); - + assertEquals(0, ShadowBadgeCountUpdater.lastCount); } - + @Test public void shouldNotSetBadgesWhenNotificationPermissionIsDisabled() throws Exception { ShadowNotificationManagerCompat.enabled = false; OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba"); OneSignal.initWithContext(blankActivity); threadAndTaskWait(); - + Bundle bundle = getBaseNotifBundle(); NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, bundle); assertEquals(0, ShadowBadgeCountUpdater.lastCount); @@ -772,7 +772,7 @@ public void shouldSetBadgesWhenRestoringNotifications() throws Exception { assertNull(Shadows.shadowOf(blankActivity).getNextStartedService()); } - + @Test public void shouldNotShowNotificationWhenAlertIsBlankOrNull() throws Exception { Bundle bundle = getBaseNotifBundle(); @@ -781,7 +781,7 @@ public void shouldNotShowNotificationWhenAlertIsBlankOrNull() throws Exception { threadAndTaskWait(); assertNoNotifications(); - + bundle = getBaseNotifBundle("UUID2"); bundle.putString("alert", ""); NotificationBundleProcessor_ProcessFromFCMIntentService(blankActivity, bundle); @@ -791,7 +791,7 @@ public void shouldNotShowNotificationWhenAlertIsBlankOrNull() throws Exception { assertNotificationDbRecords(2); } - + @Test @Config(shadows = { ShadowGenerateNotification.class }) public void shouldUpdateNormalNotificationDisplayWhenReplacingANotification() throws Exception { @@ -799,7 +799,7 @@ public void shouldUpdateNormalNotificationDisplayWhenReplacingANotification() th OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba"); OneSignal.initWithContext(blankActivity); threadAndTaskWait(); - + // Setup - Display 2 notifications with the same group and collapse_id Bundle bundle = getBaseNotifBundle("UUID1"); bundle.putString("grp", "test1"); @@ -820,10 +820,10 @@ public void shouldUpdateNormalNotificationDisplayWhenReplacingANotification() th PostedNotification postedSummaryNotification = postedNotifsIterator.next().getValue(); assertEquals(notifMessage, postedSummaryNotification.getShadow().getContentText()); assertEquals(Notification.FLAG_GROUP_SUMMARY, postedSummaryNotification.notif.flags & Notification.FLAG_GROUP_SUMMARY); - + int lastNotifId = postedNotifsIterator.next().getValue().id; ShadowRoboNotificationManager.notifications.clear(); - + // Setup - Restore BundleCompat bundle2 = createInternalPayloadBundle(bundle); bundle2.putInt("android_notif_id", lastNotifId); @@ -1098,7 +1098,7 @@ public void shouldGenerate2BasicGroupNotifications() throws Exception { assertEquals(1, ShadowBadgeCountUpdater.lastCount); cursor.close(); } - + @Test public void shouldHandleOpeningInAppAlertWithGroupKeySet() { NotificationSummaryManager_updateSummaryNotificationAfterChildRemoved(blankActivity, dbHelper, "some_group", false); @@ -1120,11 +1120,11 @@ public void shouldSetButtonsCorrectly() throws Exception { // Normal notifications should be generated right from the BroadcastReceiver // without creating a service. assertNull(Shadows.shadowOf(blankActivity).getNextStartedService()); - + Map postedNotifs = ShadowRoboNotificationManager.notifications; Iterator> postedNotifsIterator = postedNotifs.entrySet().iterator(); PostedNotification lastNotification = postedNotifsIterator.next().getValue(); - + assertEquals(1, lastNotification.notif.actions.length); String json_data = shadowOf(lastNotification.notif.actions[0].actionIntent).getSavedIntent().getStringExtra(BUNDLE_KEY_ONESIGNAL_DATA); assertEquals("id1", new JSONObject(json_data).optString(BUNDLE_KEY_ACTION_ID)); @@ -2436,7 +2436,7 @@ public void shouldUseBgacAccentColor_hasMetaData() throws Exception { } /* Helpers */ - + private static void assertNoNotifications() { assertEquals(0, ShadowRoboNotificationManager.notifications.size()); }