diff --git a/CHANGELOG.md b/CHANGELOG.md index e67f5930..783f528d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.7.1 + +- Use reflective status bar color on pre-Android 15 (API <35) to avoid Play deprecation warnings + ## 7.7.0 - Updated to use Embedded Messaging V2 endpoints diff --git a/OptimoveSDK/gradle.properties b/OptimoveSDK/gradle.properties index f17fb69d..a8fb9857 100644 --- a/OptimoveSDK/gradle.properties +++ b/OptimoveSDK/gradle.properties @@ -8,8 +8,8 @@ # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx1536m -sdk_version=7.7.0 -sdk_version_code=70700 +sdk_version=7.7.1 +sdk_version_code=70701 sdk_platform=Android android.useAndroidX=true android.enableJetifier=true \ No newline at end of file diff --git a/OptimoveSDK/optimove-sdk/src/main/java/com/optimove/android/optimobile/InAppMessageView.java b/OptimoveSDK/optimove-sdk/src/main/java/com/optimove/android/optimobile/InAppMessageView.java index 2269231f..f7cd8fbb 100644 --- a/OptimoveSDK/optimove-sdk/src/main/java/com/optimove/android/optimobile/InAppMessageView.java +++ b/OptimoveSDK/optimove-sdk/src/main/java/com/optimove/android/optimobile/InAppMessageView.java @@ -36,7 +36,6 @@ import androidx.annotation.AnyThread; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import androidx.annotation.UiThread; import com.optimove.android.BuildConfig; @@ -161,27 +160,46 @@ private void sendToClient(String type, JSONObject data) { String script = "window.postHostMessage(" + j.toString() + ")"; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - wv.evaluateJavascript(script, null); - } else { - wv.loadUrl("javascript:" + script); + wv.evaluateJavascript(script, null); + } + + private static boolean isLegacyStatusBarColorSupported() { + return Build.VERSION.SDK_INT < 35; + } + + private static int getStatusBarColorLegacy(Window window) { + if (!isLegacyStatusBarColorSupported() || window == null) { + return 0; } + try { + java.lang.reflect.Method method = Window.class.getMethod("getStatusBarColor"); + Object result = method.invoke(window); + if (result instanceof Integer) { + return (Integer) result; + } + } catch (Throwable ignored) {} + return 0; } - @UiThread - @SuppressWarnings("deprecation") - private void setStatusBarColorForDialog(Activity currentActivity) { - if (currentActivity == null) { + private static void setStatusBarColorLegacy(Window window, int color) { + if (!isLegacyStatusBarColorSupported() || window == null) { return; } + try { + java.lang.reflect.Method method = Window.class.getMethod("setStatusBarColor", int.class); + method.invoke(window, color); + } catch (Throwable ignored) {} + } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + @UiThread + private void setStatusBarColorForDialog(Activity currentActivity) { + if (currentActivity == null) { return; } Window window = currentActivity.getWindow(); - prevStatusBarColor = window.getStatusBarColor(); + prevStatusBarColor = getStatusBarColorLegacy(window); int flags = window.getAttributes().flags; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { @@ -198,18 +216,17 @@ private void setStatusBarColorForDialog(Activity currentActivity) { statusBarColor = currentActivity.getResources().getColor(R.color.statusBarColorForNotch); } - window.setStatusBarColor(statusBarColor); + setStatusBarColorLegacy(window, statusBarColor); } @UiThread - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void unsetStatusBarColorForDialog(Activity dialogActivity) { if (dialogActivity == null) { return; } Window window = dialogActivity.getWindow(); - window.setStatusBarColor(prevStatusBarColor); + setStatusBarColorLegacy(window, prevStatusBarColor); if (prevFlagTranslucentStatus) { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); @@ -225,7 +242,7 @@ private void closeDialog(Activity dialogActivity) { if (dialog != null) { dialog.setOnKeyListener(null); dialog.dismiss(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT < 35) { unsetStatusBarColorForDialog(dialogActivity); } } @@ -243,7 +260,7 @@ private void closeDialog(Activity dialogActivity) { @UiThread private void showWebView(@NonNull final Activity currentActivity) { try { - if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); } @@ -286,9 +303,7 @@ private void showWebView(@NonNull final Activity currentActivity) { WebSettings settings = wv.getSettings(); settings.setJavaScriptEnabled(true); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - settings.setMediaPlaybackRequiresUserGesture(false); - } + settings.setMediaPlaybackRequiresUserGesture(false); wv.addJavascriptInterface(this, JS_NAME); wv.setWebViewClient(this); @@ -315,7 +330,10 @@ private void closeCurrentMessage() { @Override public void onPageFinished(WebView view, String url) { view.setBackgroundColor(android.graphics.Color.TRANSPARENT); - setStatusBarColorForDialog(currentActivity); + if (Build.VERSION.SDK_INT < 35) { + setStatusBarColorForDialog(currentActivity); + } + pageFinished = true; sendCurrentMessageToClient(); @@ -324,7 +342,6 @@ public void onPageFinished(WebView view, String url) { } @Override - @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { super.onReceivedHttpError(view, request, errorResponse); @@ -458,7 +475,7 @@ private void maybeSetNotchInsets(Context context) { } List cutoutBoundingRectangles = displayCutout.getBoundingRects(); - if (cutoutBoundingRectangles.size() == 0) { + if (cutoutBoundingRectangles.isEmpty()) { return; }