Android crosswalk view

CrosswalkView

CrossWalkview is one of CrossWalk Project, and Chrome base WebView.

Android Get Started

Download library project from Website.
The core part is “xwalk_core_library”
And add this project to dependencies of your project.

API : Reference

Simple Code

Layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="jp.co.rakuten.rewards.crosswalksample.MainActivity" >
<LinearLayout
        	android:id="@+id/main"
        	android:layout_width="match_parent"
        	android:layout_height="match_parent"
        	android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>

Codes

public class MainActivity extends Activity {
   @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Add XWalkView
    commentsLayout = (LinearLayout) findViewById(R.id.main);
    xWalkWebView = new XWalkView(this, this);
    xWalkWebView.setResourceClient(new XWalkResponceClient(xWalkWebView));
    commentsLayout.addView(xWalkWebView);
}

Basic Features

  • load
  • back
  • forward
  • reload
  • stop

load
Use load method

xWalkWebView.load("http://www.rakuten.com.sg", null);

back

xWalkWebView.getNavigationHistory().navigate(Direction.BACKWARD, 1);

xWalkWebView.getNavigationHistory().navigate(Direction.FORWARD, 1);

reload

xWalkWebView.reload();

stop

xWalkWebView.stopLoading();

Event Listeners

Extends XWalkResourceClient

class XWalkResponceClient extends XWalkResourceClient {
    public XWalkResponceClient(XWalkView view) {
      super(view);
    }

    @Override
    public void onLoadFinished(XWalkView view, String url) {
      super.onLoadFinished(view, url);
      // Finish loading
    }
   
    @Override
    public void onLoadStarted(XWalkView view, String url) {
      super.onLoadStarted(view, url);
    }

    @Override
    public void onProgressChanged(XWalkView view, int progressInPercent) {
      super.onProgressChanged(view, progressInPercent);
    }
     
    @Override
    public void onReceivedLoadError(XWalkView view, int errorCode,
        String description, String failingUrl) {
      super.onReceivedLoadError(view, errorCode, description, failingUrl);
    }

    @Override
    public void onReceivedSslError(XWalkView view,
        ValueCallback<Boolean> callback, SslError error) {
      // SSL Should use default handler
      super.onReceivedSslError(view, callback, error);
    }

    @Override
    public WebResourceResponse shouldInterceptLoadRequest(XWalkView view,
        String url) {
      return super.shouldInterceptLoadRequest(view, url);
    }

    @Override
    public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
      return super.shouldOverrideUrlLoading(view, url);
    }
}

Known issues

  • Locale? When accessing Facebook, Rakuten, signin page, always open English page(not local language page)
  • It doesn’t have Download Feature(need to implement by ourselves)
  • We have to call onReceivedSslError(if not call, the user tried to access twitter.jp which has invalid ssl certificate)