Created
September 19, 2017 20:14
-
-
Save hackalog/c02703f78f09cf606cf5c1f32c074f23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kivy | |
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy.logger import Logger | |
from kivy.properties import ObjectProperty | |
from kivy.uix.anchorlayout import AnchorLayout | |
from kivy.core.window import Window | |
if kivy.platform == 'android': | |
from jnius import autoclass, PythonJavaClass, java_method | |
_PythonActivity = autoclass('org.kivy.android.PythonActivity') | |
class Runnable(PythonJavaClass): | |
__javainterfaces__ = ['java/lang/Runnable'] | |
__runnables__ = [] | |
def __init__(self, func): | |
super(Runnable, self).__init__() | |
self.func = func | |
def __call__(self, args, kwargs): | |
self.args = args | |
self.kwargs = kwargs | |
Runnable.__runnables__.append(self) | |
_PythonActivity.mActivity.runOnUiThread(self) | |
@java_method('()V') | |
def run(self): | |
try: | |
self.func(*self.args, **self.kwargs) | |
except: | |
import traceback | |
traceback.print_exc() | |
Runnable.__runnables__.remove(self) | |
def run_on_ui_thread(f): | |
def f2(*args, **kwargs): | |
Runnable(f)(args, kwargs) | |
return f2 | |
@run_on_ui_thread | |
def go_fullscreen(inst=None, value=None, *args, **kwargs): | |
'''Change to fullscreen if we are on a platform that supports it. | |
''' | |
if kivy.platform == 'android': | |
Logger.debug("go_fullscreen: Attempting to enter immersive mode") | |
activity = autoclass('org.kivy.android.PythonActivity').mActivity | |
View = autoclass('android.view.View') | |
decorView = activity.getWindow().getDecorView() | |
flags = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY \ | |
| View.SYSTEM_UI_FLAG_FULLSCREEN \ | |
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN \ | |
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE \ | |
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION \ | |
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
decorView.setSystemUiVisibility(flags) | |
def remove_loading_screen(): | |
'''Remove kivy splashscreen | |
''' | |
activity = autoclass('org.kivy.android.PythonActivity').mActivity | |
activity.removeLoadingScreen() | |
else: # not supported. stub out | |
def go_fullscreen(inst=None, value=None, *args, **kwargs): | |
pass | |
def remove_loading_screen(): | |
pass | |
class ImmersiveBug(AnchorLayout): | |
appinfo = ObjectProperty(None) | |
def do_fullscreen(self): | |
go_fullscreen() | |
self.canvas.ask_update() | |
def update_info(self, inst=None, val=None): | |
'''Update debug label text''' | |
app = App.get_running_app() | |
app_info_d = { | |
'root.size': app.root.size, | |
'Window.size': Window.size, | |
'Window.gl_size': Window._win._get_gl_size(), | |
'Window.window_size': Window._win.window_size, | |
'Window.fullscreen': Window.fullscreen, | |
'Window.borderless': Window.borderless, | |
} | |
self.appinfo.text = '\n'.join(['{}={}'.format(k,v) for k,v in app_info_d.items()]) | |
kv = Builder.load_string(''' | |
ImmersiveBug: | |
canvas.before: | |
Color: | |
rgba: .8,.5,.5,.5 | |
Rectangle: | |
pos: self.pos | |
size: self.size | |
appinfo: _appinfo | |
padding: '50dp' | |
BoxLayout: | |
Label: | |
id: _appinfo | |
text: 'refresh to see window data' | |
BoxLayout: | |
orientation: 'vertical' | |
Button: | |
Button: | |
text: 'refresh' | |
on_release: root.update_info() | |
Button: | |
Button: | |
Button: | |
text: 'fullscreen' | |
on_release: root.do_fullscreen() | |
Button: | |
Button: | |
Button: | |
text: 'Update Canvas' | |
on_release: root.canvas.ask_update() | |
Button: | |
<Widget>: | |
canvas.after: | |
Color: | |
rgba: .5,.5,.5,.5 | |
Line: | |
rectangle: self.x, self.y, self.width, self.height | |
width: 2 | |
''') | |
class ImmersiveBugApp(App): | |
def build(self): | |
self.root = kv | |
return self.root | |
if __name__ == '__main__': | |
ImmersiveBugApp().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p4a apk --name=immersive --private . --version=1 --requirements=hostpython2,kivy,android \ | |
--orientation=landscape --package=org.learnleapfly.immersive |
More bugs:
- Leave the app by swiping up from the bottom and hitting the circle button.
- relaunch the app
- Note, android soft menu bar has reappeared. App is positioned under the menu bar (BUG #2)
- Press fullscreen. Soft menu will disappear, but note app window is not full-sized (black space at top, resolution wrong) BUG #3
- Worse, notice that your touch events on the buttons are offset by the size of the black bar (pos is out of sync with displayed graphics)
This was reproduced on a Google Pixel C tablet with android 6.0.1 (Build MXC89L)
Has anyone found a solution to this problem?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To reproduce (on an Android device)