delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

Progress bar / Title Bar #34

Closed digitalprecision closed 8 years ago

digitalprecision commented 8 years ago

Hello, thanks for providing this framework, it works great. I was wondering if you were planning on adding the ability to display a progress bar and title bar?

ocram commented 8 years ago

Thanks for your question!

In order to display a progress bar, you can just create one in your own layout using <ProgressBar ...></ProgressBar> in the XML. You may place this above, below or on top (in FrameLayout) of the web view. Alternatively, you may use a ProgressDialog.

You can then update your progress bar with data from the webview like this:

mWebView.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int newProgress) {
        mProgressBar.setProgress(newProgress);
    }
});

If you want to get the current page's title, you can do so in the method onPageFinished(String url) that you override. Just call mWebView.getTitle() inside. This can then be displayed in your own TextView.

This library will not provide its own UI widgets. This is to ensure maximum flexibility and reusability.

Does that help?

ocram commented 8 years ago

Android's standard android.widget.ProgressBar is often sufficient for a proper progress indicator.

Often, you don't want a horizontal bar where some colored indicator moves in one direction. Instead, a circular progress indicator is commonly used. That indicator starts spinning when displayed to show the uncertain duration of the progress. Make sure to set proper width and height on the progress bar for that use case and turn android:indeterminate on by setting it to true.

Alternatively, a custom subclass of Dialog can be used to easily show and hide progress bars from code (as opposed to layout).

In any way, you'll want to implement AdvancedWebView.Listener in your code for the web view screen and implement onPageStarted (where you show/start the indicator) and onPageFinished (where you hide/stop the indicator), and potentially onPageError. Furthermore, you might get the exact progress as shown above.

For other progress bar styles, you might try this, this or this solution -- which are not as lightweight, but may be what you want, nevertheless.

ocram commented 8 years ago

Here's some more information on progress bar usage: https://github.com/delight-im/Android-AdvancedWebView/issues/25

digitalprecision commented 8 years ago

Awesome thanks.