1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.xwalk.core.sample;
7 import org.xwalk.core.XWalkJavascriptResult;
8 import org.xwalk.core.XWalkResourceClient;
9 import org.xwalk.core.XWalkUIClient;
10 import org.xwalk.core.XWalkView;
12 import android.app.Activity;
13 import android.net.Uri;
14 import android.os.Bundle;
15 import android.util.Log;
16 import android.webkit.ValueCallback;
17 import android.webkit.WebResourceResponse;
19 public class ResourceAndUIClientsActivity extends Activity {
21 private static final String TAG = ResourceAndUIClientsActivity.class.getName();
23 class ResourceCLient extends XWalkResourceClient {
25 public ResourceCLient(XWalkView xwalkView) {
29 public void onLoadStarted(XWalkView view, String url) {
30 super.onLoadStarted(view, url);
31 Log.d(TAG, "Load Started:" + url);
34 public void onLoadFinished(XWalkView view, String url) {
35 super.onLoadFinished(view, url);
36 Log.d(TAG, "Load Finished:" + url);
39 public void onProgressChanged(XWalkView view, int progressInPercent) {
40 super.onProgressChanged(view, progressInPercent);
41 Log.d(TAG, "Loading Progress:" + progressInPercent);
44 public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
45 Log.d(TAG, "Intercept load request");
46 return super.shouldInterceptLoadRequest(view, url);
49 public void onReceivedLoadError(XWalkView view, int errorCode, String description,
51 Log.d(TAG, "Load Failed:" + description);
52 super.onReceivedLoadError(view, errorCode, description, failingUrl);
56 class UIClient extends XWalkUIClient {
58 public UIClient(XWalkView xwalkView) {
62 public void onJavascriptCloseWindow(XWalkView view) {
63 super.onJavascriptCloseWindow(view);
64 Log.d(TAG, "Window closed.");
67 public boolean onJavascriptModalDialog(XWalkView view, JavascriptMessageType type,
69 String message, String defaultValue, XWalkJavascriptResult result) {
70 Log.d(TAG, "Show JS dialog.");
71 return super.onJavascriptModalDialog(view, type, url, message, defaultValue, result);
74 public void onFullscreenToggled(XWalkView view, boolean enterFullscreen) {
75 super.onFullscreenToggled(view, enterFullscreen);
76 if (enterFullscreen) {
77 Log.d(TAG, "Entered fullscreen.");
79 Log.d(TAG, "Exited fullscreen.");
83 public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile,
84 String acceptType, String capture) {
85 super.openFileChooser(view, uploadFile, acceptType, capture);
86 Log.d(TAG, "Opened file chooser.");
89 public void onScaleChanged(XWalkView view, float oldScale, float newScale) {
90 super.onScaleChanged(view, oldScale, newScale);
91 Log.d(TAG, "Scale changed.");
96 protected void onCreate(Bundle savedInstanceState) {
97 super.onCreate(savedInstanceState);
98 setContentView(R.layout.xwview_layout);
99 XWalkView xwalkView = (XWalkView) findViewById(R.id.xwalkview);
100 xwalkView.setResourceClient(new ResourceCLient(xwalkView));
101 xwalkView.setUIClient(new UIClient(xwalkView));
102 xwalkView.load("http://www.baidu.com", null);