").append(m.parseHTML(a)).find(d):a)}).complete(c&&function(a,b){g.each(c,e||[a.responseText,b,a])}),this},m.expr.filters.animated=function(a){return m.grep(m.timers,function(b){return a===b.elem}).length};var cd=a.document.documentElement;function dd(a){return m.isWindow(a)?a:9===a.nodeType?a.defaultView||a.parentWindow:!1}m.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=m.css(a,"position"),l=m(a),n={};"static"===k&&(a.style.position="relative"),h=l.offset(),f=m.css(a,"top"),i=m.css(a,"left"),j=("absolute"===k||"fixed"===k)&&m.inArray("auto",[f,i])>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),m.isFunction(b)&&(b=b.call(a,c,h)),null!=b.top&&(n.top=b.top-h.top+g),null!=b.left&&(n.left=b.left-h.left+e),"using"in b?b.using.call(a,n):l.css(n)}},m.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){m.offset.setOffset(this,a,b)});var b,c,d={top:0,left:0},e=this[0],f=e&&e.ownerDocument;if(f)return b=f.documentElement,m.contains(b,e)?(typeof e.getBoundingClientRect!==K&&(d=e.getBoundingClientRect()),c=dd(f),{top:d.top+(c.pageYOffset||b.scrollTop)-(b.clientTop||0),left:d.left+(c.pageXOffset||b.scrollLeft)-(b.clientLeft||0)}):d},position:function(){if(this[0]){var a,b,c={top:0,left:0},d=this[0];return"fixed"===m.css(d,"position")?b=d.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),m.nodeName(a[0],"html")||(c=a.offset()),c.top+=m.css(a[0],"borderTopWidth",!0),c.left+=m.css(a[0],"borderLeftWidth",!0)),{top:b.top-c.top-m.css(d,"marginTop",!0),left:b.left-c.left-m.css(d,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||cd;while(a&&!m.nodeName(a,"html")&&"static"===m.css(a,"position"))a=a.offsetParent;return a||cd})}}),m.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,b){var c=/Y/.test(b);m.fn[a]=function(d){return V(this,function(a,d,e){var f=dd(a);return void 0===e?f?b in f?f[b]:f.document.documentElement[d]:a[d]:void(f?f.scrollTo(c?m(f).scrollLeft():e,c?e:m(f).scrollTop()):a[d]=e)},a,d,arguments.length,null)}}),m.each(["top","left"],function(a,b){m.cssHooks[b]=Lb(k.pixelPosition,function(a,c){return c?(c=Jb(a,b),Hb.test(c)?m(a).position()[b]+"px":c):void 0})}),m.each({Height:"height",Width:"width"},function(a,b){m.each({padding:"inner"+a,content:b,"":"outer"+a},function(c,d){m.fn[d]=function(d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return V(this,function(b,c,d){var e;return m.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?m.css(b,c,g):m.style(b,c,d,g)},b,f?d:void 0,f,null)}})}),m.fn.size=function(){return this.length},m.fn.andSelf=m.fn.addBack,"function"==typeof define&&define.amd&&define("jquery",[],function(){return m});var ed=a.jQuery,fd=a.$;return m.noConflict=function(b){return a.$===m&&(a.$=fd),b&&a.jQuery===m&&(a.jQuery=ed),m},typeof b===K&&(a.jQuery=a.$=m),m});
5 | //# sourceMappingURL=jquery.min.map
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/assets/BridgeWebView/orderDetail.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
下单成功
6 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | 订单状态:AA
15 | 订单号:BB
16 | 代理商:CC
17 | 最晚到店:DD
18 |
19 |
20 |
21 | 订单总价:EE
22 | 可返现:108如何领取返现
23 |
24 | 付款方式:99
25 |
26 |
27 |
28 | 7天酒店
29 | 3个
30 | 入住:2016.10.28 离店:2016.10.29
31 | 房间数:3
32 |
33 | 带我去酒店
34 |
35 |
36 |
37 |
41 |
42 |
43 | 入住计划变更请致电酒店前台
44 |
45 | 8888
46 |
47 |
48 |
49 |
50 | 酒店订单有问题请拨打同城旅行电话
51 |
52 | 8888888
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
107 |
108 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/java/com/itheima/bridgewebviewdemo/JavaSctiptMethods.java:
--------------------------------------------------------------------------------
1 | package com.itheima.bridgewebviewdemo;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.net.Uri;
8 | import android.os.Build;
9 | import android.os.Bundle;
10 | import android.text.TextUtils;
11 | import android.util.Log;
12 | import android.webkit.WebView;
13 | import android.widget.Toast;
14 |
15 | import com.itheima.bridgewebviewdemo.view.BottomUpDialog;
16 | import com.tencent.connect.share.QQShare;
17 | import com.tencent.open.utils.ThreadManager;
18 | import com.tencent.tauth.IUiListener;
19 | import com.tencent.tauth.Tencent;
20 | import com.tencent.tauth.UiError;
21 |
22 | import org.json.JSONException;
23 | import org.json.JSONObject;
24 |
25 | /**
26 | * Created by youliang.ji on 2016/12/23.
27 | */
28 |
29 | public class JavaSctiptMethods {
30 | private WebView webView;
31 | private Activity mActivity;
32 |
33 | public JavaSctiptMethods(Activity mContext, WebView webView) {
34 | this.mActivity = mContext;
35 | this.webView = webView;
36 | }
37 |
38 | /**
39 | * 统一分发js调用android分发
40 | */
41 | public void send(String[] jsons) {
42 | final String str = jsons[0];
43 | showLog(str);
44 | try {
45 | JSONObject json = new JSONObject(str);
46 | String action = json.optString("action");//js传递过来的动作,比如callPhone代表拨号,share2QQ代表分享到QQ,其实就是H5和android通信协议(自定义的)
47 | if (!TextUtils.isEmpty(action)) {
48 | if (action.equals("toast")) {
49 | showToast(str);
50 | } else if (action.equals("callPhone")) {
51 | callphone(str);
52 | } else if (action.equals("share2QQ")) {
53 | share2QQ(str);
54 | } else if (action.equals("getHotelData")) {
55 | getHotelData(str);
56 | } else if(action.equals("showCallPhoneDialog")){//底部弹出拨号对话框
57 | final BottomUpDialog btmDlg = new BottomUpDialog(mActivity);
58 | btmDlg.setContent(json.optString("phone"));
59 | btmDlg.setOnPhoneClickListener(new BottomUpDialog.OnPhoneClickListener() {
60 | @Override
61 | public void onPhoneClick() {
62 | callphone(str);//拨号
63 | btmDlg.dismiss();
64 | }
65 | });
66 | btmDlg.show();
67 | }
68 | }
69 | } catch (JSONException e) {
70 | e.printStackTrace();
71 | }
72 | }
73 |
74 | /**
75 | * 获取酒店详情数据
76 | */
77 | private void getHotelData(String str) {
78 | try {
79 | //解析js callback方法
80 | JSONObject mJson = new JSONObject(str);
81 | String callback = mJson.optString("callback");//解析js回调方法
82 |
83 |
84 | JSONObject json = new JSONObject();
85 | json.put("hotel_name", "维多利亚大酒店");
86 | json.put("order_status", "已支付");
87 | json.put("orderId", "201612291809626");
88 | json.put("seller", "携程");
89 | json.put("expire_time", "2017年1月6日 23:00");
90 | json.put("price", "688.0");
91 | json.put("back_price", "128.0");
92 | json.put("pay_tpye", "支付宝支付");
93 | json.put("room_size", "3间房");
94 | json.put("room_count", "3");
95 | json.put("in_date", "2017年1月6日 12:00");
96 | json.put("out_date", "2017年1月8日 12:00");
97 | json.put("contact", "赵子龙先生");
98 | json.put("phone", "18888888888");
99 | json.put("server_phone", "0755-85699309");
100 | json.put("address", "深圳市宝安区兴东地铁站旁边");
101 | showLog("android收到js消息:"+str);
102 |
103 | //调用js方法必须在主线程
104 | // webView.loadUrl("javascript:"+callback+"(" + json.toString() + ")");
105 | invokeJavaScript(callback, json.toString());
106 | } catch (JSONException e) {
107 | e.printStackTrace();
108 | }
109 | }
110 |
111 | /**
112 | * 统一管理所有android调用js方法
113 | *
114 | * @param callback js回调方法名
115 | * @param json 传递json数据
116 | */
117 | private void invokeJavaScript(final String callback, final String json) {
118 | showToast("回调js方法:"+callback+", 参数:"+json);
119 |
120 | if(TextUtils.isEmpty(callback)) return;
121 | //调用js方法必须在主线程
122 | webView.post(new Runnable() {
123 | @Override
124 | public void run() {
125 | webView.loadUrl("javascript:" + callback + "(" + json + ")");
126 | }
127 | });
128 | }
129 |
130 | public void callphone(String json) {
131 | try {
132 | JSONObject jsonObject = new JSONObject(json);
133 | System.out.println("Demo callphone方法被调用:" + jsonObject.toString());
134 | //解析json
135 | String phone = jsonObject.optString("phone");
136 |
137 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//拨号:android 6.0运行时权限
138 | if (mActivity.checkSelfPermission(Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_DENIED) {
139 | mActivity.requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 100);
140 | }
141 | }
142 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
143 | mActivity.startActivity(intent);
144 | } catch (JSONException e) {
145 | e.printStackTrace();
146 | }
147 |
148 | }
149 |
150 | public void showToast(String json) {
151 | try {
152 | JSONObject jsonObject = new JSONObject(json);
153 | String msg = jsonObject.optString("msg");
154 | Toast.makeText(mActivity, msg, Toast.LENGTH_SHORT).show();
155 | } catch (JSONException e) {
156 | e.printStackTrace();
157 | }
158 | }
159 |
160 | /**
161 | * 分享到QQ
162 | *
163 | * @param jsonStr
164 | */
165 | public void share2QQ(String jsonStr) {
166 | try {
167 | JSONObject json = new JSONObject(jsonStr);
168 | Log.e("result", json.toString());
169 | //解析js传递过来的分享参数
170 | JSONObject mJson = new JSONObject(json.toString());
171 | String title = mJson.optString("title");
172 | String url = mJson.optString("url");
173 | String summary = mJson.optString("summary");
174 | String imgUrl = mJson.optString("imgUrl");
175 |
176 | //调用QQ分享SDK
177 | final Tencent tencent = Tencent.createInstance("222222", mActivity);
178 | final Bundle params = new Bundle();
179 | params.putString(QQShare.SHARE_TO_QQ_TITLE, title);
180 | params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url);
181 | params.putString(QQShare.SHARE_TO_QQ_SUMMARY, summary);
182 | params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, imgUrl);
183 |
184 | ThreadManager.getMainHandler().post(new Runnable() {
185 |
186 | @Override
187 | public void run() {
188 | if (null != tencent) {
189 | tencent.shareToQQ(mActivity, params, new IUiListener() {
190 | @Override
191 | public void onComplete(Object o) {
192 | Toast.makeText(mActivity, "" + "分享成功", Toast.LENGTH_SHORT).show();
193 | }
194 |
195 | @Override
196 | public void onError(UiError uiError) {
197 | Toast.makeText(mActivity, "" + "分享失败", Toast.LENGTH_SHORT).show();
198 | }
199 |
200 | @Override
201 | public void onCancel() {
202 | Toast.makeText(mActivity, "取消分析", Toast.LENGTH_SHORT).show();
203 | }
204 | });
205 | }
206 | }
207 | });
208 |
209 | } catch (JSONException e) {
210 | e.printStackTrace();
211 | }
212 | }
213 |
214 | private void showLog(String msg) {
215 | Log.i("result", "" + msg);
216 | }
217 |
218 | }
219 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/java/com/itheima/bridgewebviewdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.itheima.bridgewebviewdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.webkit.WebChromeClient;
6 | import android.webkit.WebViewClient;
7 |
8 | import com.itheima.view.BridgeWebView;
9 |
10 | public class MainActivity extends AppCompatActivity {
11 |
12 | private BridgeWebView mWeview;
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | initView();
19 | setWebViewClient();
20 | }
21 |
22 | private void initView() {
23 | mWeview = (BridgeWebView) findViewById(R.id.weview);
24 |
25 | mWeview.addBridgeInterface(new JavaSctiptMethods(MainActivity.this, mWeview));//设置js和android通信桥梁方法
26 | //mWeview.loadUrl("http://10.0.3.2:8080/BridgeWebView/index.html");//显示网页,在线模板
27 | mWeview.loadUrl("file:///android_asset/BridgeWebView/index.html");//本地模板
28 |
29 | }
30 |
31 | private void setWebViewClient() {
32 | mWeview.setWebViewClient(new WebViewClient());
33 |
34 | mWeview.setWebChromeClient(new WebChromeClient());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/java/com/itheima/bridgewebviewdemo/view/BottomUpDialog.java:
--------------------------------------------------------------------------------
1 | package com.itheima.bridgewebviewdemo.view;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.view.Gravity;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.LinearLayout;
9 |
10 | import com.itheima.bridgewebviewdemo.R;
11 |
12 |
13 | /**
14 | *
15 | */
16 | public class BottomUpDialog extends Dialog implements View.OnClickListener{
17 |
18 | private Button btnPhone;
19 | private OnPhoneClickListener listener;
20 | private Button btnCancel;
21 |
22 | public BottomUpDialog(Context context) {
23 | super(context, R.style.custom_dlg);
24 | setContentView(R.layout.dialog_layout);
25 | btnPhone = (Button)findViewById(R.id.btnPhone);
26 | btnCancel = (Button)findViewById(R.id.btnCancel);
27 | btnPhone.setOnClickListener(this);
28 | btnCancel.setOnClickListener(this);
29 | getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
30 | getWindow().setGravity(Gravity.BOTTOM);
31 | }
32 |
33 | public BottomUpDialog(Context context, int themeResId) {
34 | super(context, themeResId);
35 | }
36 |
37 | protected BottomUpDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
38 | super(context, cancelable, cancelListener);
39 | }
40 |
41 | public void setContent(String phone){
42 | btnPhone.setText(phone);
43 | }
44 |
45 | public void setOnPhoneClickListener(OnPhoneClickListener listener){
46 | this.listener = listener;
47 | }
48 |
49 | @Override
50 | public void onClick(View v) {
51 | switch (v.getId()){
52 | case R.id.btnPhone:
53 | dismiss();
54 | listener.onPhoneClick();
55 | break;
56 | case R.id.btnCancel:
57 | dismiss();
58 | break;
59 | }
60 | }
61 |
62 | public interface OnPhoneClickListener{
63 | void onPhoneClick();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/drawable/btn_radius_bottom_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/drawable/btn_radius_light.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/drawable/btn_radius_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/drawable/btn_radius_top_light.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/drawable/btn_radius_top_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/drawable/btn_radius_top_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/drawable/btn_radius_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/drawable/btn_raius_bottom_light.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/drawable/btn_raius_bottom_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/layout/dialog_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
16 |
21 |
22 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/BridgeWebView/701f038117681ab4b54865759ce5075465c91eb7/bridgewebviewdemo/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/BridgeWebView/701f038117681ab4b54865759ce5075465c91eb7/bridgewebviewdemo/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/BridgeWebView/701f038117681ab4b54865759ce5075465c91eb7/bridgewebviewdemo/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/BridgeWebView/701f038117681ab4b54865759ce5075465c91eb7/bridgewebviewdemo/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/BridgeWebView/701f038117681ab4b54865759ce5075465c91eb7/bridgewebviewdemo/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #00000000
8 | @color/transparent
9 | #eeffffff
10 | #eed2d2d2
11 | #a2a2a2
12 | #1482fd
13 |
14 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 | 6dp
7 |
8 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BridgeWebViewDemo
3 |
4 |
--------------------------------------------------------------------------------
/bridgewebviewdemo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
18 |
19 |
24 |
25 |
30 |
31 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/bridgewebviewlibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/bridgewebviewlibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.open-android'
4 |
5 | android {
6 | compileSdkVersion 25
7 | buildToolsVersion "25.0.0"
8 |
9 | defaultConfig {
10 | minSdkVersion 9
11 | targetSdkVersion 25
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/bridgewebviewlibrary/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 D:\ProgramFiles\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 |
--------------------------------------------------------------------------------
/bridgewebviewlibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/bridgewebviewlibrary/src/main/java/com/itheima/view/BridgeWebView.java:
--------------------------------------------------------------------------------
1 | package com.itheima.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.webkit.JavascriptInterface;
6 | import android.webkit.WebView;
7 |
8 | import java.lang.reflect.InvocationTargetException;
9 | import java.lang.reflect.Method;
10 |
11 | /**
12 | * js和android通信桥梁WebView,封装好js和安卓通信机制
13 | * Created by youliang.ji on 2016/12/23.
14 | */
15 |
16 | public class BridgeWebView extends WebView {
17 |
18 | /***
19 | * js调用android方法的映射字符串
20 | **/
21 | private static final String JS_INTERFACE = "jsInterface";
22 |
23 | public BridgeWebView(Context context) {
24 | super(context);
25 | }
26 |
27 | public BridgeWebView(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | public BridgeWebView(Context context, AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | }
34 |
35 | /**
36 | * 注册js和android通信桥梁对象
37 | *
38 | * @param obj 桥梁类对象,该对象提供方法让js调用,默认开启JavaScriptEnabled=true
39 | */
40 | public void addBridgeInterface(Object obj) {
41 | this.getSettings().setJavaScriptEnabled(true);
42 | addJavascriptInterface(new MyJavaScriptMethod(obj), JS_INTERFACE);
43 | }
44 |
45 | /**
46 | * 注册js和android通信桥梁对象
47 | * @param obj 桥梁类对象,该对象提供方法让js调用
48 | * @param url 默认开启JavaScriptEnabled=true
49 | */
50 | public void addBridgeInterface(Object obj, String url) {
51 | this.getSettings().setJavaScriptEnabled(true);
52 | addJavascriptInterface(new MyJavaScriptMethod(obj), JS_INTERFACE);
53 | loadUrl(url);
54 | }
55 |
56 | /**
57 | * 回调js方法
58 | * @param json 参数,json格式字符串
59 | */
60 | public void callbackJavaScript(String json){
61 |
62 | }
63 |
64 | private void invokeJavaScript(String callback, String params){
65 |
66 | }
67 |
68 | /**
69 | * 内置js桥梁类
70 | * Created by youliang.ji on 2016/12/23.
71 | */
72 |
73 | public class MyJavaScriptMethod {
74 |
75 | private Object mTarget;
76 | private Method targetMethod;
77 |
78 |
79 | public MyJavaScriptMethod(Object targer) {
80 | this.mTarget = targer;
81 | }
82 |
83 | /**
84 | * 内置桥梁方法
85 | * @param method 方法名
86 | * @param json js传递参数,json格式
87 | */
88 | @JavascriptInterface
89 | public void invokeMethod(String method, String[] json) {
90 | Class>[] params = new Class[]{String[].class};
91 | try {
92 | Method targetMethod = this.mTarget.getClass().getDeclaredMethod(method, params);
93 | targetMethod.invoke(mTarget, new Object[]{json});//反射调用js传递过来的方法,传参
94 |
95 | } catch (NoSuchMethodException e) {
96 | e.printStackTrace();
97 | } catch (InvocationTargetException e) {
98 | e.printStackTrace();
99 | } catch (IllegalAccessException e) {
100 | e.printStackTrace();
101 | }
102 |
103 | }
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/bridgewebviewlibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BridgeWebViewLibrary
3 |
4 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | maven { url 'https://jitpack.io' }
15 | }
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/build_project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/BridgeWebView/701f038117681ab4b54865759ce5075465c91eb7/build_project.png
--------------------------------------------------------------------------------
/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.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/BridgeWebView/701f038117681ab4b54865759ce5075465c91eb7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/screenshot1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/BridgeWebView/701f038117681ab4b54865759ce5075465c91eb7/screenshot1.gif
--------------------------------------------------------------------------------
/screenshot2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/BridgeWebView/701f038117681ab4b54865759ce5075465c91eb7/screenshot2.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':bridgewebviewlibrary', ':bridgewebviewdemo'
2 |
--------------------------------------------------------------------------------