6
6
7
7
## 功能简介
8
8
9
- 基于公共框架,进一步封装的通用webview,对于通用Webview 相关的内容,可以查看 [ LibWebview ] ( ./../libs/ui/lib-webview.md )
9
+ 基于公共框架,进一步封装的通用webview
10
10
11
11
## 组件信息
12
12
@@ -22,14 +22,88 @@ implementation 'com.bihe0832.android:common-webview:+'
22
22
23
23
## 组件功能
24
24
25
- ### BaseWebviewFragment
25
+ ### BaseWebviewFragment && BaseWebviewActivity
26
26
27
- - 封装好的通用的 [ Webview] ( ./../libs/ui/lib-webview.md ) 的Fragment,支持:
27
+ - 封装好的通用的 Webview 的Fragment、Activity ,支持:
28
28
29
29
下拉刷新,请求追加业务参数,错误页面及错误重试,非 Http 协议使用 Intent 唤起,获取网页标题,将终端的前后台切换响应到H5
30
30
31
31
- 支持Jsbridge,使用方式可以参考 [ JSBridge] ( ./../../tools/android_jsbridge.md )
32
32
33
+ ### WebviewLoggerFile
34
+
35
+ - Webview 相关的日志
36
+
37
+ ### WebViewViewModel
38
+
39
+ - 配合获取当前WebPage的title
40
+
41
+ ### NativeWebView
42
+
43
+ - 支持防 webview 远程代码执行漏洞
44
+
45
+ - 添加基础的HTML支持:
46
+
47
+ ``` java
48
+ // 设置WebView属性,能够执行Javascript脚本
49
+ webSetting. setJavaScriptEnabled(true );
50
+ webSetting. setAllowFileAccess(true );
51
+ webSetting. setSupportMultipleWindows(false );
52
+ webSetting. setPluginState(WebSettings . PluginState . ON_DEMAND );
53
+ webSetting. setUseWideViewPort(true ); // 将图片调整到适合webview的大小
54
+ webSetting. setLoadWithOverviewMode(true ); // 缩放至屏幕的大小
55
+ // 支持HTTP和HTTPS混合模式
56
+ if (Build . VERSION. SDK_INT > Build . VERSION_CODES. LOLLIPOP ) {
57
+ // 由于X5没有定义对应的常量,因此直接使用实际值,对应官方webkit的WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
58
+ webSetting. setMixedContentMode(0 );
59
+ }
60
+ // 支持缩放,默认为true。是下面那个的前提。
61
+ webSetting. setSupportZoom(true );
62
+ // 设置内置的缩放控件。
63
+ webSetting. setBuiltInZoomControls(true );
64
+
65
+ // 若上面是false,则该WebView不可缩放,这个不管设置什么都不能缩放。
66
+ webSetting. setLayoutAlgorithm(WebSettings . LayoutAlgorithm . SINGLE_COLUMN ); // 支持内容重新布局
67
+ webSetting. supportMultipleWindows(); // 多窗口
68
+ webSetting. setNeedInitialFocus(true ); // 当webview调用requestFocus时为webview设置节点
69
+ webSetting. setJavaScriptCanOpenWindowsAutomatically(true ); // 支持通过JS打开新窗口
70
+ webSetting. setLoadsImagesAutomatically(true ); // 支持自动加载图片
71
+ webSetting. setDefaultTextEncodingName(" utf-8" );// 设置编码格式
72
+ ```
73
+
74
+ - 自定义缓存支持
75
+
76
+ ```java
77
+ // 设置缓存类型
78
+ webSetting. setCacheMode(WebSettings . LOAD_DEFAULT );
79
+ // 设置缓存位置
80
+ String cacheDirPath = this . getContext(). getApplicationContext(). getFilesDir(). getAbsolutePath() + APP_CACAHE_DIRNAME ;
81
+ // JYLog.d("cacheDirPath=" + cacheDirPath);
82
+ // 设置数据库缓存路径
83
+ webSetting. setDatabasePath(cacheDirPath);
84
+ // 设置 Application Caches 缓存目录
85
+ webSetting. setAppCachePath(cacheDirPath);
86
+ // 开启 Application Caches 功能
87
+ webSetting. setAppCacheEnabled(true );
88
+ // 开启 DOM storage API 功能
89
+ webSetting. setDomStorageEnabled(true );
90
+ // 开启 database storage API 功能
91
+ webSetting. setDatabaseEnabled(true );
92
+ webSetting. setAppCacheMaxSize(Long . MAX_VALUE );
93
+ ```
94
+
95
+ ### NativeWebviewFragment
96
+
97
+ - 封装好的通用的 [NativeWebView ](. / common- webview. md) 的Fragment ,支持:
98
+
99
+ 下拉刷新,请求追加业务参数,错误页面及错误重试,非 Http 协议使用 Intent 唤起,获取网页标题,将终端的前后台切换响应到H5
100
+
101
+ - 支持Jsbridge ,使用方式可以参考 [JSBridge ](. / .. / .. / tools/ android_jsbridge. md)
102
+
103
+ ### NativeJsBridgeProxy && NativeJsBridge && NativeCookieManager
104
+
105
+ - 基于 LibJsBridge 实现的相关功能
106
+
33
107
### CommonWebviewFragment
34
108
35
109
- 对于 BaseWebviewFragment 的 进一步封装,打开时会自动在:URL 参数、cookie、UserAgent ,添加响应的字段,如下图:
0 commit comments