mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
android version:
- screen rotation lock added as proposed by issue #320 - triggered (maybe experimental) by a long tap (5 seconds) to the play ground.
This commit is contained in:
parent
27e11a6a4f
commit
e7a1979477
3 changed files with 102 additions and 0 deletions
|
@ -51,8 +51,10 @@ from kivy.uix.treeview import TreeView
|
|||
from kivy.uix.treeview import TreeViewLabel
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.utils import platform
|
||||
from kivy.properties import NumericProperty
|
||||
|
||||
from pysollib.kivy.androidperms import requestStoragePerm
|
||||
from pysollib.kivy.androidrot import AndroidScreenRotation
|
||||
from pysollib.resource import CSI
|
||||
|
||||
if platform != 'android':
|
||||
|
@ -1583,6 +1585,9 @@ class LStack:
|
|||
|
||||
|
||||
class LMainWindow(BoxLayout, LTkBase):
|
||||
|
||||
longPress = NumericProperty(0)
|
||||
|
||||
def __init__(self, **kw):
|
||||
super(LMainWindow, self).__init__(orientation='vertical')
|
||||
LTkBase.__init__(self)
|
||||
|
@ -1680,6 +1685,14 @@ class LMainWindow(BoxLayout, LTkBase):
|
|||
|
||||
def on_touch_up(self, touch):
|
||||
ret = False
|
||||
# long press only on playground.
|
||||
pgs = self.workStack.peek('playground')
|
||||
if pgs:
|
||||
pg = pgs[1]
|
||||
if pg.collide_point(*touch.pos):
|
||||
if (touch.time_end-touch.time_start) > 4.5:
|
||||
self.longPress = touch.time_end
|
||||
|
||||
# standard notifikation:
|
||||
for c in self.children:
|
||||
ret = c.on_touch_up(touch)
|
||||
|
@ -1693,6 +1706,10 @@ class LMainWindow(BoxLayout, LTkBase):
|
|||
'''
|
||||
return ret
|
||||
|
||||
def on_longPress(self, instance, timestamp):
|
||||
print('longPressed at {time}'.format(time=timestamp))
|
||||
AndroidScreenRotation.toggle()
|
||||
|
||||
# Menubar:
|
||||
|
||||
def setMenu(self, menu):
|
||||
|
@ -1914,6 +1931,8 @@ class LApp(App):
|
|||
if app is None:
|
||||
return
|
||||
|
||||
AndroidScreenRotation.unlock()
|
||||
|
||||
so = get_screen_ori()
|
||||
go = so # flake8: F841 nonsense!
|
||||
so = go
|
||||
|
|
46
pysollib/kivy/androidrot.py
Normal file
46
pysollib/kivy/androidrot.py
Normal file
|
@ -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()
|
37
pysollib/kivy/androidtoast.py
Normal file
37
pysollib/kivy/androidtoast.py
Normal file
|
@ -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()
|
Loading…
Add table
Reference in a new issue