Skip to content

Instantly share code, notes, and snippets.

@rnixx
Last active August 29, 2015 14:23
Show Gist options
  • Save rnixx/c60a744576866a7f1a42 to your computer and use it in GitHub Desktop.
Save rnixx/c60a744576866a7f1a42 to your computer and use it in GitHub Desktop.
Kivy: Screen orientation change on Android at runtime
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