Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,10 +92,45 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
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<String, String>) {
binding.progressBar.fontColor = accentColor
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/web_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@
android:title="@string/copy_url"
app:showAsAction="never" />

<item
android:id="@+id/menu_full_screen"
android:title="@string/full_screen"
app:showAsAction="never" />

</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@
<string name="double_page_horizontal">平板/横屏双页</string>
<string name="open_in_browser">浏览器打开</string>
<string name="copy_url">拷贝url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打开方式</string>
<string name="use_browser_open">是否使用外部浏览器打开?</string>
<string name="see">查看</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@
<string name="double_page_horizontal">平板/横屏双页</string>
<string name="open_in_browser">浏览器打开</string>
<string name="copy_url">拷贝url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打开方式</string>
<string name="use_browser_open">是否使用外部浏览器打开?</string>
<string name="see">查看</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@
<string name="double_page_horizontal">平板/横屏双页</string>
<string name="open_in_browser">浏览器打开</string>
<string name="copy_url">拷贝url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打开方式</string>
<string name="use_browser_open">是否使用外部浏览器打开?</string>
<string name="see">查看</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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="open_in_browser">mở trong trình duyệt</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="use_browser_open">Mở bằng trình duyệt bên ngoài?</string>
<string name="see">xem</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@
<string name="double_page_horizontal">平板/橫屏雙頁</string>
<string name="open_in_browser">瀏覽器打開</string>
<string name="copy_url">複製url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打開方式</string>
<string name="use_browser_open">是否使用外部瀏覽器打開?</string>
<string name="see">查看</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@
<string name="double_page_horizontal">平板/橫屏雙頁</string>
<string name="open_in_browser">瀏覽器打開</string>
<string name="copy_url">複製url</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打開方式</string>
<string name="use_browser_open">是否使用外部瀏覽器打開?</string>
<string name="see">查看</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@
<string name="double_page_horizontal">平板/横屏双页</string>
<string name="open_in_browser">浏览器打开</string>
<string name="copy_url">拷贝 URL</string>
<string name="full_screen">全屏</string>
<string name="open_fun">打开方式</string>
<string name="use_browser_open">是否使用外部浏览器打开?</string>
<string name="see">查看</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@
<string name="double_page_horizontal">Tablet/Landscape Dual Page</string>
<string name="open_in_browser">open in browser</string>
<string name="copy_url">copy url</string>
<string name="full_screen">full screen</string>
<string name="open_fun">open function</string>
<string name="use_browser_open">Is it opened in an external browser?</string>
<string name="see">see</string>
Expand Down Expand Up @@ -1174,4 +1175,5 @@
<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_summary">通过耳机按键来启动朗读</string>
<string name="fullscreen" translatable="false">全屏</string>
</resources>
Loading