blob: 731da698b683b0039e84d574eb36f482d0824e97 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package org.meshbay.client.shell
import android.content.Context
import android.view.View
import android.webkit.WebView
/**
* While `keepVisible` is set, the WebView is told its window stayed visible
* when the screen turns off. Chromium then never marks the page hidden, and
* its freeze of hidden pages — exactly 60 s after hiding, measured (spike
* S-2a C) — never starts. Set only while a cast runs or music plays: a page that is never
* hidden is never throttled, which is the battery cost the freeze exists to
* avoid.
*/
class ShellWebView(context: Context) : WebView(context) {
var keepVisible = false
override fun onWindowVisibilityChanged(visibility: Int) {
super.onWindowVisibilityChanged(if (keepVisible) View.VISIBLE else visibility)
}
override fun onVisibilityChanged(changedView: View, visibility: Int) {
super.onVisibilityChanged(changedView, if (keepVisible) View.VISIBLE else visibility)
}
}
|