This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
keypad.js
840 lines (719 loc) · 25 KB
/
keypad.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
/* exported KeypadManager */
/* globals AddContactMenu, CallHandler, CallLogDBManager, CallsHandler,
CallScreen, ConfirmDialog, CustomDialog, DtmfTone, FontSizeManager,
LazyLoader, LazyL10n, MultiSimActionButton, Promise,
SimSettingsHelper, SettingsListener, TonePlayer */
'use strict';
// Frequencies coming from http://en.wikipedia.org/wiki/Telephone_keypad
var gTonesFrequencies = {
'1': [697, 1209], '2': [697, 1336], '3': [697, 1477],
'4': [770, 1209], '5': [770, 1336], '6': [770, 1477],
'7': [852, 1209], '8': [852, 1336], '9': [852, 1477],
'*': [941, 1209], '0': [941, 1336], '#': [941, 1477]
};
var KeypadManager = {
kMaxDigits: 50,
_phoneNumber: '',
_onCall: false,
_keypadSoundIsEnabled: false,
_shortTone: false,
_vibrationEnabled: false,
// Keep in sync with Lockscreen and keyboard vibration
kVibrationDuration: 50, // ms
onValueChanged: null,
get phoneNumberView() {
delete this.phoneNumberView;
this.phoneNumberView = document.getElementById('phone-number-view');
return this.phoneNumberView;
},
get phoneNumberViewContainer() {
delete this.phoneNumberViewContainer;
this.phoneNumberViewContainer =
document.getElementById('phone-number-view-container');
return this.phoneNumberViewContainer;
},
get keypad() {
delete this.keypad;
this.keypad = document.getElementById('keypad');
return this.keypad;
},
get callBar() {
delete this.callBar;
this.callBar =
document.getElementById('keypad-callbar');
return this.callBar;
},
get hideBar() {
delete this.hideBar;
this.hideBar = document.getElementById('keypad-hidebar');
return this.hideBar;
},
get callBarAddContact() {
delete this.callBarAddContact;
this.callBarAddContact =
document.getElementById('keypad-callbar-add-contact');
return this.callBarAddContact;
},
get callBarCallAction() {
delete this.callBarCallAction;
this.callBarCallAction =
document.getElementById('keypad-callbar-call-action');
return this.callBarCallAction;
},
get callBarCancelAction() {
delete this.callBarCancelAction;
this.callBarCancelAction =
document.getElementById('keypad-callbar-cancel');
return this.callBarCancelAction;
},
get deleteButton() {
delete this.deleteButton;
this.deleteButton = document.getElementById('keypad-delete');
return this.deleteButton;
},
get hideBarHangUpAction() {
delete this.hideBarHangUpAction;
this.hideBarHangUpAction =
document.getElementById('keypad-hidebar-hang-up-action-wrapper');
return this.hideBarHangUpAction;
},
get hideBarHideAction() {
delete this.hideBarHideAction;
this.hideBarHideAction =
document.getElementById('keypad-hidebar-hide-keypad-action');
return this.hideBarHideAction;
},
multiSimActionButton: null,
/**
* Initializes the keypad manager, registers all the appropriate event
* handlers and instances the necessary sound infrastructure so that the
* keypad will be fully functional once this method has been called.
*
* @param oncall {Boolean} True if the keypad manager will be used during a
* call and will play sounds on the "telephony" channel. False if it
* will be used outside of a call and should use the "content" channel
* instead. We should be using the "notification" channel but we can't
* due to bug 1092346.
*/
init: function kh_init(oncall) {
this._onCall = !!oncall;
this.phoneNumberView.value = '';
this._phoneNumber = '';
var keyHandler = this.keyHandler.bind(this);
this.keypad.addEventListener('contextmenu', keyHandler);
this.keypad.addEventListener('touchstart', keyHandler, true);
this.keypad.addEventListener('touchmove', keyHandler, true);
this.keypad.addEventListener('touchend', keyHandler, true);
this.keypad.addEventListener('touchcancel', keyHandler, true);
this.deleteButton.addEventListener('touchstart', keyHandler);
this.deleteButton.addEventListener('touchend', keyHandler);
// The keypad add contact bar is only included in the normal version of
// the keypad.
if (this.callBarAddContact) {
this.callBarAddContact.addEventListener('click',
this.addContact.bind(this));
}
// The keypad call bar is only included in the normal version and
// the emergency call version of the keypad.
if (this.callBarCallAction) {
if (typeof MultiSimActionButton !== 'undefined') {
if (navigator.mozMobileConnections &&
navigator.mozMobileConnections.length > 1) {
// Use LazyL10n to load l10n.js. Single SIM devices will be slowed
// down by the cost of loading l10n.js in the startup path if we don't
// do this.
var self = this;
LazyL10n.get(function localized(_) {
self.multiSimActionButton =
new MultiSimActionButton(self.callBarCallAction,
CallHandler.call,
'ril.telephony.defaultServiceId',
self.phoneNumber.bind(self));
});
} else {
this.multiSimActionButton =
new MultiSimActionButton(this.callBarCallAction,
CallHandler.call,
'ril.telephony.defaultServiceId',
this.phoneNumber.bind(this));
}
}
this.callBarCallAction.addEventListener('click',
this.fetchLastCalled.bind(this));
}
// The keypad cancel bar is only the emergency call version of the keypad.
if (this.callBarCancelAction) {
this.callBarCancelAction.addEventListener('click', function() {
window.parent.LockScreen.switchPanel();
});
}
// The keypad hide bar is only included in the on call version of the
// keypad.
if (this.hideBarHideAction) {
this.hideBarHideAction.addEventListener('click',
this.callbarBackAction);
}
if (this.hideBarHangUpAction) {
this.hideBarHangUpAction.addEventListener('click',
this.hangUpCallFromKeypad);
}
/* XXX: We should be using the `notification' channel here but we can't due
* to bug 1092346 and pass `null' instead, forcing the use of the default
* audio channel. */
TonePlayer.init(this._onCall ? 'telephony' : null);
this.render();
LazyLoader.load(['/shared/style/action_menu.css',
'/dialer/js/suggestion_bar.js']);
this._observePreferences();
},
moveCaretToEnd: function hk_util_moveCaretToEnd(el) {
if (typeof el.selectionStart == 'number') {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != 'undefined') {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
},
render: function hk_render(layoutType) {
if (layoutType == 'oncall') {
if (CallsHandler.activeCall) {
var activeCall = CallsHandler.activeCall.call;
this._phoneNumber = activeCall.id.number;
}
this._isKeypadClicked = false;
this.phoneNumberViewContainer.classList.add('keypad-visible');
if (this.callBar) {
this.callBar.classList.add('hide');
}
if (this.hideBar) {
this.hideBar.classList.remove('hide');
}
this.deleteButton.classList.add('hide');
} else {
this.phoneNumberViewContainer.classList.remove('keypad-visible');
if (this.callBar) {
this.callBar.classList.remove('hide');
}
if (this.hideBar) {
this.hideBar.classList.add('hide');
}
this.deleteButton.classList.remove('hide');
}
},
phoneNumber: function hk_phoneNumber() {
return this._phoneNumber;
},
fetchLastCalled: function hk_fetchLastCalled() {
if (this._phoneNumber !== '') {
return;
}
var self = this;
CallLogDBManager.getGroupAtPosition(1, 'lastEntryDate', true, 'dialing',
function hk_ggap_callback(result) {
if (result && (typeof result === 'object') && result.number) {
self.updatePhoneNumber(result.number);
}
}
);
},
addContact: function hk_addContact(event) {
var number = this._phoneNumber;
if (!number) {
return;
}
LazyLoader.load(['/dialer/js/add_contact_menu.js'], function() {
AddContactMenu.show(number);
});
},
callbarBackAction: function hk_callbarBackAction(event) {
CallScreen.hideKeypad();
},
hangUpCallFromKeypad: function hk_hangUpCallFromKeypad(event) {
CallScreen.body.classList.remove('showKeypad');
CallsHandler.end();
},
_lastPressedKey: null,
_dtmfTone: null,
_playDtmfTone: function kh_playDtmfTone(key) {
var serviceId = 0;
if (!this._onCall) {
return;
}
if (CallsHandler.activeCall) {
// Single call
serviceId = CallsHandler.activeCall.call.serviceId;
} else {
// Conference call
serviceId = navigator.mozTelephony.active.calls[0].serviceId;
}
if (this._dtmfTone) {
this._dtmfTone.stop();
this._dtmfTone = null;
}
this._dtmfTone = new DtmfTone(key, this._shortTone, serviceId);
this._dtmfTone.play();
},
_stopDtmfTone: function kh_stopDtmfTone() {
if (!this._dtmfTone) {
return;
}
this._dtmfTone.stop();
this._dtmfTone = null;
},
/**
* Function used to respond to touchstart events over the keypad. Reacts to
* the first key that has been pressed by playing the appropriate tone and
* sets up the necessary timers to react to long presses.
*
* @param {String} key The key that was hit by this touchstart event.
*/
_touchStart: function kh_touchStart(key) {
this._longPress = false;
this._lastPressedKey = key;
if (key != 'delete') {
if (this._keypadSoundIsEnabled) {
// We do not support long press if not on a call
TonePlayer.start(
gTonesFrequencies[key], !this._onCall || this._shortTone);
}
if (this._vibrationEnabled) {
navigator.vibrate(this.kVibrationDuration);
}
this._playDtmfTone(key);
}
// Manage long press
if (((key == '0' || key == '*') && !this._onCall) || key == 'delete') {
this._holdTimer = setTimeout(function(self) {
if (key == 'delete') {
self._phoneNumber = '';
} else {
var index = self._phoneNumber.length - 1;
// Remove last key, this is a long press and we want to add the
// long pressed symbol
if (index >= 0 && self._phoneNumber[index] === key) {
self._phoneNumber = self._phoneNumber.substr(0, index);
}
if (key === '0') {
self._phoneNumber += '+';
} else if (key === '*') {
// ',' DTMF separator can't be the first
if (self._phoneNumber.length > 0) {
self._phoneNumber += ',';
}
}
}
self._longPress = true;
self._updatePhoneNumberView('begin', false);
}, 400, this);
}
// Voicemail long press (only if first digit pressed)
if (key === '1' && this._phoneNumber === '') {
this._holdTimer = setTimeout(function vm_call(self) {
self._longPress = true;
self._callVoicemail();
self._phoneNumber = '';
self._updatePhoneNumberView('begin', false);
}, 400, this);
}
if (key == 'delete') {
this._phoneNumber = this._phoneNumber.slice(0, -1);
} else if (this.phoneNumberViewContainer.classList.
contains('keypad-visible')) {
if (!this._isKeypadClicked) {
this._isKeypadClicked = true;
this._phoneNumber = key;
this.replaceAdditionalContactInfo('');
} else {
this._phoneNumber += key;
}
} else {
this._phoneNumber += key;
}
setTimeout(function(self) {
self._updatePhoneNumberView('begin', false);
}, 0, this);
},
/**
* Function used to respond to touchmove events over the keypad. Stops playing
* the tone associated with the last pressed key and resets it if the target
* goes outside its area.
*
* @param {Object} touch Touch position object for this move.
*/
_touchMove: function kh_touchMove(touch) {
var target = document.elementFromPoint(touch.pageX, touch.pageY);
var key = target.dataset ? target.dataset.value : null;
if (key !== this._lastPressedKey || key === 'delete') {
this._stopDtmfTone();
this._lastPressedKey = null;
}
},
/**
* Function used to respond to touchend events over the keypad. Stops playing
* tones and resets timers associated with the key press.
*
* @param {String} key The key over which the tap finished.
*/
_touchEnd: function kh_touchEnd(key) {
if (key !== 'delete' && key === this._lastPressedKey) {
this._stopDtmfTone();
this._lastPressedKey = null;
}
if (this._keypadSoundIsEnabled) {
TonePlayer.stop();
}
// Handle speed dial numbers
if (this._isSpeedDialNumber(this._phoneNumber)) {
var self = this;
var index = this._phoneNumber.slice(0, -1); // Remove the trailing '#'
this._getSpeedDialNumber(+index).then(
function(number) {
self.updatePhoneNumber(number, 'begin', false);
});
}
// If it was a long press our work is already done
if (this._longPress) {
this._longPress = false;
this._holdTimer = null;
return;
}
if (this._holdTimer) {
clearTimeout(this._holdTimer);
}
},
keyHandler: function kh_keyHandler(event) {
// When long pressing on the voicemail button, if a menu pops up on top of
// the 1 button, a click will go through and target that button unless we
// preventDefault the contextmenu event.
if (event.type == 'contextmenu') {
event.preventDefault();
return;
}
var key = event.target.dataset.value;
// We could receive this event from an element that
// doesn't have the dataset value. Got the last key
// pressed and assing this value to continue with the
// proccess.
if (!key) {
return;
}
// Per certification requirement, we need to send an MMI request to
// get the device's IMEI as soon as the user enters the last # key from
// the "*#06#" MMI string. See bug 857944.
if (key === '#' && this._phoneNumber === '*#06#') {
this.multiSimActionButton.performAction();
event.target.classList.remove('active');
return;
}
// If user input number more 50 digits, app shouldn't accept.
// The limit only applies while not on a call - there is no
// limit while on a call (bug 917630).
if (key != 'delete' && this._phoneNumber.length >= this.kMaxDigits &&
!this._onCall) {
event.target.classList.remove('active');
return;
}
event.stopPropagation();
switch (event.type) {
case 'touchstart':
event.target.classList.add('active');
this._touchStart(key);
break;
case 'touchmove':
this._touchMove(event.touches[0]);
break;
case 'touchend':
case 'touchcancel':
event.target.classList.remove('active');
this._touchEnd(key);
break;
}
},
/**
* Returns true if the number is a speed dial code as described in
* 3GPP TS 22.030 6.6.4. Speed dial codes are in the N(N)(N)# format.
*/
_isSpeedDialNumber: function(number) {
return !!number.match(/^[0-9][0-9]{0,2}\#$/);
},
/**
* Returns the telephony number corresponding to the specified index. Speed
* dial numbers are retrieved from the SIM contacts list and not from the
* regular contacts.
*
* @param {Integer} index The index of the speed dial number.
* @returns {Promise} A promise that resolves to the corresponding number.
*/
_getSpeedDialNumber: function(index) {
var self = this;
var cardIndex;
index--; // Speed dial indexes are 1-based
return new Promise(function(resolve, reject) {
LazyLoader.load(['/shared/js/sim_settings_helper.js'], function() {
SimSettingsHelper.getCardIndexFrom('outgoingCall',
function(defaultCardIndex) {
if (defaultCardIndex == SimSettingsHelper.ALWAYS_ASK_OPTION_VALUE) {
LazyLoader.load(['/shared/js/component_utils.js',
'/shared/elements/gaia_sim_picker/script.js'],
function() {
var simPicker = document.getElementById('sim-picker');
simPicker.getOrPick(defaultCardIndex, null,
function(pickedCardIndex) {
cardIndex = pickedCardIndex;
resolve();
});
});
} else {
cardIndex = defaultCardIndex;
resolve();
}
});
});
}).then(function() {
return self._getSimContactsList(cardIndex).then(
function(simContactsList) {
if ((index >= 0) && (index < simContactsList.length)) {
return simContactsList[index].number;
} else {
return Promise.reject();
}
});
});
},
/**
* Creates an array of contacts populated using the ADN contacts retrieved
* from a SIM card. Every contact will contain only the ID and first
* telephone number and the array will be sorted by ID. This array is then
* suitable to be used to pick speed dial numbers.
*
* @param {Array} contacts An array of mozContact elements.
* @returns {Array} An array of telephone numbers / ID couples sorted by ID.
*/
_createSimContactList: function(contacts) {
var numbers = new Array(contacts.length);
for (var i = 0; i < contacts.length; i++) {
numbers[i] = {
id: contacts[i].id,
number: contacts[i].tel[0].value,
};
}
numbers.sort(function(a, b) {
if (a.id.length == b.id.length) {
return (a.id > b.id) ? 1 : 0;
} else {
return (a.id.length > b.id.length) ? 1 : 0;
}
});
return numbers;
},
/**
* Gets the SIM contacts list for the specified SIM card.
*
* @param {Integer} cardIndex The SIM card index.
* @returns {Promise} A promise that is resolved with the contacts list.
*/
_getSimContactsList: function(cardIndex) {
var self = this;
var canceled = false;
return new Promise(function(resolve, reject) {
LazyLoader.load(['/shared/style/confirm.css',
'/shared/js/confirm.js',
document.getElementById('confirmation-message')],
function() {
var iccId = navigator.mozIccManager.iccIds[cardIndex];
var icc = navigator.mozIccManager.getIccById(iccId);
var req = icc.readContacts('adn');
req.onsuccess = function(event) {
var adnContacts = event.target.result;
var contacts = self._createSimContactList(adnContacts);
if (!canceled) {
ConfirmDialog.hide();
}
resolve(contacts);
};
req.onerror = function(error) {
console.error('Could not retrieve the ADN contacts from SIM card ' +
cardIndex + ', got error ' + error.name);
reject();
};
ConfirmDialog.show('loadingContacts', null, {
title: 'cancel',
callback: function() {
canceled = true;
ConfirmDialog.hide();
reject();
}
});
}
);
});
},
sanitizePhoneNumber: function(number) {
return number.replace(/\s+/g, '');
},
updatePhoneNumber: function kh_updatePhoneNumber(number, ellipsisSide,
forceMaxFontSize) {
number = this.sanitizePhoneNumber(number);
this._phoneNumber = number;
this._updatePhoneNumberView(ellipsisSide, forceMaxFontSize);
},
press: function(value) {
this._playDtmfTone(value);
TonePlayer.start(gTonesFrequencies[value], true);
setTimeout((function nextTick() {
TonePlayer.stop();
this._stopDtmfTone();
}).bind(this));
},
_updatePhoneNumberView: function kh_updatePhoneNumberview(ellipsisSide,
forceMaxFontSize) {
var phoneNumber = this._phoneNumber;
// If there are digits in the phone number, show the delete button
// and enable the add contact button
if (this._onCall) {
this.replacePhoneNumber(phoneNumber, ellipsisSide, forceMaxFontSize);
} else {
var visibility;
if (phoneNumber.length > 0) {
visibility = 'visible';
this.callBarAddContact.removeAttribute('disabled');
} else {
visibility = 'hidden';
this.callBarAddContact.setAttribute('disabled', 'disabled');
}
this.deleteButton.style.visibility = visibility;
this.phoneNumberView.value = phoneNumber;
this.moveCaretToEnd(this.phoneNumberView);
FontSizeManager.adaptToSpace(
FontSizeManager.DIAL_PAD, this.phoneNumberView, forceMaxFontSize,
ellipsisSide);
}
if (this.onValueChanged) {
this.onValueChanged(this._phoneNumber);
}
},
replacePhoneNumber:
function kh_replacePhoneNumber(phoneNumber, ellipsisSide,
forceMaxFontSize) {
if (this._onCall && CallsHandler.activeCall) {
CallsHandler.activeCall.
replacePhoneNumber(phoneNumber, ellipsisSide, forceMaxFontSize);
}
},
restorePhoneNumber:
function kh_restorePhoneNumber() {
if (this._onCall && CallsHandler.activeCall) {
CallsHandler.activeCall.restorePhoneNumber();
}
},
replaceAdditionalContactInfo:
function kh_replaceAdditionalContactInfo(additionalContactInfo) {
var call = CallsHandler.activeCall;
if (this._onCall && call) {
call.replaceAdditionalContactInfo(additionalContactInfo);
}
},
restoreAdditionalContactInfo: function kh_restoreAdditionalContactInfo() {
if (this._onCall && CallsHandler.activeCall) {
CallsHandler.activeCall.restoreAdditionalContactInfo();
}
},
_callVoicemail: function() {
if (navigator.mozIccManager.iccIds.length <= 1) {
this._callVoicemailForSim(0);
return;
}
var self = this;
var key = 'ril.voicemail.defaultServiceId';
var req = navigator.mozSettings.createLock().get(key);
req.onsuccess = function() {
LazyLoader.load(['/shared/js/component_utils.js',
'/shared/elements/gaia_sim_picker/script.js'],
function() {
LazyL10n.get(function(_) {
var simPicker = document.getElementById('sim-picker');
simPicker.getOrPick(req.result[key], _('voiceMail'),
self._callVoicemailForSim.bind(self));
});
});
};
},
_callVoicemailForSim: function(cardIndex) {
var settings = navigator.mozSettings;
if (!settings) {
return;
}
var transaction = settings.createLock();
var request = transaction.get('ril.iccInfo.mbdn');
request.onsuccess = (function() {
var numbers = request.result['ril.iccInfo.mbdn'];
var number;
if (typeof numbers == 'string') {
number = numbers;
} else {
number = numbers && numbers[cardIndex];
}
var voicemail = navigator.mozVoicemail;
if (!number && voicemail) {
number = voicemail.getNumber(cardIndex);
}
if (number) {
CallHandler.call(number, cardIndex);
} else {
this._showNoVoicemailDialog();
}
}).bind(this);
request.onerror = function() {};
},
_showNoVoicemailDialog: function hk_showNoVoicemailDialog() {
var voicemailDialog = {
title: 'voicemailNoNumberTitle',
text: 'voicemailNoNumberText',
confirm: {
title: 'voicemailNoNumberSettings',
recommend: true,
callback: this.showVoicemailSettings
},
cancel: {
title: 'voicemailNoNumberCancel',
callback: this._hideNoVoicemailDialog
}
};
LazyLoader.load(['/shared/js/custom_dialog.js'], function() {
CustomDialog.show(
voicemailDialog.title, voicemailDialog.text,
voicemailDialog.cancel, voicemailDialog.confirm);
});
},
_hideNoVoicemailDialog: function kh_hideNoVoicemailDialog() {
CustomDialog.hide();
},
showVoicemailSettings: function kh_showVoicemailSettings() {
var activity = new window.MozActivity({
name: 'configure',
data: {
target: 'device',
section: 'call'
}
});
activity.onerror = function() {
console.warn('Configure activity error:', activity.error.name);
};
},
_observePreferences: function kh_observePreferences() {
var self = this;
LazyLoader.load('/shared/js/settings_listener.js', function() {
SettingsListener.observe('phone.ring.keypad', false, function(value) {
self._keypadSoundIsEnabled = !!value;
});
SettingsListener.observe('phone.dtmf.type', false, function(value) {
self._shortTone = (value === 'short');
});
SettingsListener.observe('keyboard.vibration', false, function(value) {
self._vibrationEnabled = !!value;
});
});
}
};