Panagiotis Triantafyllou

webview android 15 and up fixes

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidProjectSystem">
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
......@@ -13,7 +14,6 @@
<option value="$PROJECT_DIR$/warply_android_sdk" />
</set>
</option>
<option name="resolveExternalAnnotations" value="false" />
</GradleProjectSettings>
</option>
</component>
......
......@@ -5,7 +5,7 @@ android.buildFeatures.buildConfig = true
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.5.5'
PUBLISH_VERSION = '4.5.5.6'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
/*
* Copyright 2010-2013 Warply Ltd. All rights reserved.
*
*
* Redistribution and use in source and binary forms, without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
......@@ -30,7 +30,9 @@ import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
......@@ -43,10 +45,14 @@ import java.security.SecureRandom;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.work.Constraints;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import ly.warp.sdk.Warply;
import ly.warp.sdk.services.PushEventsClickedWorkerService;
import ly.warp.sdk.utils.WarpJSONParser;
......@@ -116,7 +122,68 @@ public class WarpViewActivity extends WarpBaseActivity {
// Methods
// ===========================================================
//OLD with edge to edge enabled
// private void initViews() {
//
// RelativeLayout root = new RelativeLayout(this);
// root.setBackgroundColor(Color.WHITE);
//
// final ImageView ivLogo = new ImageView(this);
// RelativeLayout.LayoutParams ivLogoParams = new RelativeLayout.LayoutParams(
// RelativeLayout.LayoutParams.WRAP_CONTENT,
// RelativeLayout.LayoutParams.WRAP_CONTENT);
// ivLogoParams.addRule(RelativeLayout.CENTER_IN_PARENT);
// root.addView(ivLogo, ivLogoParams);
//
// ivLogo.setImageDrawable(WarplyProperty.getProgressDrawable(this));
// ivLogo.startAnimation(WarpUtils.getPulseAnimation());
//
// mWarpView = new WarpView(this);
// RelativeLayout.LayoutParams warpViewParams = new RelativeLayout.LayoutParams(
// RelativeLayout.LayoutParams.MATCH_PARENT,
// RelativeLayout.LayoutParams.MATCH_PARENT);
// root.addView(mWarpView, warpViewParams);
//
//
// int progressHeightDp = 7;
// final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
// progressBar.setProgressDrawable(WarpUtils.getHorizontalProgressDrawable(WarplyProperty.getProgressColor(this)));
// RelativeLayout.LayoutParams progressBarParams = new RelativeLayout.LayoutParams(
// RelativeLayout.LayoutParams.MATCH_PARENT, (int)
// (progressHeightDp * getResources().getDisplayMetrics().density + 0.5f));
// mWarpView.setProgressChangeListener(new WarpView.ProgressChangeListener() {
// @Override
// public void onProgressChanged(WebView view, int newProgress) {
//
// progressBar.setProgress(newProgress);
// if (progressBar.getProgress() == 100) {
// WarpUtils.animateVisibility(ivLogo, View.INVISIBLE);
// WarpUtils.animateVisibility(progressBar, View.INVISIBLE);
// } else {
// WarpUtils.animateVisibility(ivLogo, View.VISIBLE);
// WarpUtils.animateVisibility(progressBar, View.VISIBLE);
// }
// }
// });
/// / root.addView(progressBar, progressBarParams);
// setContentView(root);
// }
// NEW that handles edge to edge properly
private void initViews() {
// Enable edge-to-edge display for SDK 35
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getWindow().setDecorFitsSystemWindows(false);
} else {
// For older Android versions
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
);
}
RelativeLayout root = new RelativeLayout(this);
root.setBackgroundColor(Color.WHITE);
......@@ -131,12 +198,45 @@ public class WarpViewActivity extends WarpBaseActivity {
ivLogo.setImageDrawable(WarplyProperty.getProgressDrawable(this));
ivLogo.startAnimation(WarpUtils.getPulseAnimation());
// Create a container for the WebView to handle insets properly
RelativeLayout webViewContainer = new RelativeLayout(this);
RelativeLayout.LayoutParams containerParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
root.addView(webViewContainer, containerParams);
mWarpView = new WarpView(this);
RelativeLayout.LayoutParams warpViewParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
root.addView(mWarpView, warpViewParams);
webViewContainer.addView(mWarpView, warpViewParams);
// Handle window insets for the WebView container
ViewCompat.setOnApplyWindowInsetsListener(webViewContainer, (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
// Apply padding to the WebView container (parent layout) instead of WebView directly
webViewContainer.setPadding(
systemBars.left,
systemBars.top,
systemBars.right,
systemBars.bottom
);
return WindowInsetsCompat.CONSUMED;
});
// Force apply insets immediately with fallback values
webViewContainer.post(() -> {
// Get status bar height programmatically as fallback
int statusBarHeight = getStatusBarHeight();
int navigationBarHeight = getNavigationBarHeight();
// Apply fallback padding to container if insets haven't been applied yet
if (webViewContainer.getPaddingTop() == 0 && statusBarHeight > 0) {
webViewContainer.setPadding(0, statusBarHeight, 0, navigationBarHeight);
}
});
int progressHeightDp = 7;
final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
......@@ -144,10 +244,10 @@ public class WarpViewActivity extends WarpBaseActivity {
RelativeLayout.LayoutParams progressBarParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, (int)
(progressHeightDp * getResources().getDisplayMetrics().density + 0.5f));
mWarpView.setProgressChangeListener(new WarpView.ProgressChangeListener() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
progressBar.setProgress(newProgress);
if (progressBar.getProgress() == 100) {
WarpUtils.animateVisibility(ivLogo, View.INVISIBLE);
......@@ -158,10 +258,28 @@ public class WarpViewActivity extends WarpBaseActivity {
}
}
});
// root.addView(progressBar, progressBarParams);
setContentView(root);
}
private int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
private int getNavigationBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
private void setPageAccordingToIntent() {
Intent intent = getIntent();
......@@ -226,4 +344,4 @@ public class WarpViewActivity extends WarpBaseActivity {
public static Intent createIntentFromURL(Context context, String url) {
return new Intent(context, WarpViewActivity.class).putExtra("sessionUrl", url);
}
}
\ No newline at end of file
}
......
......@@ -30,7 +30,7 @@ public class WarpConstants {
/**
* The version of the SDK installed in the device
*/
public static final String SDK_VERSION = "4.5.5.5";
public static final String SDK_VERSION = "4.5.5.6";
/**
* The URL of the server where it should ping
......