-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- screen rotation lock added as proposed by issue #320 - triggered (maybe experimental) by a long tap (5 seconds) to the play ground.
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# flake8: noqa | ||
# LB230914. | ||
|
||
from pysollib.kivy.androidtoast import AndroidToaster | ||
from pysollib.mygettext import _ | ||
try: | ||
import jnius | ||
except ImportError: | ||
jnius = None | ||
|
||
class AndroidRot(object): | ||
def __init__(self): | ||
self.locked = False | ||
if jnius is None: | ||
return | ||
self.PythonActivity = jnius.autoclass('org.kivy.android.PythonActivity') | ||
self.ActivityInfo = jnius.autoclass('android.content.pm.ActivityInfo') | ||
self.currentActivity = jnius.cast('android.app.Activity', self.PythonActivity.mActivity) | ||
|
||
def isLocked(self): | ||
return self.locked | ||
|
||
def lock(self): | ||
if jnius is not None: | ||
self.currentActivity.setRequestedOrientation( | ||
self.ActivityInfo.SCREEN_ORIENTATION_LOCKED) | ||
self.locked = True | ||
|
||
def unlock(self): | ||
if jnius is not None: | ||
self.currentActivity.setRequestedOrientation( | ||
self.ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) | ||
self.locked = False | ||
|
||
def toggle(self): | ||
if self.locked: | ||
self.unlock() | ||
if jnius is not None: | ||
AndroidToaster.toastShort(_("screen rotation enabled")) | ||
else: | ||
self.lock() | ||
if jnius is not None: | ||
AndroidToaster.toastShort(_("screen rotation disabled")) | ||
return self.isLocked() | ||
|
||
AndroidScreenRotation = AndroidRot() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# flake8: noqa | ||
# LB230914. | ||
|
||
try: | ||
import jnius | ||
from android.runnable import run_on_ui_thread | ||
except ImportError: | ||
jnius = None | ||
def run_on_ui_thread(a): | ||
pass | ||
|
||
class AndroidToast(object): | ||
def __init__(self): | ||
if jnius is None: | ||
return | ||
self.PythonActivity = jnius.autoclass('org.kivy.android.PythonActivity') | ||
self.Toast = jnius.autoclass('android.widget.Toast') | ||
self.String = jnius.autoclass('java.lang.String') | ||
self.context = self.PythonActivity.mActivity | ||
|
||
@run_on_ui_thread | ||
def toastShort(self, message): | ||
if jnius is not None: | ||
jtext = jnius.cast('java.lang.CharSequence', self.String(message)) | ||
toast = self.Toast.makeText( | ||
self.context, jtext, self.Toast.LENGTH_SHORT) | ||
toast.show() | ||
|
||
@run_on_ui_thread | ||
def toastLong(self, message): | ||
if jnius is not None: | ||
jtext = jnius.cast('java.lang.CharSequence', self.String(message)) | ||
toast = self.Toast.makeText( | ||
self.context, jtext, self.Toast.LENGTH_LONG) | ||
toast.show() | ||
|
||
AndroidToaster = AndroidToast() |