add dapp:// schema handler.

This commit is contained in:
Yaroslav Dmytrotsa 2015-08-10 14:45:04 +03:00
parent 0ed73775e4
commit f881d93d08
6 changed files with 62 additions and 9 deletions

View File

@ -96,7 +96,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform (1)" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="ormlite-android-4.48" level="project" />
<orderEntry type="library" exported="" name="design-22.2.1" level="project" />
@ -119,21 +119,21 @@
<orderEntry type="library" exported="" name="leakcanary-android-1.3.1" level="project" />
<orderEntry type="library" exported="" name="logback-android-classic-1.1.1-3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" />
<orderEntry type="library" exported="" name="leveldb-api-0.7" level="project" />
<orderEntry type="library" exported="" name="json-io-2.4.1" level="project" />
<orderEntry type="library" exported="" name="leveldb-api-0.7" level="project" />
<orderEntry type="library" exported="" name="jackson-databind-2.5.1" level="project" />
<orderEntry type="library" exported="" name="leveldb-0.7" level="project" />
<orderEntry type="library" exported="" name="persistence-api-1.0.2" level="project" />
<orderEntry type="library" exported="" name="netty-all-4.0.28.Final" level="project" />
<orderEntry type="library" exported="" name="multidex-1.0.1" level="project" />
<orderEntry type="library" exported="" name="log4j-1.2.17" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="log4j-1.2.17" level="project" />
<orderEntry type="library" exported="" name="library-1.1" level="project" />
<orderEntry type="library" exported="" name="guava-18.0" level="project" />
<orderEntry type="library" exported="" name="jackson-annotations-2.5.0" level="project" />
<orderEntry type="library" exported="" name="javassist-3.15.0-GA" level="project" />
<orderEntry type="library" exported="" name="javax.annotation-10.0-b28" level="project" />
<orderEntry type="library" exported="" name="jackson-annotations-2.5.0" level="project" />
<orderEntry type="library" exported="" name="json-smart-1.3.1" level="project" />
<orderEntry type="library" exported="" name="javax.annotation-10.0-b28" level="project" />
<orderEntry type="library" exported="" name="core-1.51.0.0" level="project" />
<orderEntry type="library" exported="" name="prov-1.51.0.0" level="project" />
<orderEntry type="library" exported="" name="leakcanary-watcher-1.3.1" level="project" />

View File

@ -35,6 +35,12 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<data android:scheme="dapp" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity

View File

@ -1,5 +1,6 @@
package io.syng.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
@ -21,7 +22,16 @@ public class MainActivity extends BaseActivity {
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
Intent intent = getIntent();
if (intent.getDataString() != null && intent.getDataString().indexOf("dapp://") == 0) {
WebViewFragment wvF = new WebViewFragment();
Bundle args = new Bundle();
args.putString("url", intent.getDataString());
wvF.setArguments(args);
replaceFragment(wvF);
}
else if (savedInstanceState == null) {
replaceFragment(new ConsoleFragment());
}

View File

@ -0,0 +1,15 @@
package io.syng.cordova.plugin;
import org.apache.cordova.CordovaPlugin;
public class DappURL extends CordovaPlugin {
@Override
public boolean onOverrideUrlLoading(String url) {
if (url.indexOf("dapp://") == 0) {
webView.loadUrl(url.replace("dapp://", "http://"));
return true;
}
return false;
}
}

View File

@ -32,6 +32,8 @@ import io.syng.app.SyngApplication;
public class WebViewFragment extends Fragment {
private static final String DEFAULT_DAPP = "file:///android_asset/www/boilerplate/index.html";
protected CordovaWebView webView;
protected CordovaInterfaceImpl cordovaInterface;
protected CordovaPreferences preferences;
@ -40,6 +42,8 @@ public class WebViewFragment extends Fragment {
protected boolean keepRunning = true;
protected boolean immersiveMode;
protected String url;
/*
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 = ""
@ -53,6 +57,12 @@ public class WebViewFragment extends Fragment {
// protected View view;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
url = getArguments() != null ? getArguments().getString("url") : null;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
loadConfig();
@ -99,14 +109,17 @@ public class WebViewFragment extends Fragment {
init();
// loadUrl("http://trustdavis.meteor.com");
loadUrl("file:///android_asset/www/boilerplate/index.html");
loadUrl();
// return view;
return webView.getView();
}
public void loadUrl(String url) {
private void loadUrl() {
if (url == null || url.isEmpty()) {
url = DEFAULT_DAPP;
}
if (webView == null) {
init();
}
@ -114,6 +127,10 @@ public class WebViewFragment extends Fragment {
// If keepRunning
this.keepRunning = preferences.getBoolean("KeepRunning", true);
if (url.indexOf("dapp://") == 0) {
url = url.replace("dapp://", "http://");
}
webView.loadUrlIntoView(url, true);
}

View File

@ -60,6 +60,11 @@
<param name="android-package" value="org.apache.cordova.vibration.Vibration"/>
</feature>
<feature name="DappURL">
<param name="android-package" value="io.syng.cordova.plugin.DappURL"/>
<param name="onload" value="true" />
</feature>
<!--
After enable it block and freez requests to our JSON-RPC
-->