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

Request landscape orientation when going full screen #3478

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.duckduckgo.app.browser

import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.net.Uri
import android.os.Message
Expand Down Expand Up @@ -47,6 +48,7 @@ class BrowserChromeClient @Inject constructor(

override fun onShowCustomView(
view: View,
/* requestedOrientation: Int, */
callback: CustomViewCallback?,
) {
Timber.d("on show custom view")
Expand All @@ -56,7 +58,7 @@ class BrowserChromeClient @Inject constructor(
}

customView = view
webViewClientListener?.goFullScreen(view)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented code here demonstrates what was possible with the previous API. Since there isn't currently a way to retrieve requestedOrientation from the WebView we default to SCREEN_ORIENTATION_LANDSCAPE.

webViewClientListener?.goFullScreen(view, /* requestedOrientation */ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
}

override fun onHideCustomView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3163,7 +3163,7 @@ class BrowserTabFragment :
private fun renderFullscreenMode(viewState: BrowserViewState) {
activity?.isImmersiveModeEnabled()?.let {
if (viewState.isFullScreen) {
if (!it) goFullScreen()
if (!it) goFullScreen(viewState.fullScreenRequestedOrientation)
} else {
if (it) exitFullScreen()
}
Expand Down Expand Up @@ -3462,10 +3462,10 @@ class BrowserTabFragment :
}
}

private fun goFullScreen() {
private fun goFullScreen(requestedOrientation: Int) {
Timber.i("Entering full screen")
binding.webViewFullScreenContainer.show()
activity?.toggleFullScreen()
activity?.toggleFullScreen(requestedOrientation)
showToast(R.string.fullScreenMessage, Toast.LENGTH_SHORT)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.duckduckgo.app.browser

import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.net.Uri
import android.net.http.SslCertificate
Expand Down Expand Up @@ -224,6 +225,7 @@ class BrowserTabViewModel @Inject constructor(
data class BrowserViewState(
val browserShowing: Boolean = false,
val isFullScreen: Boolean = false,
val fullScreenRequestedOrientation: Int = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED,
val isDesktopBrowsingMode: Boolean = false,
val canChangeBrowsingMode: Boolean = false,
val showPrivacyShield: Boolean = false,
Expand Down Expand Up @@ -340,7 +342,7 @@ class BrowserTabViewModel @Inject constructor(
class SendEmail(val emailAddress: String) : Command()
object ShowKeyboard : Command()
object HideKeyboard : Command()
class ShowFullScreen(val view: View) : Command()
class ShowFullScreen(val view: View, val requestedOrientation: Int) : Command()
class DownloadImage(
val url: String,
val requestUserConfirmation: Boolean,
Expand Down Expand Up @@ -1146,16 +1148,20 @@ class BrowserTabViewModel @Inject constructor(
deleteTabPreview(tabId)
}

override fun goFullScreen(view: View) {
command.value = ShowFullScreen(view)
override fun goFullScreen(view: View, requestedOrientation: Int) {
command.value = ShowFullScreen(view, requestedOrientation)

val currentState = currentBrowserViewState()
browserViewState.value = currentState.copy(isFullScreen = true)
browserViewState.value = currentState.copy(
isFullScreen = true,
fullScreenRequestedOrientation = requestedOrientation)
}

override fun exitFullScreen() {
val currentState = currentBrowserViewState()
browserViewState.value = currentState.copy(isFullScreen = false)
browserViewState.value = currentState.copy(
isFullScreen = false,
fullScreenRequestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
}

override fun navigationStateChanged(newWebNavigationState: WebNavigationState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface WebViewClientListener {
fun sendEmailRequested(emailAddress: String)
fun sendSmsRequested(telephoneNumber: String)
fun dialTelephoneNumberRequested(telephoneNumber: String)
fun goFullScreen(view: View)
fun goFullScreen(view: View, requestedOrientation: Int)
fun exitFullScreen()
fun showFileChooser(
filePathCallback: ValueCallback<Array<Uri>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.duckduckgo.app.global.view
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Build
import android.os.Bundle
import android.view.View
Expand Down Expand Up @@ -55,13 +56,14 @@ fun Context.fadeTransitionConfig(): Bundle? {
return config.toBundle()
}

fun FragmentActivity.toggleFullScreen() {
fun FragmentActivity.toggleFullScreen(requestedOrientation: Int = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
val newUiOptions = window.decorView.systemUiVisibility
.xor(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)
.xor(View.SYSTEM_UI_FLAG_FULLSCREEN)
.xor(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)

window.decorView.systemUiVisibility = newUiOptions
this.requestedOrientation = requestedOrientation
}

fun FragmentActivity.isImmersiveModeEnabled(): Boolean {
Expand Down