Skip to content

X5 3.0 #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: x5-3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .idea/compiler.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/copyright/profiles_settings.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/dictionaries/du.xml

This file was deleted.

10 changes: 3 additions & 7 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 6 additions & 62 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 13 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "wendu.jsbdemo"
minSdkVersion 11
targetSdkVersion 23
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -16,29 +16,25 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}

lintOptions {
abortOnError false
}

testOptions {
unitTests.returnDefaultValues = true
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(path: ':dsbridge')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.squareup.okhttp3:okhttp:3.3.0'
testCompile 'junit:junit:4.12'
implementation project(path: ':dsbridge')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.squareup.okhttp3:okhttp:3.3.0'
testImplementation 'junit:junit:4.12'
}


Expand Down
62 changes: 32 additions & 30 deletions app/src/main/java/wendu/jsbdemo/CallJavascriptActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,40 @@

import wendu.dsbridge.DWebView;
import wendu.dsbridge.OnReturnValue;
import wendu.dsbridge.WebViewEventImpl;

public class CallJavascriptActivity extends AppCompatActivity implements View.OnClickListener {
public class CallJavascriptActivity extends AppCompatActivity implements View.OnClickListener{

DWebView dWebView;
public WebViewEventImpl mWebViewEvent;


public <T extends View> T getView(int viewId) {
View view = findViewById(viewId);
return (T) view;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call_javascript);
getView(R.id.addValue).setOnClickListener(this);
getView(R.id.append).setOnClickListener(this);
getView(R.id.startTimer).setOnClickListener(this);
getView(R.id.synAddValue).setOnClickListener(this);
getView(R.id.synGetInfo).setOnClickListener(this);
getView(R.id.asynAddValue).setOnClickListener(this);
getView(R.id.asynGetInfo).setOnClickListener(this);
getView(R.id.hasMethodAddValue).setOnClickListener(this);
getView(R.id.hasMethodXX).setOnClickListener(this);
getView(R.id.hasMethodAsynAddValue).setOnClickListener(this);
getView(R.id.hasMethodAsynXX).setOnClickListener(this);
DWebView.setWebContentsDebuggingEnabled(true);
dWebView= getView(R.id.webview);
dWebView.loadUrl("file:///android_asset/native-call-js.html");
findViewById(R.id.addValue).setOnClickListener(this);
findViewById(R.id.append).setOnClickListener(this);
findViewById(R.id.startTimer).setOnClickListener(this);
findViewById(R.id.synAddValue).setOnClickListener(this);
findViewById(R.id.synGetInfo).setOnClickListener(this);
findViewById(R.id.asynAddValue).setOnClickListener(this);
findViewById(R.id.asynGetInfo).setOnClickListener(this);
findViewById(R.id.hasMethodAddValue).setOnClickListener(this);
findViewById(R.id.hasMethodXX).setOnClickListener(this);
findViewById(R.id.hasMethodAsynAddValue).setOnClickListener(this);
findViewById(R.id.hasMethodAsynXX).setOnClickListener(this);

dWebView = findViewById(R.id.webview);
mWebViewEvent = new WebViewEventImpl(dWebView);
mWebViewEvent.setWebContentsDebuggingEnabled(true);
mWebViewEvent.loadUrl("file:///android_asset/native-call-js.html");


}


void showToast(Object o) {
Toast.makeText(this, o.toString(), Toast.LENGTH_SHORT).show();
}
Expand All @@ -49,87 +51,87 @@ void showToast(Object o) {
public void onClick(View v) {
switch (v.getId()) {
case R.id.addValue:
dWebView.callHandler("addValue", new Object[]{3, 4}, new OnReturnValue<Integer>() {
mWebViewEvent.callHandler("addValue", new Object[]{3, 4}, new OnReturnValue<Integer>() {
@Override
public void onValue(Integer retValue) {
showToast(retValue);
}
});
break;
case R.id.append:
dWebView.callHandler("append", new Object[]{"I", "love", "you"}, new OnReturnValue<String>() {
mWebViewEvent.callHandler("append", new Object[]{"I", "love", "you"}, new OnReturnValue<String>() {
@Override
public void onValue(String retValue) {
showToast(retValue);
}
});
break;
case R.id.startTimer:
dWebView.callHandler("startTimer", new OnReturnValue<Integer>() {
mWebViewEvent.callHandler("startTimer", new OnReturnValue<Integer>() {
@Override
public void onValue(Integer retValue) {
showToast(retValue);
}
});
break;
case R.id.synAddValue:
dWebView.callHandler("syn.addValue", new Object[]{5, 6}, new OnReturnValue<Integer>() {
mWebViewEvent.callHandler("syn.addValue", new Object[]{5, 6}, new OnReturnValue<Integer>() {
@Override
public void onValue(Integer retValue) {
showToast(retValue);
}
});
break;
case R.id.synGetInfo:
dWebView.callHandler("syn.getInfo", new OnReturnValue<JSONObject>() {
mWebViewEvent.callHandler("syn.getInfo", new OnReturnValue<JSONObject>() {
@Override
public void onValue(JSONObject retValue) {
showToast(retValue);
}
});
break;
case R.id.asynAddValue:
dWebView.callHandler("asyn.addValue", new Object[]{5, 6}, new OnReturnValue<Integer>() {
mWebViewEvent.callHandler("asyn.addValue", new Object[]{5, 6}, new OnReturnValue<Integer>() {
@Override
public void onValue(Integer retValue) {
showToast(retValue);
}
});
break;
case R.id.asynGetInfo:
dWebView.callHandler("asyn.getInfo", new OnReturnValue<JSONObject>() {
mWebViewEvent.callHandler("asyn.getInfo", new OnReturnValue<JSONObject>() {
@Override
public void onValue(JSONObject retValue) {
showToast(retValue);
}
});
break;
case R.id.hasMethodAddValue:
dWebView.hasJavascriptMethod("addValue", new OnReturnValue<Boolean>() {
mWebViewEvent.hasJavascriptMethod("addValue", new OnReturnValue<Boolean>() {
@Override
public void onValue(Boolean retValue) {
showToast(retValue);
}
});
break;
case R.id.hasMethodXX:
dWebView.hasJavascriptMethod("XX", new OnReturnValue<Boolean>() {
mWebViewEvent.hasJavascriptMethod("XX", new OnReturnValue<Boolean>() {
@Override
public void onValue(Boolean retValue) {
showToast(retValue);
}
});
break;
case R.id.hasMethodAsynAddValue:
dWebView.hasJavascriptMethod("asyn.addValue", new OnReturnValue<Boolean>() {
mWebViewEvent.hasJavascriptMethod("asyn.addValue", new OnReturnValue<Boolean>() {
@Override
public void onValue(Boolean retValue) {
showToast(retValue);
}
});
break;
case R.id.hasMethodAsynXX:
dWebView.hasJavascriptMethod("asyn.XX", new OnReturnValue<Boolean>() {
mWebViewEvent.hasJavascriptMethod("asyn.XX", new OnReturnValue<Boolean>() {
@Override
public void onValue(Boolean retValue) {
showToast(retValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
import android.support.v7.app.AppCompatActivity;

import wendu.dsbridge.DWebView;
import wendu.dsbridge.WebViewEventImpl;

public class JavascriptCallNativeActivity extends AppCompatActivity {

public WebViewEventImpl mWebViewEvent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_js_call_native);
final DWebView dwebView= (DWebView) findViewById(R.id.webview);
DWebView dwebView = findViewById(R.id.webview);
// set debug mode
DWebView.setWebContentsDebuggingEnabled(true);
dwebView.addJavascriptObject(new JsApi(), null);
dwebView.addJavascriptObject(new JsEchoApi(),"echo");
dwebView.loadUrl("file:///android_asset/js-call-native.html");
mWebViewEvent = new WebViewEventImpl(dwebView);
mWebViewEvent.setWebContentsDebuggingEnabled(true);
mWebViewEvent.addJavascriptObject(new JsApi(), null);
mWebViewEvent.addJavascriptObject(new JsEchoApi(), "echo");
mWebViewEvent.loadUrl("file:///android_asset/js-call-native.html");
}
}
Loading