cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/2] cordova-plugin-vibration git commit: android: respect silent audio setting
Date Mon, 18 May 2015 21:18:42 GMT
Repository: cordova-plugin-vibration
Updated Branches:
  refs/heads/master ef4af1e8a -> da67e34d3


android: respect silent audio setting

Do not vibrate on android, if AudioManager.RINGER_MODE_SILENT is set.

Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/commit/da917d3e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/tree/da917d3e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/diff/da917d3e

Branch: refs/heads/master
Commit: da917d3eebb699b25268a00ab37df287bdba4cd7
Parents: 265e5bf
Author: master-of-magic <master-of-magic@gmx.de>
Authored: Fri Dec 12 16:54:28 2014 +0100
Committer: master-of-magic <master-of-magic@gmx.de>
Committed: Fri Dec 12 16:54:28 2014 +0100

----------------------------------------------------------------------
 src/android/Vibration.java | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/da917d3e/src/android/Vibration.java
----------------------------------------------------------------------
diff --git a/src/android/Vibration.java b/src/android/Vibration.java
index d557976..7a2537f 100644
--- a/src/android/Vibration.java
+++ b/src/android/Vibration.java
@@ -24,6 +24,7 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import android.content.Context;
 import android.os.Vibrator;
+import android.media.AudioManager;
 
 /**
  * This class provides access to vibration on the device.
@@ -86,8 +87,11 @@ public class Vibration extends CordovaPlugin {
         if (time == 0) {
             time = 500;
         }
-        Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
-        vibrator.vibrate(time);
+        AudioManager manager = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
+        if (manager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
+            Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
+            vibrator.vibrate(time);
+        }
     }
 
     /**
@@ -112,8 +116,11 @@ public class Vibration extends CordovaPlugin {
      *                    to start repeating, or -1 for no repetition (default).
      */
     public void vibrateWithPattern(long[] pattern, int repeat) {
-        Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
-        vibrator.vibrate(pattern, repeat);
+        AudioManager manager = (AudioManager) this.cordova.getActivity().getSystemService(Context.AUDIO_SERVICE);
+        if (manager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
+            Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
+            vibrator.vibrate(pattern, repeat);
+        }
     }
 
     /**


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message