Skip to content

Commit

Permalink
Fixing overlap issue on Android when footer is shown (previous method…
Browse files Browse the repository at this point in the history
… of using margin did not work on all devices).
  • Loading branch information
hvaughan3 committed Sep 6, 2018
1 parent 800ba9f commit 50d62a2
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Color;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.InputType;
import android.util.TypedValue;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
Expand Down Expand Up @@ -648,6 +651,27 @@ private int dpToPixels(int dipValue) {
return value;
}

private int getDisplayContentHeight() {
final WindowManager windowManager = cordova.getActivity().getWindowManager();
final Point size = new Point();
int screenHeight = 0, actionBarHeight = 0;

if (cordova.getActivity().getActionBar() != null) {
actionBarHeight = cordova.getActivity().getActionBar().getHeight();
}

int contentTop = ((ViewGroup) cordova.getActivity().findViewById(android.R.id.content)).getTop();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
windowManager.getDefaultDisplay().getSize(size);
screenHeight = size.y;
} else {
Display d = windowManager.getDefaultDisplay();
screenHeight = d.getHeight();
}
return screenHeight - contentTop - actionBarHeight;
}

private View createCloseButton(int id){
View _close;
Resources activityRes = cordova.getActivity().getResources();
Expand Down Expand Up @@ -716,6 +740,9 @@ public void run() {

// Toolbar layout
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());

boolean showToolbar = getShowLocationBar();

//Please, no more black!
toolbar.setBackgroundColor(toolbarColor);
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
Expand Down Expand Up @@ -832,16 +859,31 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
View footerClose = createCloseButton(7);
footer.addView(footerClose);

// Display display = cordova.getActivity().getWindowManager().getDefaultDisplay();
// Point size = new Point();
// display.getSize(size);
// // int width = size.x;
// int height = size.y;

int webViewHeight = getDisplayContentHeight();

if (showToolbar) {
webViewHeight = webViewHeight - this.dpToPixels(44);
}

if (showFooter) {
webViewHeight = webViewHeight - footerSize;
}

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

LinearLayout.LayoutParams webViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
LinearLayout.LayoutParams webViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, webViewHeight);

if (showFooter) {
webViewLayoutParams.setMargins(0, 0, 0, footerSize); // Adding margin the same size as the footer
}
// if (showFooter) {
// webViewLayoutParams.setMargins(0, 0, 0, footerSize + this.dpToPixels(16)); // Adding margin the same size as the footer plus footer padding
// }

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

// Don't add the toolbar if its been disabled
if (getShowLocationBar()) {
if (showToolbar) {
// Add our toolbar to our main view/layout
main.addView(toolbar);
}
Expand Down Expand Up @@ -1268,4 +1310,4 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, Str
super.onReceivedHttpAuthRequest(view, handler, host, realm);
}
}
}
}

0 comments on commit 50d62a2

Please sign in to comment.