Skip to content

Commit

Permalink
feat: enable fullscreen in <video> tags
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO authored and lukstbit committed Jan 24, 2024
1 parent e2a3f64 commit 60d9c66
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import androidx.annotation.CheckResult
import androidx.annotation.IdRes
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.core.view.children
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle.State.RESUMED
Expand All @@ -59,8 +61,6 @@ import com.ichi2.anki.UIUtils.showThemedToast
import com.ichi2.anki.cardviewer.*
import com.ichi2.anki.cardviewer.CardHtml.Companion.legacyGetTtsTags
import com.ichi2.anki.cardviewer.HtmlGenerator.Companion.createInstance
import com.ichi2.anki.cardviewer.SingleSoundSide
import com.ichi2.anki.cardviewer.SoundSide
import com.ichi2.anki.cardviewer.TypeAnswer.Companion.createInstance
import com.ichi2.anki.dialogs.TtsVoicesDialogFragment
import com.ichi2.anki.dialogs.tags.TagsDialog
Expand Down Expand Up @@ -1810,7 +1810,7 @@ abstract class AbstractFlashcardViewer :
/**
* Provides a hook for calling "alert" from javascript. Useful for debugging your javascript.
*/
class AnkiDroidWebChromeClient : WebChromeClient() {
inner class AnkiDroidWebChromeClient : WebChromeClient() {
override fun onJsAlert(
view: WebView,
url: String,
Expand All @@ -1821,6 +1821,39 @@ abstract class AbstractFlashcardViewer :
result.confirm()
return true
}

private lateinit var customView: View

// used for displaying `<video>` in fullscreen.
// This implementation requires configChanges="orientation" in the manifest
// to avoid destroying the View if the device is rotated
override fun onShowCustomView(
paramView: View,
paramCustomViewCallback: CustomViewCallback?
) {
customView = paramView
(window.decorView as FrameLayout).addView(
customView,
FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
)
)
// hide system bars
with(WindowInsetsControllerCompat(window, window.decorView)) {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(WindowInsetsCompat.Type.systemBars())
}
}

override fun onHideCustomView() {
(window.decorView as FrameLayout).removeView(customView)
// show system bars back
with(WindowInsetsControllerCompat(window, window.decorView)) {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_DEFAULT
show(WindowInsetsCompat.Type.systemBars())
}
}
}

protected open fun closeReviewer(result: Int) {
Expand Down

0 comments on commit 60d9c66

Please sign in to comment.