Last active
August 29, 2015 14:23
-
-
Save rnixx/c60a744576866a7f1a42 to your computer and use it in GitHub Desktop.
Kivy: Screen orientation change on Android at runtime
This file contains hidden or 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
from android.runnable import run_on_ui_thread | |
from jnius import autoclass | |
from kivy.app import App | |
AndroidActivityInfo = autoclass('android.content.pm.ActivityInfo') | |
AndroidPythonActivity = autoclass('org.renpy.android.PythonActivity') | |
class MyApp(App): | |
@run_on_ui_thread | |
def set_orientation_landscape(self): | |
activity = AndroidPythonActivity.mActivity | |
activity.setRequestedOrientation( | |
AndroidActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) | |
@run_on_ui_thread | |
def set_orientation_portrait(self): | |
activity = AndroidPythonActivity.mActivity | |
activity.setRequestedOrientation( | |
AndroidActivityInfo.SCREEN_ORIENTATION_PORTRAIT) | |
@run_on_ui_thread | |
def set_orientation_all(self): | |
activity = AndroidPythonActivity.mActivity | |
activity.setRequestedOrientation( | |
AndroidActivityInfo.SCREEN_ORIENTATION_SENSOR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment