Skip to content

Commit 50d62a2

Browse files
committed
Fixing overlap issue on Android when footer is shown (previous method of using margin did not work on all devices).
1 parent 800ba9f commit 50d62a2

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

src/android/InAppBrowser.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ Licensed to the Apache Software Foundation (ASF) under one
2828
import android.graphics.PorterDuff;
2929
import android.graphics.PorterDuffColorFilter;
3030
import android.graphics.Color;
31+
import android.graphics.Point;
3132
import android.net.Uri;
3233
import android.os.Build;
3334
import android.os.Bundle;
3435
import android.text.InputType;
3536
import android.util.TypedValue;
37+
import android.view.Display;
3638
import android.view.Gravity;
3739
import android.view.KeyEvent;
3840
import android.view.View;
41+
import android.view.ViewGroup;
3942
import android.view.Window;
4043
import android.view.WindowManager;
4144
import android.view.WindowManager.LayoutParams;
@@ -648,6 +651,27 @@ private int dpToPixels(int dipValue) {
648651
return value;
649652
}
650653

654+
private int getDisplayContentHeight() {
655+
final WindowManager windowManager = cordova.getActivity().getWindowManager();
656+
final Point size = new Point();
657+
int screenHeight = 0, actionBarHeight = 0;
658+
659+
if (cordova.getActivity().getActionBar() != null) {
660+
actionBarHeight = cordova.getActivity().getActionBar().getHeight();
661+
}
662+
663+
int contentTop = ((ViewGroup) cordova.getActivity().findViewById(android.R.id.content)).getTop();
664+
665+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
666+
windowManager.getDefaultDisplay().getSize(size);
667+
screenHeight = size.y;
668+
} else {
669+
Display d = windowManager.getDefaultDisplay();
670+
screenHeight = d.getHeight();
671+
}
672+
return screenHeight - contentTop - actionBarHeight;
673+
}
674+
651675
private View createCloseButton(int id){
652676
View _close;
653677
Resources activityRes = cordova.getActivity().getResources();
@@ -716,6 +740,9 @@ public void run() {
716740

717741
// Toolbar layout
718742
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
743+
744+
boolean showToolbar = getShowLocationBar();
745+
719746
//Please, no more black!
720747
toolbar.setBackgroundColor(toolbarColor);
721748
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
@@ -832,16 +859,31 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
832859
View footerClose = createCloseButton(7);
833860
footer.addView(footerClose);
834861

862+
// Display display = cordova.getActivity().getWindowManager().getDefaultDisplay();
863+
// Point size = new Point();
864+
// display.getSize(size);
865+
// // int width = size.x;
866+
// int height = size.y;
867+
868+
int webViewHeight = getDisplayContentHeight();
869+
870+
if (showToolbar) {
871+
webViewHeight = webViewHeight - this.dpToPixels(44);
872+
}
873+
874+
if (showFooter) {
875+
webViewHeight = webViewHeight - footerSize;
876+
}
835877

836878
// WebView
837879
inAppWebView = new WebView(cordova.getActivity());
838880
// inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
839881

840-
LinearLayout.LayoutParams webViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
882+
LinearLayout.LayoutParams webViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, webViewHeight);
841883

842-
if (showFooter) {
843-
webViewLayoutParams.setMargins(0, 0, 0, footerSize); // Adding margin the same size as the footer
844-
}
884+
// if (showFooter) {
885+
// webViewLayoutParams.setMargins(0, 0, 0, footerSize + this.dpToPixels(16)); // Adding margin the same size as the footer plus footer padding
886+
// }
845887

846888
inAppWebView.setLayoutParams(webViewLayoutParams);
847889
inAppWebView.setId(Integer.valueOf(6));
@@ -947,7 +989,7 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
947989
if (!hideUrlBar) toolbar.addView(edittext);
948990

949991
// Don't add the toolbar if its been disabled
950-
if (getShowLocationBar()) {
992+
if (showToolbar) {
951993
// Add our toolbar to our main view/layout
952994
main.addView(toolbar);
953995
}
@@ -1268,4 +1310,4 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, Str
12681310
super.onReceivedHttpAuthRequest(view, handler, host, realm);
12691311
}
12701312
}
1271-
}
1313+
}

0 commit comments

Comments
 (0)