Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
polysoft-nafmii
/
polysoft-android
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 630d3be3
authored
Oct 21, 2021
by
amateur
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
1
1 parent
11bf2794
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
127 additions
and
2 deletions
app/src/main/java/com/polysoft/nafmii/webview/MyWebChromeClient.java
app/src/main/java/com/polysoft/nafmii/webview/MyWebChromeClient.java
View file @
630d3be
package
com
.
polysoft
.
nafmii
.
webview
;
package
com
.
polysoft
.
nafmii
.
webview
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.pm.ActivityInfo
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.WindowManager
;
import
android.widget.FrameLayout
;
import
com.polysoft.nafmii.fragment.WebViewFragment
;
import
com.tencent.smtt.export.external.interfaces.ConsoleMessage
;
import
com.tencent.smtt.export.external.interfaces.ConsoleMessage
;
import
com.tencent.smtt.export.external.interfaces.IX5WebChromeClient
;
import
com.tencent.smtt.export.external.interfaces.JsResult
;
import
com.tencent.smtt.export.external.interfaces.JsResult
;
import
com.tencent.smtt.sdk.ValueCallback
;
import
com.tencent.smtt.sdk.ValueCallback
;
import
com.tencent.smtt.sdk.WebChromeClient
;
import
com.tencent.smtt.sdk.WebChromeClient
;
...
@@ -15,9 +26,22 @@ public class MyWebChromeClient extends WebChromeClient {
...
@@ -15,9 +26,22 @@ public class MyWebChromeClient extends WebChromeClient {
private
final
WebviewLoadListener
listener
;
private
final
WebviewLoadListener
listener
;
private
AtomicBoolean
mIsLoadFinish
=
new
AtomicBoolean
();
private
AtomicBoolean
mIsLoadFinish
=
new
AtomicBoolean
();
private
boolean
mIsFinish
=
false
;
private
boolean
mIsFinish
=
false
;
private
Activity
activity
;
public
MyWebChromeClient
(
WebviewLoadListener
listener
)
{
/**
this
.
listener
=
listener
;
* 视频全屏参数
*/
protected
static
final
FrameLayout
.
LayoutParams
COVER_SCREEN_PARAMS
=
new
FrameLayout
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
MATCH_PARENT
,
ViewGroup
.
LayoutParams
.
MATCH_PARENT
);
private
View
customView
;
private
FrameLayout
fullscreenContainer
;
private
IX5WebChromeClient
.
CustomViewCallback
customViewCallback
;
private
WebView
webView
;
private
int
systemVisbility
;
public
MyWebChromeClient
(
WebViewFragment
webViewFragment
)
{
this
.
listener
=
webViewFragment
;
this
.
activity
=
webViewFragment
.
getActivity
();
this
.
webView
=
webViewFragment
.
getWebview
().
getWebview
();
}
}
@Override
@Override
...
@@ -26,6 +50,107 @@ public class MyWebChromeClient extends WebChromeClient {
...
@@ -26,6 +50,107 @@ public class MyWebChromeClient extends WebChromeClient {
}
}
@Override
@Override
public
void
onShowCustomView
(
View
view
,
IX5WebChromeClient
.
CustomViewCallback
customViewCallback
)
{
if
(
this
.
activity
.
getRequestedOrientation
()
!=
ActivityInfo
.
SCREEN_ORIENTATION_LANDSCAPE
)
{
this
.
activity
.
setRequestedOrientation
(
ActivityInfo
.
SCREEN_ORIENTATION_LANDSCAPE
);
}
// super.onShowCustomView(view, customViewCallback);
showCustomView
(
view
,
customViewCallback
);
}
@Override
public
void
onHideCustomView
()
{
if
(
this
.
activity
.
getRequestedOrientation
()
!=
ActivityInfo
.
SCREEN_ORIENTATION_PORTRAIT
)
{
this
.
activity
.
setRequestedOrientation
(
ActivityInfo
.
SCREEN_ORIENTATION_PORTRAIT
);
}
// super.onHideCustomView();
hideCustomView
();
}
/**
* 视频播放全屏
**/
private
void
showCustomView
(
View
view
,
IX5WebChromeClient
.
CustomViewCallback
callback
)
{
// if a view already exists then immediately terminate the new one
if
(
customView
!=
null
)
{
callback
.
onCustomViewHidden
();
return
;
}
View
decorView
=
this
.
activity
.
getWindow
().
getDecorView
();
this
.
systemVisbility
=
decorView
.
getSystemUiVisibility
();
decorView
.
setSystemUiVisibility
(
View
.
SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
View
.
SYSTEM_UI_FLAG_IMMERSIVE
);
if
(
decorView
instanceof
FrameLayout
)
{
FrameLayout
decor
=
(
FrameLayout
)
decorView
;
fullscreenContainer
=
new
FullscreenHolder
(
this
.
activity
);
fullscreenContainer
.
addView
(
view
,
COVER_SCREEN_PARAMS
);
decor
.
addView
(
fullscreenContainer
,
COVER_SCREEN_PARAMS
);
customView
=
view
;
setStatusBarVisibility
(
false
);
customViewCallback
=
callback
;
webView
.
setVisibility
(
View
.
GONE
);
}
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
// | View.SYSTEM_UI_FLAG_FULLSCREEN
// | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
// } else {
// decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
// | View.SYSTEM_UI_FLAG_FULLSCREEN
// | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
// }
}
/**
* 隐藏视频全屏
*/
private
void
hideCustomView
()
{
if
(
customView
==
null
)
{
return
;
}
View
decorView
=
this
.
activity
.
getWindow
().
getDecorView
();
decorView
.
setSystemUiVisibility
(
systemVisbility
);
if
(
decorView
instanceof
FrameLayout
)
{
FrameLayout
decor
=
(
FrameLayout
)
decorView
;
decor
.
removeView
(
fullscreenContainer
);
fullscreenContainer
=
null
;
customView
=
null
;
setStatusBarVisibility
(
true
);
customViewCallback
.
onCustomViewHidden
();
webView
.
setVisibility
(
View
.
VISIBLE
);
}
}
/**
* 全屏容器界面
*/
static
class
FullscreenHolder
extends
FrameLayout
{
public
FullscreenHolder
(
Context
ctx
)
{
super
(
ctx
);
setBackgroundColor
(
ctx
.
getResources
().
getColor
(
android
.
R
.
color
.
black
));
}
@Override
public
boolean
onTouchEvent
(
MotionEvent
evt
)
{
return
true
;
}
}
private
void
setStatusBarVisibility
(
boolean
visible
)
{
int
flag
=
visible
?
0
:
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
;
this
.
activity
.
getWindow
().
setFlags
(
flag
,
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
);
}
@Override
public
void
onProgressChanged
(
WebView
view
,
int
newProgress
)
{
public
void
onProgressChanged
(
WebView
view
,
int
newProgress
)
{
if
(
null
!=
this
.
listener
)
{
if
(
null
!=
this
.
listener
)
{
if
(
newProgress
==
100
)
{
if
(
newProgress
==
100
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment