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

(android) Code improve #524

Merged
merged 1 commit into from
Dec 30, 2019
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
34 changes: 16 additions & 18 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private HashMap<String, String> 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);
Expand Down Expand Up @@ -616,7 +616,7 @@ private boolean getShowLocationBar() {
return this.showLocationBar;
}

private InAppBrowser getInAppBrowser(){
private InAppBrowser getInAppBrowser() {
return this;
}

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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());
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down