This commit is contained in:
Yaroslav Dmytrotsa 2015-08-11 16:45:10 +03:00
parent 5ea8f97434
commit 35adff982a
1 changed files with 9 additions and 10 deletions

View File

@ -33,7 +33,7 @@ import io.syng.app.SyngApplication;
public class WebViewFragment extends Fragment { public class WebViewFragment extends Fragment {
private static final String DEFAULT_DAPP = "file:///android_asset/www/boilerplate/index.html"; private static final String DEFAULT_DAPP = "dapp://syng.io/dapps/wallet";
protected CordovaWebView webView; protected CordovaWebView webView;
protected CordovaInterfaceImpl cordovaInterface; protected CordovaInterfaceImpl cordovaInterface;
@ -47,14 +47,15 @@ public class WebViewFragment extends Fragment {
/* /*
Dapps must keep cordova JS files inside or we must place them on external HTTP server. If inject from file: - external scripts not have access to it. Dapps must keep cordova JS files inside or we must place them on external HTTP server. If inject from file: - external scripts not have access to it.
*/
private static String js_cordova = "" private static String js_cordova = ""
+"var script = document.createElement('script'); " +"var script = document.createElement('script'); "
+"script.setAttribute('type','text/javascript'); " +"script.setAttribute('type','text/javascript'); "
+"script.setAttribute('async','async'); " +"script.setAttribute('async','async'); "
+"script.setAttribute('src','file:///android_asset/www/cordova.js'); " +"script.setAttribute('src','http://syng.io/dapps/lib/cordova/cordova.js'); "
+"(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);" +"(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);"
+""; +"";
*/
// protected View view; // protected View view;
@ -192,17 +193,14 @@ public class WebViewFragment extends Fragment {
} }
protected CordovaInterfaceImpl makeCordovaInterface() { protected CordovaInterfaceImpl makeCordovaInterface() {
return new CordovaInterfaceImpl(getActivity());
/*
return new CordovaInterfaceImpl(getActivity()) { return new CordovaInterfaceImpl(getActivity()) {
@Override @Override
public Object onMessage(String id, Object data) { public Object onMessage(String id, Object data) {
return WebViewFragment.this.onMessage(id, data); return WebViewFragment.this.onMessage(id, data);
} }
}; };
*/
} }
/*
public Object onMessage(String id, Object data) { public Object onMessage(String id, Object data) {
if ("onReceivedError".equals(id)) { if ("onReceivedError".equals(id)) {
//TODO: do we need handle error and show it? //TODO: do we need handle error and show it?
@ -215,13 +213,14 @@ public class WebViewFragment extends Fragment {
} }
*/ */
} else if ("onPageFinished".equals(id)) { } else if ("onPageFinished".equals(id)) {
// webView.getEngine().loadUrl("javascript: " + js_cordova, false);
webView.getEngine().loadUrl("javascript: " + js_cordova, false);
} else if ("exit".equals(id)) { } else if ("exit".equals(id)) {
getActivity().finish(); getActivity().finish();
} }
return null; return null;
} }
*/
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();