diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bc4bf7de1..19fe3a9bc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -72,6 +72,8 @@ android:name=".HomeActivity" android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|layoutDirection|smallestScreenSize|screenLayout" android:launchMode="singleTask" + android:resizeableActivity="true" + android:supportsPictureInPicture="true" android:windowSoftInputMode="adjustResize"> @@ -106,6 +108,8 @@ android:label="@string/app_name" android:persistableMode="persistNever" android:taskAffinity="" + android:resizeableActivity="true" + android:supportsPictureInPicture="true" android:windowSoftInputMode="adjustResize|stateAlwaysHidden" /> () private val webchannelIntegration = ViewBoundFeatureWrapper() private val sitePermissionWifiIntegration = ViewBoundFeatureWrapper() + private var pipFeature: PictureInPictureFeature? = null var customTabSessionId: String? = null @@ -324,6 +327,15 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session view = view ) + if (FeatureFlags.pictureInPicture) { + pipFeature = PictureInPictureFeature( + requireComponents.core.sessionManager, + requireActivity(), + customTabSessionId, + ::pipModeChanged + ) + } + appLinksFeature.set( feature = AppLinksFeature( context, @@ -423,39 +435,9 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session feature = FullScreenFeature( sessionManager, SessionUseCases(sessionManager), - customTabSessionId - ) { inFullScreen -> - if (inFullScreen) { - FenixSnackbar.make( - view = view, - duration = Snackbar.LENGTH_SHORT, - isDisplayedOnBrowserFragment = true - ) - .setText(getString(R.string.full_screen_notification)) - .show() - activity?.enterToImmersiveMode() - browserToolbarView.view.visibility = View.GONE - - if (FeatureFlags.dynamicBottomToolbar) { - engineView.setDynamicToolbarMaxHeight(0) - browserToolbarView.expand() - // Without this, fullscreen has a margin at the top. - engineView.setVerticalClipping(0) - } - } else { - activity?.exitImmersiveModeIfNeeded() - (activity as? HomeActivity)?.let { activity -> - activity.themeManager.applyStatusBarTheme(activity) - } - browserToolbarView.view.visibility = View.VISIBLE - if (FeatureFlags.dynamicBottomToolbar) { - engineView.setDynamicToolbarMaxHeight(toolbarHeight) - } - } - if (!FeatureFlags.dynamicBottomToolbar) { - updateLayoutMargins(inFullScreen) - } - }, + customTabSessionId, + ::fullScreenChanged + ), owner = this, view = view ) @@ -593,7 +575,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session if (findNavController().currentDestination?.id != R.id.searchFragment) { view?.hideKeyboard() } - fullScreenFeature.onBackPressed() } @CallSuper @@ -813,6 +794,63 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session } } + override fun onHomePressed(): Boolean { + if (pipFeature?.onHomePressed() == true) { + return true + } + return false + } + + private fun pipModeChanged(enabled: Boolean) { + val fullScreenMode = + requireComponents.core.sessionManager.runWithSessionIdOrSelected(customTabSessionId) { session -> + session.fullScreenMode + } + // If we're exiting PIP mode and we're in fullscreen mode, then we should exit fullscreen mode as well. + if (!enabled && fullScreenMode) { + onBackPressed() + fullScreenChanged(false) + } + } + + final override fun onPictureInPictureModeChanged(enabled: Boolean) { + pipFeature?.onPictureInPictureModeChanged(enabled) + } + + private fun fullScreenChanged(inFullScreen: Boolean) { + if (inFullScreen) { + FenixSnackbar.make( + view = view!!, + duration = Snackbar.LENGTH_SHORT, + isDisplayedOnBrowserFragment = true + ) + .setText(getString(R.string.full_screen_notification)) + .show() + activity?.enterToImmersiveMode() + browserToolbarView.view.visibility = View.GONE + + if (FeatureFlags.dynamicBottomToolbar) { + engineView.setDynamicToolbarMaxHeight(0) + browserToolbarView.expand() + // Without this, fullscreen has a margin at the top. + engineView.setVerticalClipping(0) + } + } else { + activity?.exitImmersiveModeIfNeeded() + (activity as? HomeActivity)?.let { activity -> + activity.themeManager.applyStatusBarTheme(activity) + } + browserToolbarView.view.visibility = View.VISIBLE + if (FeatureFlags.dynamicBottomToolbar) { + val toolbarHeight = resources.getDimensionPixelSize(R.dimen.browser_toolbar_height) + engineView.setDynamicToolbarMaxHeight(toolbarHeight) + } + } + if (!FeatureFlags.dynamicBottomToolbar) { + updateLayoutMargins(inFullScreen) + } + } + /* * Dereference these views when the fragment view is destroyed to prevent memory leaks */