1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00
PySolFC/pysollib/kivy/androidtoast.py
lufebe16 e7a1979477 android version:
- screen rotation lock added as proposed by issue #320
- triggered (maybe experimental) by a long tap (5 seconds) to the play ground.
2023-09-16 15:27:58 +02:00

37 lines
1.1 KiB
Python

# 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()