13
13
See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
- package com .ycbjie .webviewlib ;
16
+ package com .ycbjie .webviewlib . base ;
17
17
18
18
import android .Manifest ;
19
- import android .annotation .SuppressLint ;
20
19
import android .app .Activity ;
21
20
import android .content .Context ;
22
21
import android .content .Intent ;
23
- import android .content .pm .ActivityInfo ;
24
22
import android .content .pm .PackageManager ;
25
23
import android .graphics .Bitmap ;
26
24
import android .net .Uri ;
27
25
import android .os .Build ;
28
26
import android .os .Message ;
29
27
import android .support .v4 .app .ActivityCompat ;
30
- import android .view .LayoutInflater ;
31
- import android .view .View ;
32
- import android .widget .FrameLayout ;
33
28
34
29
import com .tencent .smtt .export .external .interfaces .ConsoleMessage ;
35
30
import com .tencent .smtt .export .external .interfaces .GeolocationPermissionsCallback ;
36
- import com .tencent .smtt .export .external .interfaces .IX5WebChromeClient ;
37
31
import com .tencent .smtt .export .external .interfaces .JsPromptResult ;
38
32
import com .tencent .smtt .export .external .interfaces .JsResult ;
39
33
import com .tencent .smtt .export .external .interfaces .PermissionRequest ;
40
34
import com .tencent .smtt .sdk .ValueCallback ;
41
- import com .tencent .smtt .sdk .WebChromeClient ;
42
35
import com .tencent .smtt .sdk .WebStorage ;
43
36
import com .tencent .smtt .sdk .WebView ;
37
+ import com .ycbjie .webviewlib .inter .InterWebListener ;
38
+ import com .ycbjie .webviewlib .inter .VideoWebListener ;
39
+ import com .ycbjie .webviewlib .utils .X5LogUtils ;
40
+ import com .ycbjie .webviewlib .utils .X5WebUtils ;
41
+ import com .ycbjie .webviewlib .video .VideoChromeClient ;
44
42
import static android .app .Activity .RESULT_OK ;
45
43
46
44
/**
55
53
* 作用:WebViewClient主要辅助WebView执行处理各种响应请求事件的
56
54
* </pre>
57
55
*/
58
- public class X5WebChromeClient extends WebChromeClient {
56
+ public class X5WebChromeClient extends VideoChromeClient {
59
57
60
58
private ValueCallback <Uri > mUploadMessage ;
61
59
private ValueCallback <Uri []> mUploadMessageForAndroid5 ;
@@ -65,15 +63,9 @@ public class X5WebChromeClient extends WebChromeClient {
65
63
public static int FILE_CHOOSER_RESULT_CODE = 1 ;
66
64
public static int FILE_CHOOSER_RESULT_CODE_5 = 2 ;
67
65
private InterWebListener webListener ;
68
- private VideoWebListener videoWebListener ;
69
66
private boolean isShowContent = false ;
70
67
private Context context ;
71
- private View progressVideo ;
72
- private View customView ;
73
- private IX5WebChromeClient .CustomViewCallback customViewCallback ;
74
- private FullscreenHolder videoFullView ;
75
68
private WebView webView ;
76
- private boolean isShowCustomVideo = true ;
77
69
public static final int REQUEST_LOCATION = 100 ;
78
70
79
71
/**
@@ -89,22 +81,23 @@ public void setWebListener(InterWebListener listener){
89
81
* @param videoWebListener listener
90
82
*/
91
83
public void setVideoWebListener (VideoWebListener videoWebListener ){
92
- this . videoWebListener = videoWebListener ;
84
+ setVideoListener ( videoWebListener ) ;
93
85
}
94
86
95
87
/**
96
- * 设置是否使用
88
+ * 设置是否使用自定义视频视图,建议使用
97
89
* @param showCustomVideo 是否使用自定义视频视图
98
90
*/
99
91
public void setShowCustomVideo (boolean showCustomVideo ) {
100
- isShowCustomVideo = showCustomVideo ;
92
+ setCustomVideo ( showCustomVideo ) ;
101
93
}
102
94
103
95
/**
104
96
* 构造方法
105
97
* @param context 上下文
106
98
*/
107
99
public X5WebChromeClient (WebView webView , Context context ) {
100
+ super (context , webView );
108
101
this .context = context ;
109
102
this .webView = webView ;
110
103
}
@@ -259,133 +252,6 @@ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermiss
259
252
}
260
253
}
261
254
262
- /**
263
- * 当全屏的视频正在缓冲时,此方法返回一个占位视图(比如旋转的菊花)。
264
- * 视频加载时进程loading
265
- */
266
- @ Override
267
- public View getVideoLoadingProgressView () {
268
- if (progressVideo == null && context !=null ) {
269
- LayoutInflater inflater = LayoutInflater .from (context );
270
- progressVideo = inflater .inflate (R .layout .view_web_video_progress , null );
271
- }
272
- return progressVideo ;
273
- }
274
-
275
- /**
276
- * 通知应用当前页进入了全屏模式,此时应用必须显示一个包含网页内容的自定义View
277
- * 播放网络视频时全屏会被调用的方法,播放视频切换为横屏
278
- * @param view view
279
- * @param callback callback
280
- */
281
- @ SuppressLint ("SourceLockedOrientationActivity" )
282
- @ Override
283
- public void onShowCustomView (View view , IX5WebChromeClient .CustomViewCallback callback ) {
284
- X5LogUtils .i ("-------onShowCustomView-------" );
285
- if (isShowCustomVideo ){
286
- if (context instanceof Activity ){
287
- Activity activity = (Activity ) context ;
288
- activity .setRequestedOrientation (ActivityInfo .SCREEN_ORIENTATION_LANDSCAPE );
289
- videoWebListener .hindWebView ();
290
- // 如果一个视图已经存在,那么立刻终止并新建一个
291
- if (customView != null ) {
292
- callback .onCustomViewHidden ();
293
- return ;
294
- }
295
- fullViewAddView (view );
296
- customView = view ;
297
- customViewCallback = callback ;
298
- videoWebListener .showVideoFullView ();
299
- }
300
- }
301
- }
302
-
303
- /**
304
- * 添加view到decorView容齐中
305
- * @param view view
306
- */
307
- private void fullViewAddView (View view ) {
308
- //增强逻辑判断,尤其是getWindow()
309
- if (context !=null && context instanceof Activity ){
310
- Activity activity = (Activity ) context ;
311
- if (activity .getWindow ()!=null ){
312
- FrameLayout decor = (FrameLayout ) activity .getWindow ().getDecorView ();
313
- videoFullView = new FullscreenHolder (activity );
314
- videoFullView .addView (view );
315
- decor .addView (videoFullView );
316
- }
317
- }
318
- }
319
-
320
- /**
321
- * 获取视频控件view
322
- * @return view
323
- */
324
- private FrameLayout getVideoFullView () {
325
- return videoFullView ;
326
- }
327
-
328
- /**
329
- * 销毁的时候需要移除一下视频view
330
- */
331
- public void removeVideoView (){
332
- if (videoFullView !=null ){
333
- videoFullView .removeAllViews ();
334
- }
335
- }
336
-
337
- /**
338
- * 通知应用当前页退出了全屏模式,此时应用必须隐藏之前显示的自定义View
339
- * 视频播放退出全屏会被调用的
340
- */
341
- @ SuppressLint ("SourceLockedOrientationActivity" )
342
- @ Override
343
- public void onHideCustomView () {
344
- X5LogUtils .i ("-------onHideCustomView-------" );
345
- if (isShowCustomVideo ){
346
- if (customView == null ) {
347
- // 不是全屏播放状态
348
- return ;
349
- }
350
- if (context !=null && context instanceof Activity ){
351
- Activity activity = (Activity ) context ;
352
- activity .setRequestedOrientation (ActivityInfo .SCREEN_ORIENTATION_PORTRAIT );
353
- }
354
- customView .setVisibility (View .GONE );
355
- if (getVideoFullView () != null ) {
356
- getVideoFullView ().removeView (customView );
357
- }
358
- customView = null ;
359
- if (videoWebListener !=null ){
360
- videoWebListener .hindVideoFullView ();
361
- }
362
- customViewCallback .onCustomViewHidden ();
363
- if (videoWebListener !=null ){
364
- videoWebListener .showWebView ();
365
- }
366
- }
367
- }
368
-
369
- /**
370
- * 判断是否是全屏
371
- */
372
- public boolean inCustomView () {
373
- return (customView != null );
374
- }
375
-
376
- /**
377
- * 逻辑是:先判断是否全频播放,如果是,则退出全频播放
378
- * 全屏时按返加键执行退出全屏方法
379
- */
380
- @ SuppressLint ("SourceLockedOrientationActivity" )
381
- public void hideCustomView () {
382
- this .onHideCustomView ();
383
- if (context !=null && context instanceof Activity ){
384
- Activity activity = (Activity ) context ;
385
- activity .setRequestedOrientation (ActivityInfo .SCREEN_ORIENTATION_PORTRAIT );
386
- }
387
- }
388
-
389
255
/**
390
256
* 打开文件夹,扩展浏览器上传文件,3.0++版本
391
257
* @param uploadMsg msg
0 commit comments