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

Add fullscreen support to android #1602

Merged
Merged
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
25 changes: 24 additions & 1 deletion webview/platforms/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
AndroidString = autoclass('java.lang.String')
CookieManager = autoclass('android.webkit.CookieManager')
WebViewA = autoclass('android.webkit.WebView')
View = autoclass('android.view.View')
KeyEvent = autoclass('android.view.KeyEvent')
PyWebViewClient = autoclass('com.pywebview.PyWebViewClient')
PyWebChromeClient = autoclass('com.pywebview.PyWebChromeClient')
Expand Down Expand Up @@ -109,6 +110,7 @@ def __init__(self, window, **kwargs):
super(BrowserView, self).__init__(**kwargs)
self.window.native = self
Clock.schedule_once(lambda dt: run_ui_thread(self.create_webview), 0)
self.is_fullscreen = False

def create_webview(self, *args):
def js_api_handler(func, params, id):
Expand Down Expand Up @@ -179,6 +181,9 @@ def webview_callback(event, data):
elif self.window.html:
self.webview.loadDataWithBaseURL(None, self.window.html, 'text/html', 'UTF-8', None)

if self.window.fullscreen:
toggle_fullscreen(self.window)

self.window.events.shown.set()

def dismiss(self):
Expand Down Expand Up @@ -414,8 +419,26 @@ def set_on_top(_, on_top):
logger.warning('Always on top mode is not supported on Android')


@run_on_ui_thread
def toggle_fullscreen(_):
logger.warning('Fullscreen mode is not supported on Android')
is_fullscreen = app.view.is_fullscreen

try:
if not is_fullscreen:
option = (View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
app.view.webview.setSystemUiVisibility(option)
app.view.is_fullscreen = True
else:
option = View.SYSTEM_UI_FLAG_VISIBLE
app.view.webview.setSystemUiVisibility(option)
app.view.is_fullscreen = False
except Exception as e:
logger.error(f"Error toggling fullscreen: {e}")


def add_tls_cert(certfile):
Expand Down