| 167 | ErrorPopup(error_text=error).open() |
| 168 | |
| 169 | class TestApp(App): |
| 170 | |
| 171 | kivy_request = kivy |
| 172 | inclemnet_request = inclemnet |
| 173 | |
| 174 | people = ', '.join(map(str, list(Person.select()))) |
| 175 | |
| 176 | def build(self): |
| 177 | root = Builder.load_string(kv) |
| 178 | Clock.schedule_interval(self.print_something, 2) |
| 179 | # Clock.schedule_interval(self.test_pyjnius, 5) |
| 180 | print('testing metrics') |
| 181 | from kivy.metrics import Metrics |
| 182 | print('dpi is', Metrics.dpi) |
| 183 | print('density is', Metrics.density) |
| 184 | print('fontscale is', Metrics.fontscale) |
| 185 | return root |
| 186 | |
| 187 | def print_something(self, *args): |
| 188 | print('App print tick', Clock.get_boottime()) |
| 189 | |
| 190 | def on_pause(self): |
| 191 | return True |
| 192 | |
| 193 | def test_pyjnius(self, *args): |
| 194 | try: |
| 195 | from jnius import autoclass, cast |
| 196 | except ImportError: |
| 197 | raise_error('Could not import pyjnius') |
| 198 | return |
| 199 | print('Attempting to vibrate with pyjnius') |
| 200 | ANDROID_VERSION = autoclass('android.os.Build$VERSION') |
| 201 | SDK_INT = ANDROID_VERSION.SDK_INT |
| 202 | |
| 203 | Context = autoclass("android.content.Context") |
| 204 | PythonActivity = autoclass('org.kivy.android.PythonActivity') |
| 205 | activity = PythonActivity.mActivity |
| 206 | |
| 207 | vibrator_service = activity.getSystemService(Context.VIBRATOR_SERVICE) |
| 208 | vibrator = cast("android.os.Vibrator", vibrator_service) |
| 209 | |
| 210 | if vibrator and SDK_INT >= 26: |
| 211 | print("Using android's `VibrationEffect` (SDK >= 26)") |
| 212 | VibrationEffect = autoclass("android.os.VibrationEffect") |
| 213 | vibrator.vibrate( |
| 214 | VibrationEffect.createOneShot( |
| 215 | 1000, VibrationEffect.DEFAULT_AMPLITUDE, |
| 216 | ), |
| 217 | ) |
| 218 | elif vibrator: |
| 219 | print("Using deprecated android's vibrate (SDK < 26)") |
| 220 | vibrator.vibrate(1000) |
| 221 | else: |
| 222 | print('Something happened...vibrator service disabled?') |
| 223 | |
| 224 | def test_ctypes(self, *args): |
| 225 | pass |
| 226 | |