From 2ecd8bcf09ab8d5f25b6612dd299a67751baf6a4 Mon Sep 17 00:00:00 2001 From: SunQAQ Date: Thu, 5 Dec 2024 19:42:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(browser):=20=E6=B7=BB=E5=8A=A0=E5=85=A8?= =?UTF-8?q?=E5=B1=8F=E5=8A=9F=E8=83=BD-=20=E5=9C=A8=20WebViewActivity=20?= =?UTF-8?q?=E4=B8=AD=E5=AE=9E=E7=8E=B0=E5=85=A8=E5=B1=8F=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20-=20=E5=9C=A8=E8=8F=9C=E5=8D=95=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=8F=E9=80=89=E9=A1=B9=20-=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=9A=E8=AF=AD=E8=A8=80=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E6=96=87=E4=BB=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=85=A8?= =?UTF-8?q?=E5=B1=8F=E7=9B=B8=E5=85=B3=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/browser/WebViewActivity.kt | 38 +++++++++++++++++++ app/src/main/res/menu/web_view.xml | 5 +++ app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-vi/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 2 + 10 files changed, 52 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt index 65d6d9ecc2d0..6f6efa7eb44f 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt @@ -4,10 +4,13 @@ import android.annotation.SuppressLint import android.content.pm.ActivityInfo import android.net.Uri import android.net.http.SslError +import android.os.Build import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View +import android.view.WindowInsets +import android.view.WindowInsetsController import android.webkit.* import androidx.activity.addCallback import androidx.activity.viewModels @@ -89,10 +92,45 @@ class WebViewActivity : VMBaseActivity() { finish() } } + R.id.menu_full_screen -> toggleFullScreen(item) } return super.onCompatOptionsItemSelected(item) } + private var isFullScreen = false + + //实现starBrowser调起页面全屏 + private fun toggleFullScreen(item: MenuItem) { + isFullScreen = !isFullScreen + item.title = if (isFullScreen) "Exit full screen" else "Full screen" + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + // For API 30 and above + val windowInsetsController = window.insetsController + windowInsetsController?.let { + if (isFullScreen) { + it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + it.hide(WindowInsets.Type.systemBars()) + supportActionBar?.hide() + } else { + it.show(WindowInsets.Type.systemBars()) + supportActionBar?.show() + } + } + } else { + // For older APIs + @Suppress("DEPRECATION") + window.decorView.systemUiVisibility = if (isFullScreen) { + (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + or View.SYSTEM_UI_FLAG_FULLSCREEN + or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) + } else { + View.SYSTEM_UI_FLAG_VISIBLE + } + supportActionBar?.let { if (isFullScreen) it.hide() else it.show() } + } + } + @SuppressLint("JavascriptInterface", "SetJavaScriptEnabled") private fun initWebView(url: String, headerMap: HashMap) { binding.progressBar.fontColor = accentColor diff --git a/app/src/main/res/menu/web_view.xml b/app/src/main/res/menu/web_view.xml index 57b095c91d09..3bcf2a4fe284 100644 --- a/app/src/main/res/menu/web_view.xml +++ b/app/src/main/res/menu/web_view.xml @@ -18,4 +18,9 @@ android:title="@string/copy_url" app:showAsAction="never" /> + + \ No newline at end of file diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 8ab66c38e636..df4d781847d2 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -909,6 +909,7 @@ 平板/横屏双页 浏览器打开 拷贝url + 全屏 打开方式 是否使用外部浏览器打开? 查看 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 8e9e8dfc557c..508a1adf962e 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -912,6 +912,7 @@ 平板/横屏双页 浏览器打开 拷贝url + 全屏 打开方式 是否使用外部浏览器打开? 查看 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 3d4463de60fa..476cdf7713e4 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -910,6 +910,7 @@ 平板/横屏双页 浏览器打开 拷贝url + 全屏 打开方式 是否使用外部浏览器打开? 查看 diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 2098aee475c7..e68fff1da062 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -909,6 +909,7 @@ Còn Trang kép dạng máy tính bảng/ngang mở trong trình duyệt sao chép url + Toàn màn hình mở chức năng Mở bằng trình duyệt bên ngoài? xem diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 15d8027d5e98..24cfe8a87ee6 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -909,6 +909,7 @@ 平板/橫屏雙頁 瀏覽器打開 複製url + 全屏 打開方式 是否使用外部瀏覽器打開? 查看 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 6996bf91699a..51c387bc25ac 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -911,6 +911,7 @@ 平板/橫屏雙頁 瀏覽器打開 複製url + 全屏 打開方式 是否使用外部瀏覽器打開? 查看 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index a001c751eb90..65a9d10cb9e8 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -914,6 +914,7 @@ 平板/横屏双页 浏览器打开 拷贝 URL + 全屏 打开方式 是否使用外部浏览器打开? 查看 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c31a27ce4392..d9c02d99d804 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -915,6 +915,7 @@ Tablet/Landscape Dual Page open in browser copy url + full screen open function Is it opened in an external browser? see @@ -1174,4 +1175,5 @@ 阅读需要读取手机状态实现来电期间暂停朗读功能 耳机按键启动朗读 通过耳机按键来启动朗读 + 全屏