| 1 | from jnius import autoclass |
| 2 | from plyer.platforms.android import activity |
| 3 | from plyer.facades import Orientation |
| 4 | |
| 5 | ActivityInfo = autoclass('android.content.pm.ActivityInfo') |
| 6 | |
| 7 | |
| 8 | class AndroidOrientation(Orientation): |
| 9 | |
| 10 | def _set_landscape(self, **kwargs): |
| 11 | reverse = kwargs.get('reverse') |
| 12 | if reverse: |
| 13 | activity.setRequestedOrientation( |
| 14 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) |
| 15 | else: |
| 16 | activity.setRequestedOrientation( |
| 17 | ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) |
| 18 | |
| 19 | def _set_portrait(self, **kwargs): |
| 20 | reverse = kwargs.get('reverse') |
| 21 | if reverse: |
| 22 | activity.setRequestedOrientation( |
| 23 | ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) |
| 24 | else: |
| 25 | activity.setRequestedOrientation( |
| 26 | ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) |
| 27 | |
| 28 | def _set_sensor(self, **kwargs): |
| 29 | mode = kwargs.get('mode') |
| 30 | |
| 31 | if mode == 'any': |
| 32 | activity.setRequestedOrientation( |
| 33 | ActivityInfo.SCREEN_ORIENTATION_SENSOR) |
| 34 | elif mode == 'landscape': |
| 35 | activity.setRequestedOrientation( |
| 36 | ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) |
| 37 | elif mode == 'portrait': |
| 38 | activity.setRequestedOrientation( |
| 39 | ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) |
| 40 | |
| 41 | |
| 42 | def instance(): |
| 43 | return AndroidOrientation() |