diff options
Diffstat (limited to 'external/plyer/platforms/ios')
-rw-r--r-- | external/plyer/platforms/ios/__init__.py | 0 | ||||
-rw-r--r-- | external/plyer/platforms/ios/accelerometer.py | 34 | ||||
-rw-r--r-- | external/plyer/platforms/ios/battery.py | 36 | ||||
-rw-r--r-- | external/plyer/platforms/ios/compass.py | 31 | ||||
-rw-r--r-- | external/plyer/platforms/ios/email.py | 41 | ||||
-rw-r--r-- | external/plyer/platforms/ios/gps.py | 45 | ||||
-rw-r--r-- | external/plyer/platforms/ios/gyroscope.py | 31 | ||||
-rw-r--r-- | external/plyer/platforms/ios/tts.py | 35 | ||||
-rw-r--r-- | external/plyer/platforms/ios/uniqueid.py | 17 |
9 files changed, 270 insertions, 0 deletions
diff --git a/external/plyer/platforms/ios/__init__.py b/external/plyer/platforms/ios/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/external/plyer/platforms/ios/__init__.py diff --git a/external/plyer/platforms/ios/accelerometer.py b/external/plyer/platforms/ios/accelerometer.py new file mode 100644 index 0000000..bf1ef02 --- /dev/null +++ b/external/plyer/platforms/ios/accelerometer.py @@ -0,0 +1,34 @@ +''' +iOS accelerometer +----------------- + +Taken from: http://pyobjus.readthedocs.org/en/latest/pyobjus_ios.html \ + #accessing-accelerometer +''' + +from plyer.facades import Accelerometer +from pyobjus import autoclass + + +class IosAccelerometer(Accelerometer): + + def __init__(self): + super(IosAccelerometer, self).__init__() + self.bridge = autoclass('bridge').alloc().init() + self.bridge.motionManager.setAccelerometerUpdateInterval_(0.1) + + def _enable(self): + self.bridge.startAccelerometer() + + def _disable(self): + self.bridge.stopAccelerometer() + + def _get_acceleration(self): + return ( + self.bridge.ac_x, + self.bridge.ac_y, + self.bridge.ac_z) + + +def instance(): + return IosAccelerometer() diff --git a/external/plyer/platforms/ios/battery.py b/external/plyer/platforms/ios/battery.py new file mode 100644 index 0000000..55aa2c6 --- /dev/null +++ b/external/plyer/platforms/ios/battery.py @@ -0,0 +1,36 @@ +from pyobjus import autoclass +from pyobjus.dylib_manager import load_framework +from plyer.facades import Battery + +load_framework('/System/Library/Frameworks/UIKit.framework') +UIDevice = autoclass('UIDevice') + + +class iOSBattery(Battery): + def __init__(self): + super(iOSBattery, self).__init__() + self.device = UIDevice.currentDevice() + + def _get_state(self): + status = {"isCharging": None, "percentage": None} + + if(not self.device.batteryMonitoringEnabled): + self.device.setBatteryMonitoringEnabled_(True) + + if self.device.batteryState == 0: + isCharging = None + elif self.device.batteryState == 2: + isCharging = True + else: + isCharging = False + + percentage = self.device.batteryLevel * 100. + + status['isCharging'] = isCharging + status['percentage'] = percentage + + return status + + +def instance(): + return iOSBattery() diff --git a/external/plyer/platforms/ios/compass.py b/external/plyer/platforms/ios/compass.py new file mode 100644 index 0000000..6e5c935 --- /dev/null +++ b/external/plyer/platforms/ios/compass.py @@ -0,0 +1,31 @@ +''' +iOS Compass +--------------------- +''' + +from plyer.facades import Compass +from pyobjus import autoclass + + +class IosCompass(Compass): + + def __init__(self): + super(IosCompass, self).__init__() + self.bridge = autoclass('bridge').alloc().init() + self.bridge.motionManager.setMagnetometerUpdateInterval_(0.1) + + def _enable(self): + self.bridge.startMagnetometer() + + def _disable(self): + self.bridge.stopMagnetometer() + + def _get_orientation(self): + return ( + self.bridge.mg_x, + self.bridge.mg_y, + self.bridge.mg_z) + + +def instance(): + return IosCompass() diff --git a/external/plyer/platforms/ios/email.py b/external/plyer/platforms/ios/email.py new file mode 100644 index 0000000..7e55e4e --- /dev/null +++ b/external/plyer/platforms/ios/email.py @@ -0,0 +1,41 @@ +try: + from urllib.parse import quote +except ImportError: + from urllib import quote + +from plyer.facades import Email +from pyobjus import autoclass, objc_str +from pyobjus.dylib_manager import load_framework + +load_framework('/System/Library/Frameworks/UIKit.framework') + +NSURL = autoclass('NSURL') +NSString = autoclass('NSString') +UIApplication = autoclass('UIApplication') + + +class iOSXEmail(Email): + def _send(self, **kwargs): + recipient = kwargs.get('recipient') + subject = kwargs.get('subject') + text = kwargs.get('text') + + uri = "mailto:" + if recipient: + uri += str(recipient) + if subject: + uri += "?" if not "?" in uri else "&" + uri += "subject=" + uri += quote(str(subject)) + if text: + uri += "?" if not "?" in uri else "&" + uri += "body=" + uri += quote(str(text)) + + nsurl = NSURL.alloc().initWithString_(objc_str(uri)) + + UIApplication.sharedApplication().openURL_(nsurl) + + +def instance(): + return iOSXEmail() diff --git a/external/plyer/platforms/ios/gps.py b/external/plyer/platforms/ios/gps.py new file mode 100644 index 0000000..4d6d665 --- /dev/null +++ b/external/plyer/platforms/ios/gps.py @@ -0,0 +1,45 @@ +''' +iOS GPS +----------- +''' + +from pyobjus import autoclass, protocol +from pyobjus.dylib_manager import load_framework +from plyer.facades import GPS + +load_framework('/System/Library/Frameworks/CoreLocation.framework') +CLLocationManager = autoclass('CLLocationManager') + + +class IosGPS(GPS): + def _configure(self): + if not hasattr(self, '_location_manager'): + self._location_manager = CLLocationManager.alloc().init() + + def _start(self): + self._location_manager.delegate = self + + self._location_manager.requestWhenInUseAuthorization() + # NSLocationWhenInUseUsageDescription key must exist in Info.plist + # file. When the authorization prompt is displayed your app goes + # into pause mode and if your app doesn't support background mode + # it will crash. + self._location_manager.startUpdatingLocation() + + def _stop(self): + self._location_manager.stopUpdatingLocation() + + @protocol('CLLocationManagerDelegate') + def locationManager_didUpdateLocations_(self, manager, locations): + location = manager.location + + self.on_location( + lat=location.coordinate.a, + lon=location.coordinate.b, + speed=location.speed, + bearing=location.course, + altitude=location.altitude) + + +def instance(): + return IosGPS() diff --git a/external/plyer/platforms/ios/gyroscope.py b/external/plyer/platforms/ios/gyroscope.py new file mode 100644 index 0000000..e8b93cf --- /dev/null +++ b/external/plyer/platforms/ios/gyroscope.py @@ -0,0 +1,31 @@ +''' +iOS Gyroscope +--------------------- +''' + +from plyer.facades import Gyroscope +from pyobjus import autoclass + + +class IosGyroscope(Gyroscope): + + def __init__(self): + super(IosGyroscope, self).__init__() + self.bridge = autoclass('bridge').alloc().init() + self.bridge.motionManager.setGyroscopeUpdateInterval_(0.1) + + def _enable(self): + self.bridge.startGyroscope() + + def _disable(self): + self.bridge.stopGyroscope() + + def _get_orientation(self): + return ( + self.bridge.gy_x, + self.bridge.gy_y, + self.bridge.gy_z) + + +def instance(): + return IosGyroscope() diff --git a/external/plyer/platforms/ios/tts.py b/external/plyer/platforms/ios/tts.py new file mode 100644 index 0000000..a711483 --- /dev/null +++ b/external/plyer/platforms/ios/tts.py @@ -0,0 +1,35 @@ +from pyobjus import autoclass, objc_str +from pyobjus.dylib_manager import load_framework + +from plyer.facades import TTS + +load_framework('/System/Library/Frameworks/AVFoundation.framework') +AVSpeechUtterance = autoclass('AVSpeechUtterance') +AVSpeechSynthesizer = autoclass('AVSpeechSynthesizer') +AVSpeechSynthesisVoice = autoclass('AVSpeechSynthesisVoice') + + +class iOSTextToSpeech(TTS): + def __init__(self): + super(iOSTextToSpeech, self).__init__() + self.synth = AVSpeechSynthesizer.alloc().init() + self.voice = None + + def _set_locale(self, locale="en-US"): + self.voice = AVSpeechSynthesisVoice.voiceWithLanguage_(objc_str(locale)) + + def _speak(self, **kwargs): + message = kwargs.get('message') + + if(not self.voice): + self._set_locale() + + utterance = \ + AVSpeechUtterance.speechUtteranceWithString_(objc_str(message)) + + utterance.voice = self.voice + self.synth.speakUtterance_(utterance) + + +def instance(): + return iOSTextToSpeech() diff --git a/external/plyer/platforms/ios/uniqueid.py b/external/plyer/platforms/ios/uniqueid.py new file mode 100644 index 0000000..1587f4b --- /dev/null +++ b/external/plyer/platforms/ios/uniqueid.py @@ -0,0 +1,17 @@ +from pyobjus import autoclass +from pyobjus.dylib_manager import load_framework +from plyer.facades import UniqueID + +load_framework('/System/Library/Frameworks/UIKit.framework') +UIDevice = autoclass('UIDevice') + + +class iOSUniqueID(UniqueID): + + def _get_uid(self): + uuid = UIDevice.currentDevice().identifierForVendor.UUIDString() + return uuid.UTF8String() + + +def instance(): + return iOSUniqueID() |