Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: android 35 nav bar height issue #430

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
## 24.7.7
* Mitigated an issue where, on Android 35 and above, the navigation bar was overlapping with the content display.

## 24.7.6
* Added support for localization of content blocks.

* Mitigated an issue where visibility could have been wrongly assigned if a view was closed while going to background. (Experimental!)
* Fixed a bug where passing the global content callback was not possible.
* Mitigated an issue related to content actions navigation.
* Mitigated an issue that parsing internal content event segmentation.

## 24.7.5
* ! Minor breaking change ! All active views will now automatically stop when consent for "views" is revoked.

Expand Down
39 changes: 32 additions & 7 deletions sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
Expand Down Expand Up @@ -53,16 +54,24 @@ protected void onCreate(Bundle savedInstanceState) {
Log.v(Countly.TAG, "[TransparentActivity] onCreate, configPortrait x: [" + configPortrait.x + "] y: [" + configPortrait.y + "] width: [" + configPortrait.width + "] height: [" + configPortrait.height + "]");

TransparentActivityConfig config;
int navBarHeight = 0;
if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
config = configLandscape;
} else {
// This is only needed for the portrait mode and
// after android 35 the function that gives height gives the full height of the screen
// so we need to subtract the height of the navigation bar
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
navBarHeight = getNavigationBarHeight();
}

config = configPortrait;
}

config = setupConfig(config);

int width = config.width;
int height = config.height;
int height = config.height - navBarHeight;

configLandscape.listeners.add((url, webView) -> {
if (url.startsWith(URL_START)) {
Expand Down Expand Up @@ -126,23 +135,23 @@ private TransparentActivityConfig setupConfig(@Nullable TransparentActivityConfi
return config;
}

private void changeOrientation(TransparentActivityConfig config) {
private void changeOrientation(TransparentActivityConfig config, int navBarHeight) {
Log.d(Countly.TAG, "[TransparentActivity] changeOrientation, config x: [" + config.x + "] y: [" + config.y + "] width: [" + config.width + "] height: [" + config.height + "]");
WindowManager.LayoutParams params = getWindow().getAttributes();
params.x = config.x;
params.y = config.y;
params.height = config.height;
params.height = config.height - navBarHeight;
params.width = config.width;
getWindow().setAttributes(params);

ViewGroup.LayoutParams layoutParams = relativeLayout.getLayoutParams();
layoutParams.width = config.width;
layoutParams.height = config.height;
layoutParams.height = config.height - navBarHeight;
relativeLayout.setLayoutParams(layoutParams);

ViewGroup.LayoutParams webLayoutParams = webView.getLayoutParams();
webLayoutParams.width = config.width;
webLayoutParams.height = config.height;
webLayoutParams.height = config.height - navBarHeight;
webView.setLayoutParams(webLayoutParams);
}

Expand All @@ -163,13 +172,21 @@ private void changeOrientationInternal() {
case Configuration.ORIENTATION_LANDSCAPE:
if (configLandscape != null) {
configLandscape = setupConfig(configLandscape);
changeOrientation(configLandscape);
changeOrientation(configLandscape, 0);
}
break;
case Configuration.ORIENTATION_PORTRAIT:
if (configPortrait != null) {
configPortrait = setupConfig(configPortrait);
changeOrientation(configPortrait);
// This is only needed for the portrait mode and
// after android 35 the function that gives height gives the full height of the screen
// so we need to subtract the height of the navigation bar
// this is implemented twice because in the future resize_me action will be able to change the height of the content
int navBarHeight = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
navBarHeight = getNavigationBarHeight();
}
changeOrientation(configPortrait, navBarHeight);
}
break;
default:
Expand Down Expand Up @@ -368,4 +385,12 @@ private WebView createWebView(TransparentActivityConfig config) {
webView.loadUrl(config.url);
return webView;
}

private int getNavigationBarHeight() {
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return getResources().getDimensionPixelSize(resourceId);
}
return 0;
}
}
Loading