This commit is contained in:
lunaticbum 2024-11-12 17:13:05 +09:00
parent 4b51b9807a
commit 0a2cd56c93
3 changed files with 304 additions and 339 deletions

View File

@ -59,7 +59,6 @@ import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.snackbar.Snackbar
import kr.lunaticbum.awesomewebview.databinding.AwesomeWebViewBinding
import kr.lunaticbum.awesomewebview.enums.Position
@ -74,7 +73,6 @@ import kr.lunaticbum.awesomewebview.helpers.UrlParser
import kr.lunaticbum.awesomewebview.jsInterface.CommonJsHelper
import kr.lunaticbum.awesomewebview.listeners.BroadCastManager
import kr.lunaticbum.awesomewebview.objects.CustomMenu
import kr.lunaticbum.awesomewebview.views.ShadowLayout
import kr.lunaticbum.awesomewebview.views.VideoEnabledWebChromeClient
import kr.lunaticbum.awesomewebview.views.VideoEnabledWebView
import kr.lunaticbum.converters.UnitConverter
@ -239,35 +237,35 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
protected var url: String? = null
protected var extraHeaders: Map<String, String>? = null
protected var extraHeadersMainPage: Boolean? = null
protected var appBar: AppBarLayout? = null
protected var toolbar: Toolbar? = null
protected var toolbarLayout: RelativeLayout? = null
protected var title: TextView? = null
protected var urlTv: TextView? = null
protected var close: AppCompatImageButton? = null
protected var back: AppCompatImageButton? = null
protected var forward: AppCompatImageButton? = null
protected var more: AppCompatImageButton? = null
// protected var appBar: AppBarLayout? = null
// protected var toolbar: Toolbar? = null
// protected var toolbarLayout: RelativeLayout? = null
// protected var title: TextView? = null
// protected var urlTv: TextView? = null
// protected var close: AppCompatImageButton? = null
// protected var back: AppCompatImageButton? = null
// protected var forward: AppCompatImageButton? = null
// protected var more: AppCompatImageButton? = null
protected var webView: WebView? = null
protected var webChromeClient: WebChromeClient? = null
protected var webViewClient: WebViewClient? = null
protected var gradient: View? = null
protected var divider: View? = null
protected var progressBar: ProgressBar? = null
protected var menuLayout: RelativeLayout? = null
protected var shadowLayout: ShadowLayout? = null
protected var menuBackground: LinearLayout? = null
protected var menuRefresh: LinearLayout? = null
protected var menuRefreshTv: TextView? = null
protected var menuFind: LinearLayout? = null
protected var menuFindTv: TextView? = null
protected var menuShareVia: LinearLayout? = null
protected var menuShareViaTv: TextView? = null
protected var menuCopyLink: LinearLayout? = null
protected var menuCopyLinkTv: TextView? = null
protected var menuOpenWith: LinearLayout? = null
protected var menuOpenWithTv: TextView? = null
protected var webLayout: FrameLayout? = null
// protected var gradient: View? = null
// protected var divider: View? = null
// protected var progressBar: ProgressBar? = null
// protected var menuLayout: RelativeLayout? = null
// protected var shadowLayout: ShadowLayout? = null
// protected var menuBackground: LinearLayout? = null
// protected var menuRefresh: LinearLayout? = null
// protected var menuRefreshTv: TextView? = null
// protected var menuFind: LinearLayout? = null
// protected var menuFindTv: TextView? = null
// protected var menuShareVia: LinearLayout? = null
//// protected var menuShareViaTv: TextView? = null
// protected var menuCopyLink: LinearLayout? = null
// protected var menuCopyLinkTv: TextView? = null
// protected var menuOpenWith: LinearLayout? = null
// protected var menuOpenWithTv: TextView? = null
// protected var webLayout: FrameLayout? = null
var downloadListener: DownloadListener =
DownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
BroadCastManager.onDownloadStart(
@ -529,51 +527,18 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
}
protected fun bindViews() {
appBar = findViewById(R.id.appBar)
toolbar = findViewById(R.id.toolbar)
toolbarLayout = findViewById(R.id.toolbarLayout)
title = findViewById(R.id.title)
urlTv = findViewById(R.id.url)
close = findViewById(R.id.close)
back = findViewById(R.id.back)
forward = findViewById(R.id.forward)
more = findViewById(R.id.more)
close?.setOnClickListener(this)
back?.setOnClickListener(this)
forward?.setOnClickListener(this)
more?.setOnClickListener(this)
gradient = findViewById(R.id.gradient)
divider = findViewById(R.id.divider)
progressBar = findViewById(R.id.progressBar)
menuLayout = findViewById(R.id.menuLayout)
shadowLayout = findViewById(R.id.shadowLayout)
menuBackground = findViewById(R.id.menuBackground)
menuRefresh = findViewById(R.id.menuRefresh)
menuRefreshTv = findViewById(R.id.menuRefreshTv)
menuFind = findViewById(R.id.menuFind)
menuFindTv = findViewById(R.id.menuFindTv)
menuShareVia = findViewById(R.id.menuShareVia)
menuShareViaTv = findViewById(R.id.menuShareViaTv)
menuCopyLink = findViewById(R.id.menuCopyLink)
menuCopyLinkTv = findViewById(R.id.menuCopyLinkTv)
menuOpenWith = findViewById(R.id.menuOpenWith)
menuOpenWithTv = findViewById(R.id.menuOpenWithTv)
webLayout = findViewById(R.id.webLayout)
binding.toolbarContent.close.setOnClickListener(this)
binding.toolbarContent.back.setOnClickListener(this)
binding.toolbarContent.forward.setOnClickListener(this)
binding.toolbarContent.more.setOnClickListener(this)
webView = buildWebView()
webLayout?.addView(webView)
binding.webLayout.addView(webView)
}
protected fun layoutViews() {
if (!toolbarVisible) {
setSupportActionBar(toolbar)
toolbar!!.visibility = View.GONE
setSupportActionBar(binding.toolbar)
binding.toolbar.visibility = View.GONE
}
run {
@ -586,8 +551,8 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
ViewGroup.LayoutParams.MATCH_PARENT,
toolbarHeight.toInt()
)
appBar!!.layoutParams = params
awesomeWebViewBinding.coordinatorLayout.requestLayout()
binding.appBar.layoutParams = params
binding.coordinatorLayout.requestLayout()
}
run {
@ -599,25 +564,26 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
ViewGroup.LayoutParams.MATCH_PARENT,
toolbarHeight.toInt()
)
toolbarLayout!!.minimumHeight = toolbarHeight.toInt()
toolbarLayout!!.layoutParams = params
awesomeWebViewBinding.coordinatorLayout.requestLayout()
binding.toolbarContent.toolbarLayout.minimumHeight = toolbarHeight.toInt()
binding.toolbarContent.toolbarLayout.layoutParams = params
binding.coordinatorLayout.requestLayout()
}
run {
// TextViews
val maxWidth = this.maxWidth
title!!.maxWidth = maxWidth
urlTv!!.maxWidth = maxWidth
binding.toolbarContent.title.maxWidth = maxWidth
binding.toolbarContent.url.maxWidth = maxWidth
requestCenterLayout()
}
run {
// Icons
updateIcon(close, if (rtl) R.drawable.more else R.drawable.close)
updateIcon(back, R.drawable.back)
updateIcon(forward, R.drawable.forward)
updateIcon(more, if (rtl) R.drawable.close else R.drawable.more)
updateIcon(binding.toolbarContent.close, if (rtl) R.drawable.more else R.drawable.close)
updateIcon(binding.toolbarContent.back, R.drawable.back)
updateIcon(binding.toolbarContent.forward, R.drawable.forward)
updateIcon(binding.toolbarContent.more, if (rtl) R.drawable.close else R.drawable.more)
}
run { // Divider
@ -625,15 +591,15 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
val toolbarHeight =
if (toolbarVisible) resources.getDimension(R.dimen.toolbarHeight) else 0f
val params =
gradient!!.layoutParams as CoordinatorLayout.LayoutParams
binding.gradient.layoutParams as CoordinatorLayout.LayoutParams
params.setMargins(0, toolbarHeight.toInt(), 0, 0)
gradient!!.layoutParams = params
binding.gradient.layoutParams = params
}
}
run {
// ProgressBar
progressBar!!.minimumHeight = progressBarHeight.toInt()
binding.progressBar.minimumHeight = progressBarHeight.toInt()
val params =
CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
@ -670,7 +636,7 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
0
)
}
progressBar!!.layoutParams = params
binding.progressBar.layoutParams = params
}
run {
@ -683,7 +649,7 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
var webLayoutMinimumHeight =
screenHeight - toolbarHeight - statusBarHeight
if (showDivider && !gradientDivider) webLayoutMinimumHeight -= dividerHeight
webLayout!!.minimumHeight = webLayoutMinimumHeight.toInt()
binding.webLayout.minimumHeight = webLayoutMinimumHeight.toInt()
val params =
CoordinatorLayout.LayoutParams(
@ -691,15 +657,15 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
ViewGroup.LayoutParams.MATCH_PARENT
)
params.setMargins(0, toolbarHeight.toInt(), 0, 0)
webLayout!!.layoutParams = params
binding.webLayout.layoutParams = params
}
}
@SuppressLint("SetJavaScriptEnabled")
protected fun initializeViews() {
if (!toolbarVisible) {
setSupportActionBar(toolbar)
toolbar!!.visibility = View.GONE
setSupportActionBar(binding.toolbar)
binding.toolbar.visibility = View.GONE
}
run {
@ -721,33 +687,33 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
}
run { // Toolbar
toolbar!!.setBackgroundColor(toolbarColor)
binding.toolbar.setBackgroundColor(toolbarColor)
}
run {
// TextViews
title!!.text = titleDefault
title!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize)
title!!.setTypeface(TypefaceHelper.get(this, titleFont))
title!!.setTextColor(mTitleColor)
binding.toolbarContent.title.text = titleDefault
binding.toolbarContent.title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize)
binding.toolbarContent.title.setTypeface(TypefaceHelper.get(this, titleFont))
binding.toolbarContent.title.setTextColor(mTitleColor)
urlTv!!.visibility = if (showUrl) View.VISIBLE else View.GONE
urlTv!!.text = UrlParser.getHost(url)
urlTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, urlSize)
urlTv!!.setTypeface(TypefaceHelper.get(this, urlFont))
urlTv!!.setTextColor(urlColor)
binding.toolbarContent.url.visibility = if (showUrl) View.VISIBLE else View.GONE
binding.toolbarContent.url.text = UrlParser.getHost(url)
binding.toolbarContent.url.setTextSize(TypedValue.COMPLEX_UNIT_PX, urlSize)
binding.toolbarContent.url.setTypeface(TypefaceHelper.get(this, urlFont))
binding.toolbarContent.url.setTextColor(urlColor)
requestCenterLayout()
}
run {
// Icons
close!!.setBackgroundResource(iconSelector)
back!!.setBackgroundResource(iconSelector)
forward!!.setBackgroundResource(iconSelector)
more!!.setBackgroundResource(iconSelector)
binding.toolbarContent.close.setBackgroundResource(iconSelector)
binding.toolbarContent.back.setBackgroundResource(iconSelector)
binding.toolbarContent.forward.setBackgroundResource(iconSelector)
binding.toolbarContent.more.setBackgroundResource(iconSelector)
close!!.visibility = if (showIconClose) View.VISIBLE else View.GONE
close!!.isEnabled = !disableIconClose
binding.toolbarContent.close.visibility = if (showIconClose) View.VISIBLE else View.GONE
binding.toolbarContent.close.isEnabled = !disableIconClose
if (((showMenuRefresh
|| showMenuFind
@ -755,11 +721,11 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
|| showMenuCopyLink
|| showMenuOpenWith) || customMenus!!.size > 0) && showIconMenu
) {
more!!.visibility = View.VISIBLE
binding.toolbarContent.more.visibility = View.VISIBLE
} else {
more!!.visibility = View.GONE
binding.toolbarContent.more.visibility = View.GONE
}
more!!.isEnabled = !disableIconMenu
binding.toolbarContent.more.isEnabled = !disableIconMenu
}
run { // Cookie
@ -1012,8 +978,8 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
run {
// Divider
gradient!!.visibility = if (showDivider && gradientDivider) View.VISIBLE else View.GONE
divider!!.visibility = if (showDivider && !gradientDivider) View.VISIBLE else View.GONE
binding.gradient.visibility = if (showDivider && gradientDivider) View.VISIBLE else View.GONE
binding.toolbarContent.divider.visibility = if (showDivider && !gradientDivider) View.VISIBLE else View.GONE
if (gradientDivider) {
val dividerWidth = DisplayUtil.width
val bitmap =
@ -1023,28 +989,28 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
dividerColor
)
val drawable = BitmapDrawable(resources, bitmap)
ViewUtil.setBackground(gradient, drawable)
ViewUtil.setBackground(binding.gradient, drawable)
val params =
gradient!!.layoutParams as CoordinatorLayout.LayoutParams
binding.gradient.layoutParams as CoordinatorLayout.LayoutParams
params.height = dividerHeight.toInt()
gradient!!.layoutParams = params
binding.gradient.layoutParams = params
} else {
divider!!.setBackgroundColor(dividerColor)
binding.toolbarContent.divider.setBackgroundColor(dividerColor)
val params =
divider!!.layoutParams as LinearLayout.LayoutParams
binding.toolbarContent.divider.layoutParams as LinearLayout.LayoutParams
params.height = dividerHeight.toInt()
divider!!.layoutParams = params
binding.toolbarContent.divider.layoutParams = params
}
}
run {
// ProgressBar
progressBar!!.visibility = if (showProgressBar) View.VISIBLE else View.GONE
progressBar!!.progressDrawable
binding.progressBar.visibility = if (showProgressBar) View.VISIBLE else View.GONE
binding.progressBar.progressDrawable
.setColorFilter(progressBarColor, PorterDuff.Mode.SRC_IN)
progressBar!!.minimumHeight = progressBarHeight.toInt()
binding.progressBar.minimumHeight = progressBarHeight.toInt()
val params =
CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
@ -1081,7 +1047,7 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
0
)
}
progressBar!!.layoutParams = params
binding.progressBar.layoutParams = params
}
run {
@ -1090,13 +1056,13 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
drawable.cornerRadius = resources.getDimension(R.dimen.defaultMenuCornerRadius)
drawable.setColor(menuColor)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
menuBackground!!.background = drawable
binding.menus.menuBackground.background = drawable
} else {
menuBackground!!.setBackgroundDrawable(drawable)
binding.menus.menuBackground.setBackgroundDrawable(drawable)
}
shadowLayout!!.setShadowColor(menuDropShadowColor)
shadowLayout!!.setShadowSize(menuDropShadowSize)
binding.menus.shadowLayout.setShadowColor(menuDropShadowColor)
binding.menus.shadowLayout.setShadowSize(menuDropShadowSize)
val params =
RelativeLayout.LayoutParams(
@ -1108,67 +1074,62 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
params.setMargins(0, margin, margin, 0)
params.addRule(RelativeLayout.ALIGN_PARENT_TOP)
params.addRule(if (rtl) RelativeLayout.ALIGN_PARENT_LEFT else RelativeLayout.ALIGN_PARENT_RIGHT)
shadowLayout!!.layoutParams = params
binding.menus.shadowLayout.layoutParams = params
menuRefresh!!.visibility = if (showMenuRefresh) View.VISIBLE else View.GONE
menuRefresh!!.setBackgroundResource(menuSelector)
menuRefresh!!.gravity = menuTextGravity
menuRefreshTv!!.setText(stringResRefresh)
menuRefreshTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
menuRefreshTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
menuRefreshTv!!.setTextColor(menuTextColor)
menuRefreshTv!!.setPadding(
binding.menus.menuRefresh.visibility = if (showMenuRefresh) View.VISIBLE else View.GONE
binding.menus.menuRefresh.setBackgroundResource(menuSelector)
binding.menus.menuRefresh.gravity = menuTextGravity
binding.menus.menuRefreshTv.setText(stringResRefresh)
binding.menus.menuRefreshTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
binding.menus.menuRefreshTv.setTypeface(TypefaceHelper.get(this, menuTextFont))
binding.menus.menuRefreshTv.setTextColor(menuTextColor)
binding.menus.menuRefreshTv.setPadding(
menuTextPaddingLeft.toInt(),
0,
menuTextPaddingRight.toInt(),
0
)
menuFind!!.visibility = if (showMenuFind) View.VISIBLE else View.GONE
menuFind!!.setBackgroundResource(menuSelector)
menuFind!!.gravity = menuTextGravity
menuFindTv!!.setText(stringResFind)
menuFindTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
menuFindTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
menuFindTv!!.setTextColor(menuTextColor)
menuFindTv!!.setPadding(menuTextPaddingLeft.toInt(), 0, menuTextPaddingRight.toInt(), 0)
binding.menus.menuFind.visibility = if (showMenuFind) View.VISIBLE else View.GONE
binding.menus.menuFind.setBackgroundResource(menuSelector)
binding.menus.menuFind.gravity = menuTextGravity
binding.menus.menuFindTv.setText(stringResFind)
binding.menus.menuFindTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
binding.menus.menuFindTv.setTypeface(TypefaceHelper.get(this, menuTextFont))
binding.menus.menuFindTv.setTextColor(menuTextColor)
binding.menus.menuFindTv.setPadding(menuTextPaddingLeft.toInt(), 0, menuTextPaddingRight.toInt(), 0)
menuShareVia!!.visibility = if (showMenuShareVia) View.VISIBLE else View.GONE
menuShareVia!!.setBackgroundResource(menuSelector)
menuShareVia!!.gravity = menuTextGravity
menuShareViaTv!!.setText(stringResShareVia)
menuShareViaTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
menuShareViaTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
menuShareViaTv!!.setTextColor(menuTextColor)
menuShareViaTv!!.setPadding(
binding.menus.menuShareVia.visibility = if (showMenuShareVia) View.VISIBLE else View.GONE
binding.menus.menuShareVia.setBackgroundResource(menuSelector)
binding.menus.menuShareVia.gravity = menuTextGravity
binding.menus.menuShareViaTv.setText(stringResShareVia)
binding.menus.menuShareViaTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
binding.menus.menuShareViaTv.setTypeface(TypefaceHelper.get(this, menuTextFont))
binding.menus.menuShareViaTv.setTextColor(menuTextColor)
binding.menus.menuShareViaTv.setPadding(menuTextPaddingLeft.toInt(), 0, menuTextPaddingRight.toInt(), 0)
binding.menus.menuCopyLink.visibility = if (showMenuCopyLink) View.VISIBLE else View.GONE
binding.menus.menuCopyLink.setBackgroundResource(menuSelector)
binding.menus.menuCopyLink.gravity = menuTextGravity
binding.menus.menuCopyLinkTv.setText(stringResCopyLink)
binding.menus.menuCopyLinkTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
binding.menus.menuCopyLinkTv.setTypeface(TypefaceHelper.get(this, menuTextFont))
binding.menus.menuCopyLinkTv.setTextColor(menuTextColor)
binding.menus.menuCopyLinkTv.setPadding(
menuTextPaddingLeft.toInt(),
0,
menuTextPaddingRight.toInt(),
0
)
menuCopyLink!!.visibility = if (showMenuCopyLink) View.VISIBLE else View.GONE
menuCopyLink!!.setBackgroundResource(menuSelector)
menuCopyLink!!.gravity = menuTextGravity
menuCopyLinkTv!!.setText(stringResCopyLink)
menuCopyLinkTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
menuCopyLinkTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
menuCopyLinkTv!!.setTextColor(menuTextColor)
menuCopyLinkTv!!.setPadding(
menuTextPaddingLeft.toInt(),
0,
menuTextPaddingRight.toInt(),
0
)
menuOpenWith!!.visibility = if (showMenuOpenWith) View.VISIBLE else View.GONE
menuOpenWith!!.setBackgroundResource(menuSelector)
menuOpenWith!!.gravity = menuTextGravity
menuOpenWithTv!!.setText(stringResOpenWith)
menuOpenWithTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
menuOpenWithTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
menuOpenWithTv!!.setTextColor(menuTextColor)
menuOpenWithTv!!.setPadding(
binding.menus.menuOpenWith.visibility = if (showMenuOpenWith) View.VISIBLE else View.GONE
binding.menus.menuOpenWith.setBackgroundResource(menuSelector)
binding.menus.menuOpenWith.gravity = menuTextGravity
binding.menus.menuOpenWithTv.setText(stringResOpenWith)
binding.menus.menuOpenWithTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
binding.menus.menuOpenWithTv.setTypeface(TypefaceHelper.get(this, menuTextFont))
binding.menus.menuOpenWithTv.setTextColor(menuTextColor)
binding.menus.menuOpenWithTv.setPadding(
menuTextPaddingLeft.toInt(),
0,
menuTextPaddingRight.toInt(),
@ -1204,7 +1165,7 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
hideMenu()
}
menuBackground!!.addView(
binding.menus.menuBackground.addView(
customMenuRoot,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
@ -1219,13 +1180,9 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
protected fun buildWebChromeClient(): WebChromeClient {
// Initialize the VideoEnabledWebChromeClient and set event handlers
val nonVideoLayout: View? = webLayout // Your own view, read class comments
val videoLayout =
findViewById<View>(R.id.videoLayout) as ViewGroup // Your own view, read class comments
val loadingView = layoutInflater.inflate(
R.layout.view_loading_video,
null
) // Your own view, read class comments
val nonVideoLayout: View? = binding.webLayout // Your own view, read class comments
val videoLayout = binding.videoLayout
val loadingView = layoutInflater.inflate(R.layout.view_loading_video, null) // Your own view, read class comments
val webChromeClient = MyWebChromeClient(nonVideoLayout, videoLayout, loadingView, webView)
webChromeClient.setOnToggledFullscreen { fullscreen -> // Your code to handle the full-screen change, for example showing and hiding the title bar. Example:
if (fullscreen) {
@ -1294,7 +1251,7 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
}
protected val maxWidth: Int
get() = if (forward!!.visibility == View.VISIBLE) {
get() = if (binding.toolbarContent.forward.visibility == View.VISIBLE) {
DisplayUtil.width - UnitConverter.dpToPx(100)
} else {
DisplayUtil.width - UnitConverter.dpToPx(52)
@ -1348,13 +1305,13 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
// }
}
lateinit var awesomeWebViewBinding: AwesomeWebViewBinding
lateinit var binding: AwesomeWebViewBinding
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initializeOptions()
awesomeWebViewBinding = AwesomeWebViewBinding.inflate(layoutInflater)
setContentView(awesomeWebViewBinding.root)
binding = AwesomeWebViewBinding.inflate(layoutInflater)
setContentView(binding.root)
bindViews()
layoutViews()
initializeViews()
@ -1369,7 +1326,7 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
if (webChromeClient is MyWebChromeClient && (webChromeClient as MyWebChromeClient).onBackPressed()) {
return
}
if (menuLayout!!.visibility == View.VISIBLE) {
if (binding.menus.menuLayout.visibility == View.VISIBLE) {
hideMenu()
} else if (backPressToClose || !webView!!.canGoBack()) {
exitActivity()
@ -1427,7 +1384,7 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
ClipboardManagerUtil.text = webView!!.url
val snackbar = Snackbar.make(
coordinatorLayout!!, getString(stringResCopiedToClipboard),
binding.coordinatorLayout, getString(stringResCopiedToClipboard),
Snackbar.LENGTH_LONG
)
val snackbarView = snackbar.view
@ -1466,20 +1423,20 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
}
protected fun showMenu() {
menuLayout!!.visibility = View.VISIBLE
binding.menus.menuLayout.visibility = View.VISIBLE
val popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_show)
shadowLayout!!.startAnimation(popupAnim)
binding.menus.shadowLayout.startAnimation(popupAnim)
}
protected fun hideMenu() {
val popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_hide)
shadowLayout!!.startAnimation(popupAnim)
binding.menus.shadowLayout.startAnimation(popupAnim)
popupAnim.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {
}
override fun onAnimationEnd(animation: Animation) {
menuLayout!!.visibility = View.GONE
binding.menus.menuLayout.visibility = View.GONE
}
override fun onAnimationRepeat(animation: Animation) {
@ -1499,10 +1456,10 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
DisplayUtil.width - UnitConverter.dpToPx(48) * 2
}
title!!.maxWidth = maxWidth
urlTv!!.maxWidth = maxWidth
title!!.requestLayout()
urlTv!!.requestLayout()
binding.toolbarContent.title.maxWidth = maxWidth
binding.toolbarContent.url.maxWidth = maxWidth
binding.toolbarContent.title.requestLayout()
binding.toolbarContent.url.requestLayout()
}
override fun onConfigurationChanged(newConfig: Configuration) {
@ -1540,7 +1497,6 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
}
if (msg.what == MSG_CLICK_ON_WEBVIEW) {
val hitTestResult = webView!!.hitTestResult
// 如果是图片类型或者是带有图片链接的类型
if (hitTestResult.type == HitTestResult.IMAGE_TYPE ||
hitTestResult.type == HitTestResult.SRC_IMAGE_ANCHOR_TYPE
) {
@ -1563,7 +1519,7 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
BroadCastManager.onProgressChanged(this@AwesomeWebViewActivity, key, progress)
if (progress == 100) progress = 0
progressBar!!.progress = progress
binding.progressBar.progress = progress
}
override fun onReceivedTitle(view: WebView, title: String) {
@ -1832,20 +1788,20 @@ class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
override fun onPageFinished(view: WebView, url: String) {
BroadCastManager.onPageFinished(this@AwesomeWebViewActivity, key, url)
if (updateTitleFromHtml) title!!.text = view.title
urlTv!!.text = UrlParser.getHost(url)
if (updateTitleFromHtml) binding.toolbarContent.title.text = view.title
binding.toolbarContent.url.text = UrlParser.getHost(url)
requestCenterLayout()
if (view.canGoBack() || view.canGoForward()) {
back!!.visibility = if (showIconBack) View.VISIBLE else View.GONE
forward!!.visibility = if (showIconForward) View.VISIBLE else View.GONE
back!!.isEnabled =
binding.toolbarContent.back.visibility = if (showIconBack) View.VISIBLE else View.GONE
binding.toolbarContent.forward.visibility = if (showIconForward) View.VISIBLE else View.GONE
binding.toolbarContent.back.isEnabled =
!disableIconBack && (if (rtl) view.canGoForward() else view.canGoBack())
forward!!.isEnabled =
binding.toolbarContent.forward.isEnabled =
!disableIconForward && (if (rtl) view.canGoBack() else view.canGoForward())
} else {
back!!.visibility = View.GONE
forward!!.visibility = View.GONE
binding.toolbarContent.back.visibility = View.GONE
binding.toolbarContent.forward.visibility = View.GONE
}
if (injectJavaScript != null) {

View File

@ -34,7 +34,8 @@
app:contentInsetRight="0dp"
app:contentInsetStart="0dp">
<include layout="@layout/toolbar_content" />
<include
android:id="@+id/toolbar_content" layout="@layout/toolbar_content" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
@ -54,7 +55,9 @@
android:indeterminate="false"
android:progressDrawable="@drawable/progress_drawable" />
<include layout="@layout/menus" />
<include
android:id="@+id/menus"
layout="@layout/menus" />
<!-- View where the video will be shown when video goes fullscreen -->
<RelativeLayout

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout>
<data>
</data>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/menuLayout"
android:layout_width="match_parent"
@ -143,3 +148,4 @@
</LinearLayout>
</kr.lunaticbum.awesomewebview.views.ShadowLayout>
</RelativeLayout>
</layout>