Is there a XWalkView webviewclient?
Asked Answered
H

3

6

I'm trying to use XWalkView as webview replacement in my android app. I noticed that there's no setWebViewClient method on XWalkView object. The thing is that I want to check when the page is finished (onPageFinished) and when the resource is loaded (onLoadResource). How can I do this with XWalkView?

I embed the XWalkView using this tutorial

embed crosswalk in android studio

Hypertensive answered 20/10, 2015 at 4:54 Comment(0)
A
19

Cross Walk API introduces its own names for every component. Not only the WebView is renamed to XWalkView, but also WebViewClient has its counterpart named XWalkResourceClient and WebChromeClient - XWalkUIClient. So, instead of setWebViewClient you should use setResourceClient method and pass XWalkResourceClient instance to it. In this object you can implement some required methods, for example onLoadFinished. Please, consult with Cross Walk API documentation for further details.

Archery answered 30/12, 2015 at 19:47 Comment(0)
I
5

WebViewClient example:

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            //Do stuff
        }
    });

Same thing but using XWalkView version:

xWalkView.setResourceClient(new XWalkResourceClient(xWalkView){
        @Override
        public void onLoadFinished(XWalkView view, String url) {
            super.onLoadFinished(view, url);
            //Do Stuff
        }
    });
Impecunious answered 21/9, 2016 at 17:30 Comment(0)
S
2

you can use ResourceClient.

class ResourceClient extends XWalkResourceClient {
    public ResourceClient(XWalkView xwalkView) {
        super(xwalkView);
    }

    public void onLoadStarted(XWalkView view, String url) {
        mProgress = (ProgressBar) findViewById(R.id.progressBar);
        mProgress.setVisibility(View.VISIBLE);
        super.onLoadStarted(view, url);
        Log.d("INFO", "Load Started:" + url);
    }

    public void onLoadFinished(XWalkView view, String url) {
        super.onLoadFinished(view, url);
        Log.d("INFO", "Load Finished:" + url);
        bottomBar = (BottomBar) findViewById(R.id.bottomBar);
        mProgress = (ProgressBar) findViewById(R.id.progressBar);
        mProgress.setVisibility(View.GONE);
    }

    public void onProgressChanged(XWalkView view, int progressInPercent) {
        super.onProgressChanged(view, progressInPercent);
        Log.d("INFO", "Loading Progress:" + progressInPercent);
        mProgress = (ProgressBar) findViewById(R.id.progressBar);
        mProgress.setProgress(progressInPercent);
    }
Subcartilaginous answered 5/1, 2017 at 14:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.