diff --git a/apps/communications/dialer/test/unit/keypad_test.js b/apps/communications/dialer/test/unit/keypad_test.js index 4780e6991a96..63d75fd67cbe 100644 --- a/apps/communications/dialer/test/unit/keypad_test.js +++ b/apps/communications/dialer/test/unit/keypad_test.js @@ -276,6 +276,27 @@ suite('dialer/keypad', function() { }); }); + suite('Keypad vibration', function() { + setup(function() { + this.sinon.spy(navigator, 'vibrate'); + subject._observePreferences(); + }); + + test('vibrates if setting is set', function() { + MockSettingsListener.mCallbacks['keyboard.vibration'](true); + + subject._touchStart('1'); + sinon.assert.calledWith(navigator.vibrate, 50); + }); + + test('does not vibrate if setting is not set', function() { + MockSettingsListener.mCallbacks['keyboard.vibration'](false); + + subject._touchStart('1'); + sinon.assert.notCalled(navigator.vibrate); + }); + }); + suite('During a call', function() { var mockCall; var mockHC; diff --git a/apps/keyboard/js/keyboard/feedback_manager.js b/apps/keyboard/js/keyboard/feedback_manager.js index 16de2295d979..504447994845 100644 --- a/apps/keyboard/js/keyboard/feedback_manager.js +++ b/apps/keyboard/js/keyboard/feedback_manager.js @@ -10,6 +10,7 @@ var VibrationFeedback = function(app) { this.settings = null; }; +// Keep in sync with Dialer and Lockscreen keypad vibration VibrationFeedback.prototype.VIBRATE_MS = 50; VibrationFeedback.prototype.start = function() { diff --git a/apps/system/lockscreen/js/lockscreen.js b/apps/system/lockscreen/js/lockscreen.js index 796f7528f875..43f52012d2ae 100755 --- a/apps/system/lockscreen/js/lockscreen.js +++ b/apps/system/lockscreen/js/lockscreen.js @@ -143,6 +143,11 @@ */ HANDLE_MAX: 70, + _passcodePadVibrationEnabled: false, + + // Keep in sync with Dialer and Keyboard vibration + _passcodePadVibrationDuration: 50, + /** * Object used for handling the clock UI element, wraps all related timers */ @@ -475,6 +480,11 @@ this.setLockMessage(value); }).bind(this)); + window.SettingsListener.observe('keyboard.vibration', + false, (function(value) { + this._passcodePadVibrationEnabled = !!value; + }).bind(this)); + // FIXME(ggp) this is currently used by Find My Device // to force locking. Should be replaced by a proper IAC API in // bug 992277. We don't need to use SettingsListener because @@ -713,6 +723,10 @@ this.passCodeEntered += key; this.updatePassCodeUI(); + if (this._passcodePadVibrationEnabled) { + navigator.vibrate(this._passcodePadVibrationDuration); + } + if (this.passCodeEntered.length === 4) { this.checkPassCode(); } diff --git a/shared/js/dialer/keypad.js b/shared/js/dialer/keypad.js index bfc76007dc54..1e2f9d9becf4 100644 --- a/shared/js/dialer/keypad.js +++ b/shared/js/dialer/keypad.js @@ -72,6 +72,10 @@ var KeypadManager = { _keypadSoundIsEnabled: false, _shortTone: false, + _vibrationEnabled: false, + + // Keep in sync with Lockscreen and keyboard vibration + kVibrationDuration: 50, // ms onValueChanged: null, @@ -383,6 +387,10 @@ var KeypadManager = { gTonesFrequencies[key], !this._onCall || this._shortTone); } + if (this._vibrationEnabled) { + navigator.vibrate(this.kVibrationDuration); + } + this._playDtmfTone(key); } @@ -710,6 +718,10 @@ var KeypadManager = { SettingsListener.observe('phone.dtmf.type', false, function(value) { self._shortTone = (value === 'short'); }); + + SettingsListener.observe('keyboard.vibration', false, function(value) { + self._vibrationEnabled = !!value; + }); }); } };