From 283957d7887e5fe5587bdba996514a885b1af6c2 Mon Sep 17 00:00:00 2001 From: Mark Jenzer Date: Wed, 20 Sep 2023 15:29:21 +0200 Subject: [PATCH] GH-1022 android: enable zoom without on-screen controls --- README.md | 3 ++- src/android/InAppBrowser.java | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6703f5cb6..44ac6c93e 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,8 @@ instance, or the system browser. - __navigationbuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color of both navigation buttons from default. Only has effect if user has location set to `yes` and not hidenavigationbuttons set to `yes`. - __toolbarcolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color the toolbar from default. Only has effect if user has location set to `yes`. - __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the right and close button to the left. Default value is `no`. - - __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`. + - __zoom__: set to `yes` to enable Android browser's zoom controls, set to `no` to disable them. Default value is `yes`. + - __zoomcontrols__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `no`. - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). - __shouldPauseOnSuspend__: Set to `yes` to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues like described in [CB-11013](https://issues.apache.org/jira/browse/CB-11013)). - __useWideViewPort__: Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is `no`, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is `yes` and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. (defaults to `yes`). diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index eed595016..f1dbe7f22 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -94,6 +94,7 @@ public class InAppBrowser extends CordovaPlugin { private static final String EXIT_EVENT = "exit"; private static final String LOCATION = "location"; private static final String ZOOM = "zoom"; + private static final String ZOOMCONTROLS = "zoomcontrols"; private static final String HIDDEN = "hidden"; private static final String LOAD_START_EVENT = "loadstart"; private static final String LOAD_STOP_EVENT = "loadstop"; @@ -128,7 +129,8 @@ public class InAppBrowser extends CordovaPlugin { private EditText edittext; private CallbackContext callbackContext; private boolean showLocationBar = true; - private boolean showZoomControls = true; + private boolean enableZoom = true; + private boolean showZoomControls = false; private boolean openWindowHidden = false; private boolean clearAllCache = false; private boolean clearSessionCache = false; @@ -631,7 +633,8 @@ private InAppBrowser getInAppBrowser() { public String showWebPage(final String url, HashMap features) { // Determine if we should hide the location bar. showLocationBar = true; - showZoomControls = true; + enableZoom = true; + showZoomControls = false; openWindowHidden = false; mediaPlaybackRequiresUserGesture = false; @@ -648,7 +651,11 @@ public String showWebPage(final String url, HashMap features) { } String zoom = features.get(ZOOM); if (zoom != null) { - showZoomControls = zoom.equals("yes") ? true : false; + enableZoom = zoom.equals("yes") ? true : false; + } + String zoomcontrols = features.get(ZOOMCONTROLS); + if (zoomcontrols != null) { + showZoomControls = zoomcontrols.equals("yes") ? true : false; } String hidden = features.get(HIDDEN); if (hidden != null) { @@ -946,7 +953,8 @@ public boolean onShowFileChooser (WebView webView, ValueCallback filePath WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); - settings.setBuiltInZoomControls(showZoomControls); + settings.setBuiltInZoomControls(enableZoom); + settings.setDisplayZoomControls(showZoomControls); settings.setPluginState(android.webkit.WebSettings.PluginState.ON); // download event