1 // Copyright (c) 2013 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.app.runtime;
7 import android.app.Activity;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.util.AttributeSet;
11 import android.widget.LinearLayout;
14 * This class is to provide public APIs which are called by web application
15 * APKs. Since the runtime is shared as a library APK, web application APKs
16 * have to call them via class loader but not direct API calling.
18 * A web application APK should create its Activity and set this view as
21 // Implementation notes.
22 // Please be careful to change any public APIs for the backward compatibility
23 // is very important to us. Don't change any of them without permisson.
24 public class XWalkRuntimeView extends LinearLayout {
25 // The actual implementation to hide the internals to API users.
26 private XWalkRuntimeViewProvider mProvider;
29 * Contructs a XWalkRuntimeView with Activity and library Context. Called
30 * from runtime client.
32 * @param activity the activity from runtime client
33 * @param context a context when creating this package
34 * @param attrs the attributes of the XML tag that is inflating the view
36 public XWalkRuntimeView(Activity activity, Context context, AttributeSet attrs) {
37 super(context, attrs);
39 // MixedContext is needed for cross package because the application
40 // context is different.
41 init(context, activity);
45 * This is for inflating this view from XML. Called from test shell.
46 * @param context a context to construct View
47 * @param attrs the attributes of the XML tag that is inflating the view
49 public XWalkRuntimeView(Context context, AttributeSet attrs) {
50 super(context, attrs);
52 init(context, (Activity)context);
55 private void init(Context context, Activity activity) {
56 mProvider = XWalkRuntimeViewProviderFactory.getProvider(context, activity);
57 setOrientation(LinearLayout.VERTICAL);
58 this.addView(mProvider.getView(),
59 new LinearLayout.LayoutParams(
60 LinearLayout.LayoutParams.MATCH_PARENT,
61 LinearLayout.LayoutParams.MATCH_PARENT));
65 * Get the version information of current runtime library.
67 * @return the string containing the version information.
69 public String getVersion() {
70 return mProvider.getVersion();
74 * Load a web application through the entry url. It may be
75 * a file from assets or a url from network.
77 * @param url the url of loaded html resource.
79 public void loadAppFromUrl(String url) {
80 mProvider.loadAppFromUrl(url);
84 * Load a web application through the url of the manifest file.
85 * The manifest file typically is placed in android assets. Now it is
86 * compliant to W3C SysApps spec.
88 * @param manifestUrl the url of the manifest file
90 public void loadAppFromManifest(String manifestUrl) {
91 mProvider.loadAppFromManifest(manifestUrl);
95 * Tell runtime that the application is on creating. This can make runtime
96 * be aware of application life cycle.
98 public void onCreate() {
103 * Tell runtime that the application is on resuming. This can make runtime
104 * be aware of application life cycle.
106 public void onResume() {
107 mProvider.onResume();
111 * Tell runtime that the application is on pausing. This can make runtime
112 * be aware of application life cycle.
114 public void onPause() {
119 * Tell runtime that the application is on destroying. This can make runtime
120 * be aware of application life cycle.
122 public void onDestroy() {
123 mProvider.onDestroy();
127 * Tell runtime that one activity exists so that it can know the result code
130 * @param requestCode the request code to identify where the result is from
131 * @param resultCode the result code of the activity
132 * @param data the data to contain the result data
134 public void onActivityResult(int requestCode, int resultCode, Intent data) {
135 mProvider.onActivityResult(requestCode, resultCode, data);
139 * Tell runtime that the activity receive a new Intent to start it. It may contains
140 * data that runtime want to deal with.
141 * @param intent the new coming Intent.
142 * @return boolean whether runtime consumed it.
144 public boolean onNewIntent(Intent intent) {
145 return mProvider.onNewIntent(intent);
149 * Enable remote debugging for the loaded web application. The caller
150 * can set the url of debugging url. Besides, the socket name for remote
151 * debugging has to be unique so typically the string can be appended
152 * with the package name of the application.
154 * @param frontEndUrl the url of debugging url. If it's empty, then a
155 * default url will be used.
156 * @param socketName the unique socket name for setting up socket for
157 * remote debugging. If it's empty, then a default
159 * @return the url of web socket for remote debugging
161 public void enableRemoteDebugging(String frontEndUrl, String socketName) {
162 // TODO(yongsheng): Figure out which parameters are needed once we
163 // have a conclusion.
164 mProvider.enableRemoteDebugging(frontEndUrl,socketName);
168 * Disable remote debugging so runtime can close related stuff for
171 public void disableRemoteDebugging() {
172 mProvider.disableRemoteDebugging();
175 // For instrumentation test.
176 public String getTitleForTest() {
177 return mProvider.getTitleForTest();
180 public void setCallbackForTest(Object callback) {
181 mProvider.setCallbackForTest(callback);
184 public void loadDataForTest(String data, String mimeType, boolean isBase64Encoded) {
185 mProvider.loadDataForTest(data, mimeType, isBase64Encoded);