feat(browser): 添加全屏功能- 在 WebViewActivity 中实现全屏切换功能 (#4404)

- 在菜单中添加全屏选项
- 更新多语言字符串文件,添加全屏相关翻译

Co-authored-by: SunQAQ <sunqi87c6@gmail.com>
This commit is contained in:
Sun-QAQ
2024-12-06 14:32:45 +08:00
committed by GitHub
co-authored by SunQAQ
parent 6b6b53617a
commit 007ee2b17f
10 changed files with 52 additions and 0 deletions
@@ -4,10 +4,13 @@ import android.annotation.SuppressLint
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.net.Uri import android.net.Uri
import android.net.http.SslError import android.net.http.SslError
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.webkit.* import android.webkit.*
import androidx.activity.addCallback import androidx.activity.addCallback
import androidx.activity.viewModels import androidx.activity.viewModels
@@ -89,10 +92,45 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
finish() finish()
} }
} }
R.id.menu_full_screen -> toggleFullScreen(item)
} }
return super.onCompatOptionsItemSelected(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") @SuppressLint("JavascriptInterface", "SetJavaScriptEnabled")
private fun initWebView(url: String, headerMap: HashMap<String, String>) { private fun initWebView(url: String, headerMap: HashMap<String, String>) {
binding.progressBar.fontColor = accentColor binding.progressBar.fontColor = accentColor
+5
View File
@@ -18,4 +18,9 @@
android:title="@string/copy_url" android:title="@string/copy_url"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_full_screen"
android:title="@string/full_screen"
app:showAsAction="never" />
</menu> </menu>
@@ -909,6 +909,7 @@
<string name="double_page_horizontal">平板/横屏双页</string> <string name="double_page_horizontal">平板/横屏双页</string>
<string name="open_in_browser">浏览器打开</string> <string name="open_in_browser">浏览器打开</string>
<string name="copy_url">拷贝url</string> <string name="copy_url">拷贝url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打开方式</string> <string name="open_fun">打开方式</string>
<string name="use_browser_open">是否使用外部浏览器打开?</string> <string name="use_browser_open">是否使用外部浏览器打开?</string>
<string name="see">查看</string> <string name="see">查看</string>
@@ -912,6 +912,7 @@
<string name="double_page_horizontal">平板/横屏双页</string> <string name="double_page_horizontal">平板/横屏双页</string>
<string name="open_in_browser">浏览器打开</string> <string name="open_in_browser">浏览器打开</string>
<string name="copy_url">拷贝url</string> <string name="copy_url">拷贝url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打开方式</string> <string name="open_fun">打开方式</string>
<string name="use_browser_open">是否使用外部浏览器打开?</string> <string name="use_browser_open">是否使用外部浏览器打开?</string>
<string name="see">查看</string> <string name="see">查看</string>
@@ -910,6 +910,7 @@
<string name="double_page_horizontal">平板/横屏双页</string> <string name="double_page_horizontal">平板/横屏双页</string>
<string name="open_in_browser">浏览器打开</string> <string name="open_in_browser">浏览器打开</string>
<string name="copy_url">拷贝url</string> <string name="copy_url">拷贝url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打开方式</string> <string name="open_fun">打开方式</string>
<string name="use_browser_open">是否使用外部浏览器打开?</string> <string name="use_browser_open">是否使用外部浏览器打开?</string>
<string name="see">查看</string> <string name="see">查看</string>
+1
View File
@@ -909,6 +909,7 @@ Còn </string>
<string name="double_page_horizontal">Trang kép dạng máy tính bảng/ngang</string> <string name="double_page_horizontal">Trang kép dạng máy tính bảng/ngang</string>
<string name="open_in_browser">mở trong trình duyệt</string> <string name="open_in_browser">mở trong trình duyệt</string>
<string name="copy_url">sao chép url</string> <string name="copy_url">sao chép url</string>
<string name="full_screen">Toàn màn hình</string>
<string name="open_fun">mở chức năng</string> <string name="open_fun">mở chức năng</string>
<string name="use_browser_open">Mở bằng trình duyệt bên ngoài?</string> <string name="use_browser_open">Mở bằng trình duyệt bên ngoài?</string>
<string name="see">xem</string> <string name="see">xem</string>
@@ -909,6 +909,7 @@
<string name="double_page_horizontal">平板/橫屏雙頁</string> <string name="double_page_horizontal">平板/橫屏雙頁</string>
<string name="open_in_browser">瀏覽器打開</string> <string name="open_in_browser">瀏覽器打開</string>
<string name="copy_url">複製url</string> <string name="copy_url">複製url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打開方式</string> <string name="open_fun">打開方式</string>
<string name="use_browser_open">是否使用外部瀏覽器打開?</string> <string name="use_browser_open">是否使用外部瀏覽器打開?</string>
<string name="see">查看</string> <string name="see">查看</string>
@@ -911,6 +911,7 @@
<string name="double_page_horizontal">平板/橫屏雙頁</string> <string name="double_page_horizontal">平板/橫屏雙頁</string>
<string name="open_in_browser">瀏覽器打開</string> <string name="open_in_browser">瀏覽器打開</string>
<string name="copy_url">複製url</string> <string name="copy_url">複製url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打開方式</string> <string name="open_fun">打開方式</string>
<string name="use_browser_open">是否使用外部瀏覽器打開?</string> <string name="use_browser_open">是否使用外部瀏覽器打開?</string>
<string name="see">查看</string> <string name="see">查看</string>
+1
View File
@@ -914,6 +914,7 @@
<string name="double_page_horizontal">平板/横屏双页</string> <string name="double_page_horizontal">平板/横屏双页</string>
<string name="open_in_browser">浏览器打开</string> <string name="open_in_browser">浏览器打开</string>
<string name="copy_url">拷贝 URL</string> <string name="copy_url">拷贝 URL</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打开方式</string> <string name="open_fun">打开方式</string>
<string name="use_browser_open">是否使用外部浏览器打开?</string> <string name="use_browser_open">是否使用外部浏览器打开?</string>
<string name="see">查看</string> <string name="see">查看</string>
+2
View File
@@ -915,6 +915,7 @@
<string name="double_page_horizontal">Tablet/Landscape Dual Page</string> <string name="double_page_horizontal">Tablet/Landscape Dual Page</string>
<string name="open_in_browser">open in browser</string> <string name="open_in_browser">open in browser</string>
<string name="copy_url">copy url</string> <string name="copy_url">copy url</string>
<string name="full_screen">full screen</string>
<string name="open_fun">open function</string> <string name="open_fun">open function</string>
<string name="use_browser_open">Is it opened in an external browser?</string> <string name="use_browser_open">Is it opened in an external browser?</string>
<string name="see">see</string> <string name="see">see</string>
@@ -1174,4 +1175,5 @@
<string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string> <string name="read_aloud_read_phone_state_permission_rationale">阅读需要读取手机状态实现来电期间暂停朗读功能</string>
<string name="read_aloud_by_media_button_title">耳机按键启动朗读</string> <string name="read_aloud_by_media_button_title">耳机按键启动朗读</string>
<string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string> <string name="read_aloud_by_media_button_summary">通过耳机按键来启动朗读</string>
<string name="fullscreen" translatable="false">全屏</string>
</resources> </resources>