For #1901: Screenshot engineView to remove GV flash
Co-authored-by: ekager <ekager@mozilla.com>master
parent
0630e2482f
commit
d918cfdf38
|
@ -15,6 +15,7 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
import androidx.core.graphics.drawable.toDrawable
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
@ -475,9 +476,16 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
|
||||||
|
|
||||||
private fun adjustBackgroundAndNavigate(directions: NavDirections) {
|
private fun adjustBackgroundAndNavigate(directions: NavDirections) {
|
||||||
context?.let {
|
context?.let {
|
||||||
swipeRefresh?.background = ColorDrawable(Color.TRANSPARENT)
|
engineView.captureThumbnail { bitmap ->
|
||||||
engineView?.asView()?.visibility = View.GONE
|
lifecycleScope.launch {
|
||||||
findNavController().nav(R.id.browserFragment, directions)
|
// If the bitmap is null, the best we can do to reduce the flash is set transparent
|
||||||
|
swipeRefresh.background = bitmap?.toDrawable(it.resources)
|
||||||
|
?: ColorDrawable(Color.TRANSPARENT)
|
||||||
|
|
||||||
|
engineView.asView().visibility = View.GONE
|
||||||
|
findNavController().nav(R.id.browserFragment, directions)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,9 +539,9 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
return findInPageIntegration.onBackPressed() ||
|
return findInPageIntegration.onBackPressed() ||
|
||||||
fullScreenFeature.onBackPressed() ||
|
fullScreenFeature.onBackPressed() ||
|
||||||
sessionFeature.onBackPressed() ||
|
sessionFeature.onBackPressed() ||
|
||||||
removeSessionIfNeeded()
|
removeSessionIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.graphics.drawable.ColorDrawable
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
|
import androidx.core.graphics.drawable.toDrawable
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavDirections
|
import androidx.navigation.NavDirections
|
||||||
import androidx.navigation.NavOptions
|
import androidx.navigation.NavOptions
|
||||||
|
@ -184,14 +185,18 @@ class DefaultBrowserToolbarController(
|
||||||
val directions = BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
|
val directions = BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
|
||||||
sessionId = null
|
sessionId = null
|
||||||
)
|
)
|
||||||
adjustBackgroundAndNavigate.invoke(directions)
|
|
||||||
|
// Do not adjustBackground here or an exception gets thrown as we switch themes
|
||||||
|
navController.nav(R.id.browserFragment, directions)
|
||||||
browsingModeManager.mode = BrowsingMode.Normal
|
browsingModeManager.mode = BrowsingMode.Normal
|
||||||
}
|
}
|
||||||
ToolbarMenu.Item.NewPrivateTab -> {
|
ToolbarMenu.Item.NewPrivateTab -> {
|
||||||
val directions = BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
|
val directions = BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
|
||||||
sessionId = null
|
sessionId = null
|
||||||
)
|
)
|
||||||
adjustBackgroundAndNavigate.invoke(directions)
|
|
||||||
|
// Do not adjustBackground here or an exception gets thrown as we switch themes
|
||||||
|
navController.nav(R.id.browserFragment, directions)
|
||||||
browsingModeManager.mode = BrowsingMode.Private
|
browsingModeManager.mode = BrowsingMode.Private
|
||||||
}
|
}
|
||||||
ToolbarMenu.Item.FindInPage -> {
|
ToolbarMenu.Item.FindInPage -> {
|
||||||
|
@ -299,16 +304,22 @@ class DefaultBrowserToolbarController(
|
||||||
browserLayout,
|
browserLayout,
|
||||||
"${TAB_ITEM_TRANSITION_NAME}${currentSession?.id}"
|
"${TAB_ITEM_TRANSITION_NAME}${currentSession?.id}"
|
||||||
).build()
|
).build()
|
||||||
swipeRefresh.background = ColorDrawable(Color.TRANSPARENT)
|
engineView.captureThumbnail { bitmap ->
|
||||||
engineView.asView().visibility = View.GONE
|
scope.launch {
|
||||||
if (!navController.popBackStack(R.id.homeFragment, false)) {
|
// If the bitmap is null, the best we can do to reduce the flash is set transparent
|
||||||
navController.nav(
|
swipeRefresh.background = bitmap?.toDrawable(activity.resources)
|
||||||
R.id.browserFragment,
|
?: ColorDrawable(Color.TRANSPARENT)
|
||||||
R.id.action_browserFragment_to_homeFragment,
|
engineView.asView().visibility = View.GONE
|
||||||
null,
|
if (!navController.popBackStack(R.id.homeFragment, false)) {
|
||||||
options,
|
navController.nav(
|
||||||
extras
|
R.id.browserFragment,
|
||||||
)
|
R.id.action_browserFragment_to_homeFragment,
|
||||||
|
null,
|
||||||
|
options,
|
||||||
|
extras
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -367,7 +367,7 @@ class DefaultBrowserToolbarControllerTest {
|
||||||
verify {
|
verify {
|
||||||
val directions = BrowserFragmentDirections
|
val directions = BrowserFragmentDirections
|
||||||
.actionBrowserFragmentToSearchFragment(sessionId = null)
|
.actionBrowserFragmentToSearchFragment(sessionId = null)
|
||||||
adjustBackgroundAndNavigate.invoke(directions)
|
navController.nav(R.id.browserFragment, directions)
|
||||||
}
|
}
|
||||||
verify { browsingModeManager.mode = BrowsingMode.Private }
|
verify { browsingModeManager.mode = BrowsingMode.Private }
|
||||||
}
|
}
|
||||||
|
@ -438,7 +438,7 @@ class DefaultBrowserToolbarControllerTest {
|
||||||
verify {
|
verify {
|
||||||
val directions = BrowserFragmentDirections
|
val directions = BrowserFragmentDirections
|
||||||
.actionBrowserFragmentToSearchFragment(sessionId = null)
|
.actionBrowserFragmentToSearchFragment(sessionId = null)
|
||||||
adjustBackgroundAndNavigate.invoke(directions)
|
navController.nav(R.id.browserFragment, directions)
|
||||||
}
|
}
|
||||||
verify { browsingModeManager.mode = BrowsingMode.Normal }
|
verify { browsingModeManager.mode = BrowsingMode.Normal }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue