Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 17 additions & 4 deletions src/android/InAppChromeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.json.JSONArray;
import org.json.JSONException;

import android.view.View;
import android.webkit.JsPromptResult;
import android.webkit.WebChromeClient;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.GeolocationPermissions.Callback;
import android.widget.ProgressBar;

public class InAppChromeClient extends WebChromeClient {

private CordovaWebView webView;
private String LOG_TAG = "InAppChromeClient";
private long MAX_QUOTA = 100 * 1024 * 1024;

public InAppChromeClient(CordovaWebView webView) {
private ProgressBar progressbar;
public InAppChromeClient(CordovaWebView webView,ProgressBar progressbar) {
super();
this.webView = webView;
this.progressbar=progressbar;
}
/**
* Handle database quota exceeded notification.
Expand Down Expand Up @@ -128,5 +131,15 @@ public boolean onJsPrompt(WebView view, String url, String message, String defau
}
return false;
}

}
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
progressbar.setVisibility(View.GONE);
} else {
if (progressbar.getVisibility() == View.GONE)
progressbar.setVisibility(View.VISIBLE);
progressbar.setProgress(newProgress);
}
super.onProgressChanged(view, newProgress);
}
}
47 changes: 45 additions & 2 deletions src/android/ThemeableBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
Expand Down Expand Up @@ -58,6 +61,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
Expand Down Expand Up @@ -242,6 +246,17 @@ public void run() {
pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult);
}
else if (action.equals("hide")) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.hide();
}
});
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult);
}
else if (action.equals("reload")) {
if (inAppWebView != null) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -750,7 +765,25 @@ public void onNothingSelected(
title.setTextSize(features.title.textSize);
}
}

final ProgressBar progressbar = new ProgressBar(cordova.getActivity(), null, android.R.attr.progressBarStyleHorizontal);
FrameLayout.LayoutParams progressbarLayout = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, 6);
//progressbarLayout.
progressbar.setLayoutParams(progressbarLayout);
if (features.browserProgress != null){
Integer progressColor=Color.BLUE;
if ( features.browserProgress.progressColor != null
&& features.browserProgress.progressColor.length() > 0) {
progressColor = Color.parseColor(features.browserProgress.progressColor);
}
ClipDrawable progressDrawable = new ClipDrawable(new ColorDrawable(progressColor), Gravity.LEFT, ClipDrawable.HORIZONTAL);
progressbar.setProgressDrawable(progressDrawable);
Integer progressBgColor = Color.GRAY;
if ( features.browserProgress.progressBgColor != null
&& features.browserProgress.progressBgColor.length() > 0) {
progressBgColor = Color.parseColor(features.browserProgress.progressBgColor);
}
progressbar.setBackgroundColor(progressBgColor);
}
// WebView
inAppWebView = new WebView(cordova.getActivity());
final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen
Expand All @@ -760,7 +793,7 @@ public void onNothingSelected(
((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
}
inAppWebView.setLayoutParams(inAppWebViewParams);
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView, progressbar));
WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {
@Override
public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
Expand Down Expand Up @@ -927,6 +960,9 @@ public void onClick(View view) {
if (features.location) {
// Add our toolbar to our main view/layout
main.addView(toolbar);
if (features.browserProgress!=null&&features.browserProgress.showProgress){
main.addView(progressbar);
}
}

if (!features.fullscreen) {
Expand Down Expand Up @@ -1390,6 +1426,7 @@ private static class Options {
public boolean backButtonCanClose;
public boolean disableAnimation;
public boolean fullscreen;
public BrowserProgress browserProgress;
}

private static class Event {
Expand Down Expand Up @@ -1417,6 +1454,12 @@ private static class BrowserMenu extends BrowserButton {
public EventLabel[] items;
}

private static class BrowserProgress {
public boolean showProgress;
public String progressBgColor;
public String progressColor;
}

private static class Toolbar {
public int height = TOOLBAR_DEF_HEIGHT;
public String color;
Expand Down
5 changes: 5 additions & 0 deletions src/ios/CDVThemeableBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
@property (nonatomic) NSDictionary* statusbar;
@property (nonatomic) NSDictionary* toolbar;
@property (nonatomic) NSDictionary* title;
@property (nonatomic) NSDictionary* browserProgress;
@property (nonatomic) NSDictionary* backButton;
@property (nonatomic) NSDictionary* forwardButton;
@property (nonatomic) NSDictionary* closeButton;
Expand Down Expand Up @@ -76,6 +77,7 @@
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
- (void)show:(CDVInvokedUrlCommand*)command;
- (void)show:(CDVInvokedUrlCommand*)command withAnimation:(BOOL)animated;
- (void)hide:(CDVInvokedUrlCommand*)command;
- (void)reload:(CDVInvokedUrlCommand*)command;

@end
Expand Down Expand Up @@ -105,6 +107,7 @@
@property (nonatomic, strong) IBOutlet UIButton* menuButton;
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;
@property (nonatomic, strong) IBOutlet UIView* toolbar;
@property (nonatomic, strong) IBOutlet UIProgressView* progressView;

@property (nonatomic, strong) NSArray* leftButtons;
@property (nonatomic, strong) NSArray* rightButtons;
Expand All @@ -114,6 +117,8 @@
@property (nonatomic) NSURL* currentURL;
@property (nonatomic) CGFloat titleOffset;

@property (nonatomic , readonly , getter=loadProgress) CGFloat currentProgress;

- (void)close;
- (void)reload;
- (void)navigateTo:(NSURL*)url;
Expand Down
Loading