diff --git a/README.rst b/README.rst index a02ec19a7..8498806ba 100644 --- a/README.rst +++ b/README.rst @@ -26,7 +26,7 @@ GPS X X X Notifications X X X X X Text to speech X X X X X X Email (open mail client) X X X X X -Vibrator X +Vibrator X X Sms (send messages) X X Compass X X X Unique ID (IMEI or SN) X X X X X X diff --git a/examples/vibrator/main.py b/examples/vibrator/main.py index 3644b4e93..d7b0f30d6 100644 --- a/examples/vibrator/main.py +++ b/examples/vibrator/main.py @@ -1,8 +1,6 @@ - from kivy.app import App -from kivy.uix.boxlayout import BoxLayout from kivy.lang import Builder - +from kivy.uix.boxlayout import BoxLayout Builder.load_string(''' #:import vibrator plyer.vibrator @@ -36,10 +34,12 @@ class VibrationInterface(BoxLayout): + '''Root Widget.''' pass class VibrationApp(App): + def build(self): return VibrationInterface() diff --git a/plyer/facades.py b/plyer/facades.py index 10ec41038..e8a948531 100644 --- a/plyer/facades.py +++ b/plyer/facades.py @@ -251,7 +251,7 @@ def vibrate(self, time=1): def _vibrate(self, **kwargs): raise NotImplementedError() - def pattern(self, pattern=[0, 1], repeat=-1): + def pattern(self, pattern=(0, 1), repeat=-1): '''Ask the vibrator to vibrate with the given pattern, with an optional repeat. diff --git a/plyer/platforms/android/vibrator.py b/plyer/platforms/android/vibrator.py index 4642957ea..c28fe8e21 100644 --- a/plyer/platforms/android/vibrator.py +++ b/plyer/platforms/android/vibrator.py @@ -1,12 +1,24 @@ +'''Implementation Vibrator for Android.''' + from jnius import autoclass from plyer.facades import Vibrator from plyer.platforms.android import activity +from plyer.platforms.android import SDK_INT Context = autoclass('android.content.Context') vibrator = activity.getSystemService(Context.VIBRATOR_SERVICE) class AndroidVibrator(Vibrator): + '''Android Vibrator class. + + Supported features: + * vibrate for some period of time. + * vibrate from given pattern. + * cancel vibration. + * check whether Vibrator exists. + ''' + def _vibrate(self, time=None, **kwargs): if vibrator: vibrator.vibrate(int(1000 * time)) @@ -18,11 +30,19 @@ def _pattern(self, pattern=None, repeat=None, **kwargs): vibrator.vibrate(pattern, repeat) def _exists(self, **kwargs): - return vibrator.hasVibrator() + if SDK_INT >= 11: + return vibrator.hasVibrator() + elif activity.getSystemService(Context.VIBRATOR_SERVICE) is None: + raise NotImplementedError() + return True def _cancel(self, **kwargs): vibrator.cancel() def instance(): + '''Returns Vibrator with android features. + + :return: instance of class AndroidVibrator + ''' return AndroidVibrator()