Upstream version 6.35.131.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / sample / src / org / xwalk / core / sample / ResourceAndUIClientsActivity.java
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.
4
5 package org.xwalk.core.sample;
6
7 import org.xwalk.core.XWalkJavascriptResult;
8 import org.xwalk.core.XWalkResourceClient;
9 import org.xwalk.core.XWalkUIClient;
10 import org.xwalk.core.XWalkView;
11
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;
18
19 public class ResourceAndUIClientsActivity extends Activity {
20
21     private static final String TAG = ResourceAndUIClientsActivity.class.getName();
22
23     class ResourceCLient extends XWalkResourceClient {
24
25         public ResourceCLient(XWalkView xwalkView) {
26             super(xwalkView);
27         }
28
29         public void onLoadStarted(XWalkView view, String url) {
30             super.onLoadStarted(view, url);
31             Log.d(TAG, "Load Started:" + url);
32         }
33
34         public void onLoadFinished(XWalkView view, String url) {
35             super.onLoadFinished(view, url);
36             Log.d(TAG, "Load Finished:" + url);
37         }
38
39         public void onProgressChanged(XWalkView view, int progressInPercent) {
40             super.onProgressChanged(view, progressInPercent);
41             Log.d(TAG, "Loading Progress:" + progressInPercent);
42         }
43
44         public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
45             Log.d(TAG, "Intercept load request");
46             return super.shouldInterceptLoadRequest(view, url);
47         }
48
49         public void onReceivedLoadError(XWalkView view, int errorCode, String description,
50                 String failingUrl) {
51             Log.d(TAG, "Load Failed:" + description);
52             super.onReceivedLoadError(view, errorCode, description, failingUrl);
53         }
54     }
55
56     class UIClient extends XWalkUIClient {
57
58         public UIClient(XWalkView xwalkView) {
59             super(xwalkView);
60         }
61
62         public void onJavascriptCloseWindow(XWalkView view) {
63             super.onJavascriptCloseWindow(view);
64             Log.d(TAG, "Window closed.");
65         }
66
67         public boolean onJavascriptModalDialog(XWalkView view, JavascriptMessageType type,
68                 String url,
69                 String message, String defaultValue, XWalkJavascriptResult result) {
70             Log.d(TAG, "Show JS dialog.");
71             return super.onJavascriptModalDialog(view, type, url, message, defaultValue, result);
72         }
73
74         public void onFullscreenToggled(XWalkView view, boolean enterFullscreen) {
75             super.onFullscreenToggled(view, enterFullscreen);
76             if (enterFullscreen) {
77                 Log.d(TAG, "Entered fullscreen.");
78             } else {
79                 Log.d(TAG, "Exited fullscreen.");
80             }
81         }
82
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.");
87         }
88
89         public void onScaleChanged(XWalkView view, float oldScale, float newScale) {
90             super.onScaleChanged(view, oldScale, newScale);
91             Log.d(TAG, "Scale changed.");
92         }
93     }
94
95     @Override
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);
103     }
104 }