From 9eb5ef27455fb28083200be4fc90c4eabea16fb9 Mon Sep 17 00:00:00 2001 From: Lorenzo Boaro <1482350+flexaddicted@users.noreply.github.com> Date: Tue, 20 Aug 2019 14:54:43 +0200 Subject: [PATCH] Replace "beforeload" with BEFORELOAD Improve code formatting --- src/android/InAppBrowser.java | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 060330261..87df9d230 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -437,7 +437,7 @@ private HashMap parseFeature(String optString) { if (option.hasMoreElements()) { String key = option.nextToken(); String value = option.nextToken(); - if (!customizableOptions.contains(key)){ + if (!customizableOptions.contains(key)) { value = value.equals("yes") || value.equals("no") ? value : "yes"; } map.put(key, value); @@ -616,7 +616,7 @@ private boolean getShowLocationBar() { return this.showLocationBar; } - private InAppBrowser getInAppBrowser(){ + private InAppBrowser getInAppBrowser() { return this; } @@ -730,7 +730,7 @@ private int dpToPixels(int dipValue) { return value; } - private View createCloseButton(int id){ + private View createCloseButton(int id) { View _close; Resources activityRes = cordova.getActivity().getResources(); @@ -906,9 +906,9 @@ public boolean onKey(View v, int keyCode, KeyEvent event) { // Footer RelativeLayout footer = new RelativeLayout(cordova.getActivity()); int _footerColor; - if(footerColor != ""){ + if(footerColor != "") { _footerColor = Color.parseColor(footerColor); - }else{ + } else { _footerColor = android.graphics.Color.LTGRAY; } footer.setBackgroundColor(_footerColor); @@ -1208,26 +1208,26 @@ public boolean shouldOverrideUrlLoading(String url, String method) { if (beforeload.equals("yes") && method == null) { useBeforeload = true; - }else if(beforeload.equals("yes") + } else if(beforeload.equals("yes") //TODO handle POST requests then this condition can be removed: && !method.equals("POST")) { useBeforeload = true; - }else if(beforeload.equals("get") && (method == null || method.equals("GET"))){ + } else if(beforeload.equals("get") && (method == null || method.equals("GET"))) { useBeforeload = true; - }else if(beforeload.equals("post") && (method == null || method.equals("POST"))){ + } else if(beforeload.equals("post") && (method == null || method.equals("POST"))) { //TODO handle POST requests errorMessage = "beforeload doesn't yet support POST requests"; } // On first URL change, initiate JS callback. Only after the beforeload event, continue. if (useBeforeload && this.waitForBeforeload) { - if(sendBeforeLoad(url, method)){ + if(sendBeforeLoad(url, method)) { return true; } } - if(errorMessage != null){ + if(errorMessage != null) { try { LOG.e(LOG_TAG, errorMessage); JSONObject obj = new JSONObject(); @@ -1236,7 +1236,7 @@ public boolean shouldOverrideUrlLoading(String url, String method) { obj.put("code", -1); obj.put("message", errorMessage); sendUpdate(obj, true, PluginResult.Status.ERROR); - }catch(Exception e){ + } catch(Exception e) { LOG.e(LOG_TAG, "Error sending loaderror for " + url + ": " + e.toString()); } } @@ -1322,12 +1322,12 @@ else if (!url.startsWith("http:") && !url.startsWith("https:") && url.matches("^ return override; } - private boolean sendBeforeLoad(String url, String method){ + private boolean sendBeforeLoad(String url, String method) { try { JSONObject obj = new JSONObject(); - obj.put("type", "beforeload"); + obj.put("type", BEFORELOAD); obj.put("url", url); - if(method != null){ + if(method != null) { obj.put("method", method); } sendUpdate(obj, true); @@ -1365,7 +1365,7 @@ public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceReque return shouldInterceptRequest(request.getUrl().toString(), super.shouldInterceptRequest(view, request), request.getMethod()); } - public WebResourceResponse shouldInterceptRequest(String url, WebResourceResponse response, String method){ + public WebResourceResponse shouldInterceptRequest(String url, WebResourceResponse response, String method) { return response; } @@ -1406,13 +1406,11 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) { } } - - public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // Set the namespace for postMessage() - if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1){ + if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { injectDeferredObject("window.webkit={messageHandlers:{cordova_iab:cordova_iab}}", null); }