├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ └── styles.xml │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ ├── xml │ │ │ └── wjbconfig.xml │ │ └── layout │ │ │ └── activity_main.xml │ │ ├── java │ │ └── com │ │ │ └── luffyjet │ │ │ └── jsbridgeexample │ │ │ ├── ImagesResult.java │ │ │ ├── handlers │ │ │ ├── DeviceInfoHandler.java │ │ │ └── ImageChooseHandler.java │ │ │ ├── PathUtil.java │ │ │ ├── NetworkStauts.java │ │ │ └── MainActivity.java │ │ ├── AndroidManifest.xml │ │ └── assets │ │ ├── ExampleApp.html │ │ └── js │ │ └── ccnativeapi.js ├── proguard-rules.pro └── build.gradle ├── library ├── .gitignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── luffyjet │ │ │ └── webviewjavascriptbridge │ │ │ ├── JSResult.java │ │ │ ├── RequestHandler.java │ │ │ ├── BridgeInterface.java │ │ │ ├── Utils.java │ │ │ ├── HandlerEntry.java │ │ │ ├── ConfigXmlParser.java │ │ │ ├── HandlerManager.java │ │ │ ├── WebViewJavaScriptBridge.java │ │ │ └── WebViewJavaScriptBridgeBase.java │ │ └── assets │ │ └── webviewjsbridge.js ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── .gitlab-ci.yml ├── gradle.properties ├── gradlew.bat ├── gradlew ├── README.md └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library' 2 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | JSBridgeExample 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luffyjet/WebViewJavaScriptBridge/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luffyjet/WebViewJavaScriptBridge/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luffyjet/WebViewJavaScriptBridge/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luffyjet/WebViewJavaScriptBridge/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luffyjet/WebViewJavaScriptBridge/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luffyjet/WebViewJavaScriptBridge/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | /app/build 11 | /library/build 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - build 3 | - archive 4 | 5 | build_project: 6 | stage: build 7 | script: 8 | - gradle clean 9 | 10 | archive_project: 11 | stage: archive 12 | script: 13 | - gradle assembleRelease 14 | only: 15 | - master 16 | artifacts: 17 | paths: 18 | - app/build/outputs/apk/ -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/luffyjet/jsbridgeexample/ImagesResult.java: -------------------------------------------------------------------------------- 1 | package com.luffyjet.jsbridgeexample; 2 | 3 | import com.google.gson.Gson; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Title : 9 | * Author : luffyjet 10 | * Date : 2016/12/20 11 | * Project : branch_1009 12 | * Site : http://www.luffyjet.com 13 | */ 14 | 15 | public class ImagesResult { 16 | public List localIds; 17 | public boolean status; 18 | public ImagesResult(boolean b) { 19 | status = b; 20 | } 21 | 22 | public String toJSON() { 23 | return new Gson().toJson(this); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/res/xml/wjbconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 10 | 11 | 12 | 13 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/luffyjet/Documents/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/luffyjet/Documents/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion Integer.parseInt(rootProject.android_compileSdkVersion) 5 | buildToolsVersion rootProject.android_buildToolsVersion 6 | 7 | defaultConfig { 8 | applicationId rootProject.example_package 9 | minSdkVersion Integer.parseInt(rootProject.android_minSdkVersion) 10 | targetSdkVersion Integer.parseInt(rootProject.android_targetSdkVersion) 11 | versionCode Integer.parseInt(rootProject.android_versionCode) 12 | versionName rootProject.android_versionName 13 | } 14 | 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | compile "com.android.support:appcompat-v7:${android_support}" 27 | compile "com.google.code.gson:gson:${android_gson}" 28 | // compile project(':library') 29 | compile 'com.luffyjet:webviewjavascriptbridge:1.0' 30 | } 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | org.gradle.daemon=true 18 | org.gradle.parallel=true 19 | 20 | example_package = com.luffyjet.jsbridgeexample 21 | 22 | android_compileSdkVersion=23 23 | android_buildToolsVersion = 23.0.3 24 | android_support = 23.0.1 25 | 26 | android_minSdkVersion =9 27 | android_targetSdkVersion =22 28 | android_versionCode = 1 29 | android_versionName = 1.0 30 | android_gson = 2.4 31 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.novoda.bintray-release' 3 | android { 4 | compileSdkVersion Integer.parseInt(rootProject.android_compileSdkVersion) 5 | buildToolsVersion rootProject.android_buildToolsVersion 6 | 7 | defaultConfig { 8 | minSdkVersion Integer.parseInt(rootProject.android_minSdkVersion) 9 | targetSdkVersion Integer.parseInt(rootProject.android_targetSdkVersion) 10 | versionCode Integer.parseInt(rootProject.android_versionCode) 11 | versionName rootProject.android_versionName 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | 24 | } 25 | 26 | publish { 27 | userOrg = 'luffyjetx' 28 | groupId = 'com.luffyjet' 29 | artifactId = 'webviewjavascriptbridge' 30 | publishVersion = '1.0' 31 | desc = 'android webview javascript bridge' 32 | website = 'https://github.com/luffyjet/webviewjavascriptbridge' 33 | licences = ['Apache-2.0'] 34 | } -------------------------------------------------------------------------------- /library/src/main/java/com/luffyjet/webviewjavascriptbridge/JSResult.java: -------------------------------------------------------------------------------- 1 | package com.luffyjet.webviewjavascriptbridge; 2 | 3 | import org.json.JSONException; 4 | import org.json.JSONObject; 5 | 6 | /** 7 | * Title : 8 | * Author : luffyjet 9 | * Date : 2017/4/27 10 | * Project : WebViewJavaScriptBridge 11 | * Site : http://www.luffyjet.com 12 | */ 13 | 14 | public class JSResult { 15 | public boolean status; 16 | public String resultStr; 17 | public String errorMessage; 18 | 19 | public JSResult() { 20 | } 21 | 22 | public JSResult(boolean result) { 23 | status = result; 24 | } 25 | 26 | public JSResult(String result) { 27 | resultStr = result; 28 | status = true; 29 | } 30 | 31 | public JSResult setErrorMessage(String message) { 32 | errorMessage = message; 33 | return this; 34 | } 35 | 36 | 37 | public String toJson() { 38 | JSONObject jsonObject = new JSONObject(); 39 | try { 40 | jsonObject.put("status", status); 41 | jsonObject.put("resultStr", resultStr); 42 | jsonObject.put("errorMessage", errorMessage); 43 | } catch (JSONException e) { 44 | e.printStackTrace(); 45 | } 46 | return jsonObject.toString(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /library/src/main/java/com/luffyjet/webviewjavascriptbridge/RequestHandler.java: -------------------------------------------------------------------------------- 1 | package com.luffyjet.webviewjavascriptbridge; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.util.Log; 6 | 7 | /** 8 | * Title : 9 | * Author : luffyjet 10 | * Date : 2016/12/16 11 | * Project : WebViewJavaScriptBridge 12 | * Site : http://www.luffyjet.com 13 | */ 14 | 15 | public abstract class RequestHandler implements WebViewJavaScriptBridgeBase.WVJBHandler { 16 | protected BridgeInterface mBridgeInterface; 17 | protected Context mContext; 18 | private String service; 19 | 20 | public RequestHandler() { 21 | } 22 | 23 | public void log(String msg) { 24 | if (WebViewJavaScriptBridgeBase.logging) { 25 | Log.d("RequestHandler", msg); 26 | } 27 | } 28 | 29 | 30 | public void log(String tag, String msg) { 31 | if (WebViewJavaScriptBridgeBase.logging) { 32 | Log.d(tag, msg); 33 | } 34 | } 35 | 36 | protected String getHandlerName() { 37 | return service; 38 | } 39 | 40 | public void onActivityResult(int requestCode, int resultCode, Intent data){ 41 | 42 | } 43 | 44 | public void onPayResult(String result, String message){ 45 | 46 | } 47 | 48 | void privateInitialize(String service, Context ctx , BridgeInterface bridgeInterface) { 49 | this.service = service; 50 | mContext = ctx; 51 | mBridgeInterface = bridgeInterface; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 16 | 17 | 20 | 21 |