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: nav bar on 35 #448

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
53 changes: 20 additions & 33 deletions sdk/src/main/java/ly/count/android/sdk/TransparentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,53 +61,40 @@ 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 - navBarHeight;

configLandscape.listeners.add((url, webView) -> {
if (url.startsWith(URL_START)) {
return contentUrlAction(url, configLandscape, webView);
WebViewUrlListener listener = new WebViewUrlListener() {
@Override public boolean onUrl(String url, WebView webView) {
if (url.startsWith(URL_START)) {
return contentUrlAction(url, webView);
}
return false;
}
return false;
});
};

configPortrait.listeners.add((url, webView) -> {
if (url.startsWith(URL_START)) {
return contentUrlAction(url, configPortrait, webView);
}
return false;
});
configLandscape.listeners.add(listener);
configPortrait.listeners.add(listener);

// Configure window layout parameters
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.gravity = Gravity.TOP | Gravity.LEFT; // try out START
params.x = config.x;
params.y = config.y;
params.height = height;
params.width = width;
params.height = config.height;
params.width = config.width;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
getWindow().setAttributes(params);
getWindow().setBackgroundDrawableResource(android.R.color.transparent);

// Create and configure the layout
relativeLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(config.width, config.height);
relativeLayout.setLayoutParams(layoutParams);
webView = createWebView(config);

Expand All @@ -127,7 +114,7 @@ private void hideSystemUI() {
| View.SYSTEM_UI_FLAG_FULLSCREEN
);
}

private TransparentActivityConfig setupConfig(@Nullable TransparentActivityConfig config) {
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
Expand All @@ -154,23 +141,23 @@ private TransparentActivityConfig setupConfig(@Nullable TransparentActivityConfi
return config;
}

private void changeOrientation(TransparentActivityConfig config, int navBarHeight) {
private void changeOrientation(TransparentActivityConfig config) {
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 - navBarHeight;
params.height = config.height;
params.width = config.width;
getWindow().setAttributes(params);

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

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

Expand All @@ -191,7 +178,7 @@ private void changeOrientationInternal() {
case Configuration.ORIENTATION_LANDSCAPE:
if (configLandscape != null) {
configLandscape = setupConfig(configLandscape);
changeOrientation(configLandscape, 0);
changeOrientation(configLandscape);
}
break;
case Configuration.ORIENTATION_PORTRAIT:
Expand All @@ -205,15 +192,15 @@ private void changeOrientationInternal() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
navBarHeight = getNavigationBarHeight();
}
changeOrientation(configPortrait, navBarHeight);
changeOrientation(configPortrait);
}
break;
default:
break;
}
}

private boolean contentUrlAction(String url, TransparentActivityConfig config, WebView view) {
private boolean contentUrlAction(String url, WebView view) {
Log.d(Countly.TAG, "[TransparentActivity] contentUrlAction, url: [" + url + "]");
Map<String, Object> query = splitQuery(url);
Log.v(Countly.TAG, "[TransparentActivity] contentUrlAction, query: [" + query + "]");
Expand Down
Loading