Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #24477 from Rik/keypad-vibrate-1069286
Browse files Browse the repository at this point in the history
Bug 1069286 - No tactile feedback when dialling a number r=drs, r=gweng
  • Loading branch information
rik committed Oct 7, 2014
2 parents 9306e43 + f78672c commit 7d54bbb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apps/communications/dialer/test/unit/keypad_test.js
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions apps/keyboard/js/keyboard/feedback_manager.js
Expand Up @@ -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() {
Expand Down
14 changes: 14 additions & 0 deletions apps/system/lockscreen/js/lockscreen.js
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -713,6 +723,10 @@
this.passCodeEntered += key;
this.updatePassCodeUI();

if (this._passcodePadVibrationEnabled) {
navigator.vibrate(this._passcodePadVibrationDuration);
}

if (this.passCodeEntered.length === 4) {
this.checkPassCode();
}
Expand Down
12 changes: 12 additions & 0 deletions shared/js/dialer/keypad.js
Expand Up @@ -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,

Expand Down Expand Up @@ -383,6 +387,10 @@ var KeypadManager = {
gTonesFrequencies[key], !this._onCall || this._shortTone);
}

if (this._vibrationEnabled) {
navigator.vibrate(this.kVibrationDuration);
}

this._playDtmfTone(key);
}

Expand Down Expand Up @@ -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;
});
});
}
};

0 comments on commit 7d54bbb

Please sign in to comment.