Updating manifest file to specify Murphy role - TC-1731
[profile/ivi/Modello_Phone.git] / js / main.js
1 /*global disconnectCall, Bootstrap, Carousel, ContactsLibrary, getAppByID, disconnectCall, Configuration, Speech, Phone, changeCssBgImageColor, ThemeKeyColorSelected */
2
3 /**
4  * This application provides voice call from paired Bluetooth phone. Application uses following APIs:
5  *
6  * * {{#crossLink "Phone"}}{{/crossLink}} library
7  * * [tizen.bt]() as replacement of [tizen.bluetooth](https://developer.tizen.org/dev-guide/2.2.0/org.tizen.web.device.apireference/tizen/bluetooth.html) API due to
8  *   conficts in underlying framework
9  *
10  * Application supports multiple connected devices, however only one of the devices can be selected at the time.
11  * Selection is done from {{#crossLink "Bluetooth"}}{{/crossLink}} UI. In case that phone has active call additional {{#crossLink "Carousel"}}{{/crossLink}}
12  * element is replaced by {{#crossLink "CallDuration"}}{{/crossLink}} element.
13  *
14  * Application allows following operations:
15  *
16  * * {{#crossLink "Phone/acceptCall:method"}}Place call{{/crossLink}}
17  * * Handles incoming calls passed from {{#crossLink "IncomingCall"}}{{/crossLink}} widget
18  * * Display {{#crossLink "Carousel"}}call history{{/crossLink}}
19  * * Display {{#crossLink "ContactsLibrary"}}contact list{{/crossLink}}
20  * * Mute/unmute call - not working due to [TIVI-2448](https://bugs.tizen.org/jira/browse/TIVI-2448)
21  *
22  * Additionaly application can be controlled using speech recognition via {{#crossLink "Speech"}}{{/crossLink}} component.
23  *
24  * Hover and click on elements in images below to navigate to components of Phone application.
25  *
26  * <img id="Image-Maps_1201312180420487" src="../assets/img/phone.png" usemap="#Image-Maps_1201312180420487" border="0" width="649" height="1152" alt="" />
27  *   <map id="_Image-Maps_1201312180420487" name="Image-Maps_1201312180420487">
28  *     <area shape="rect" coords="0,0,573,78" href="../classes/TopBarIcons.html" alt="top bar icons" title="Top bar icons" />
29  *     <area shape="rect" coords="0,77,644,132" href="../classes/Clock.html" alt="clock" title="Clock"    />
30  *     <area shape="rect" coords="0,994,644,1147" href="../classes/BottomPanel.html" alt="bottom panel" title="Bottom panel" />
31  *     <area shape="rect" coords="573,1,644,76" href="../modules/Settings.html" alt="Settings" title="Settings"    />
32  *     <area shape="rect" coords="552,136,646,181" href="../classes/ContactsLibrary.html" alt="Contacts library" title="Contacts library" />
33  *     <area shape="rect" coords="95,345,164,491" href="../classes/Phone.html#method_acceptCall" alt="Call button" title="Call button" />
34  *     <area shape="rect" coords="1,668,644,984" href="../classes/Carousel.html" alt="" title="History carousel" />
35  *     <area shape="rect" coords="171,181,471,635" alt=""   href="../classes/keyboard.html" alt="Keyboard input" title="Keyboard input"    >
36  *   </map>
37  *
38  * @module PhoneApplication
39  * @main PhoneApplication
40  * @class Phone
41  */
42
43 /**
44  * Holds object of input for dialing phone number.
45  *
46  * @property telInput {Object}
47  */
48 var telInput;
49 /**
50  * Instance of class Bootstrap, this class provides unified way to boot up the HTML applications by loading shared components in proper order.
51  * * {{#crossLink "Bootstrap"}}{{/crossLink}}
52  *
53  * @property bootstrap {Object}
54  */
55 var bootstrap;
56
57 /**
58 * Instance of class Carousel, this class provides methods to operate with history carousel.
59 * * {{#crossLink "Carousel"}}{{/crossLink}}
60 *
61 * @property callHistoryCarousel {Object}
62 */
63 var callHistoryCarousel = null;
64
65 /**
66 * This property holds information about accept Phone call from Other widgets.
67 * If is true, phone call came from another widget.
68 * @property acceptPhoneCallFromOtherWidget {Boolean}
69 */
70 var acceptPhoneCallFromOtherWidget = false;
71
72 /**
73  * Class handling user input from keyboard
74  *
75  * @class keyboard
76  * @static
77  */
78 var keyboard = {
79     /**
80      * property holding Interval within which next click on the same key is considered as rotating associated characters with the given key.
81      *
82      * @property clickInterval {int}
83      */
84     clickInterval: 1000,
85
86     /**
87      * property holding info about last pressed key
88      *
89      * @property pressedKey {string}
90      */
91     pressedKey: "-1",
92
93     /**
94      * Array of input object holding info about main key character, all associated characters with the given key and index of currently used key
95      *
96      * @property inputs {Array of Object}
97      */
98     inputs: [{
99         key: "1",
100         values: ["1"],
101         index: 0
102     }, {
103         key: "2",
104         values: ["2", "A", "B", "C"],
105         index: 0
106     }, {
107         key: "3",
108         values: ["3", "D", "E", "F"],
109         index: 0
110     }, {
111         key: "4",
112         values: ["4", "G", "H", "I"],
113         index: 0
114     }, {
115         key: "5",
116         values: ["5", "J", "K", "L"],
117         index: 0
118     }, {
119         key: "6",
120         values: ["6", "M", "N", "O"],
121         index: 0
122     }, {
123         key: "7",
124         values: ["7", "P", "Q", "R", "S"],
125         index: 0
126     }, {
127         key: "8",
128         values: ["8", "T", "U", "V"],
129         index: 0
130     }, {
131         key: "9",
132         values: ["9", "W", "X", "Y", "Z"],
133         index: 0
134     }, {
135         key: "*",
136         values: ["*"],
137         index: 0
138     }, {
139         key: "0",
140         values: ["0", "+"],
141         index: 0
142     }, {
143         key: "#",
144         values: ["#"],
145         index: 0
146     }],
147
148     /**
149      * property holding time of clickedInterval started
150      *
151      * @property startedTime {Date}
152      */
153     startedTime: null,
154
155     /**
156      * property holding input object associated with last pressed key
157      *
158      * @property selectedInput {Object}
159      */
160     selectedInput: null,
161
162     /**
163      * function starting clickInterval
164      *
165      * @method startTimer
166      */
167     startTimer: function() {
168         "use strict";
169         keyboard.startedTime = new Date();
170     },
171
172     /**
173      * function testing if clickInterval expired
174      *
175      * @method intervalExpired
176      * @param currTime {Date}
177      */
178     intervalExpired: function(currTime) {
179         "use strict";
180         if (currTime - keyboard.startedTime > keyboard.clickInterval) {
181             keyboard.resetIndices();
182             return true;
183         }
184         return false;
185     },
186
187     /**
188      * function reseting indices for all input objects to 0
189      *
190      * @method resetIndices
191      */
192     resetIndices: function() {
193         "use strict";
194         for (var i in keyboard.inputs) {
195             if (keyboard.inputs.hasOwnProperty(i)) {
196                 keyboard.inputs[i].index = 0;
197             }
198         }
199     },
200
201     /**
202      * function cycling associated input characters within clickInterval
203      *
204      * @method nextKey
205      */
206     nextKey: function() {
207         "use strict";
208         for (var i in keyboard.inputs) {
209             if (keyboard.pressedKey === keyboard.inputs[i].key) {
210                 if (keyboard.inputs[i].values.length > 1) {
211                     if (keyboard.inputs[i].index < keyboard.inputs[i].values.length - 1) {
212                         keyboard.inputs[i].index += 1;
213                     } else {
214                         keyboard.inputs[i].index = 0;
215                     }
216                 } else {
217                     keyboard.inputs[i].index = 0;
218                 }
219                 keyboard.selectedInput = keyboard.inputs[i];
220                 return keyboard.inputs[i].values[keyboard.inputs[i].index];
221             }
222         }
223         return keyboard.pressedKey;
224     },
225
226     /**
227      * function setting selected input object based on last pressed key
228      *
229      * @method selectInput
230      */
231     selectInput: function() {
232         "use strict";
233         for (var i in keyboard.inputs) {
234             if (keyboard.pressedKey === keyboard.inputs[i].key) {
235                 keyboard.selectedInput = keyboard.inputs[i];
236             }
237         }
238     }
239 };
240
241 /**
242  * Holds status of calling panel initialization.
243  *
244  * @property callingPanelInitialized {Boolean}  if is true, calling panel is initialized
245  * @default false
246  */
247 var callingPanelInitialized = false;
248
249 /**
250  * Class which provides initialize call info.
251  *
252  * @method initializeCallInfo
253  * @param contact {Object} Contact object.
254  * @for Phone
255  */
256 function initializeCallInfo(contact) {
257     "use strict";
258     var callNumber;
259     console.log(contact);
260     if ( !! contact) {
261
262         if ( !! contact.name) {
263             var nameStr;
264             if (contact.name.displayName) {
265                 nameStr = contact.name.displayName;
266             } else {
267                 nameStr = !! contact.name.firstName ? contact.name.firstName : "";
268                 nameStr += !! contact.name.lastName ? " " + contact.name.lastName : "";
269             }
270             $("#callName").html(nameStr.trim());
271         } else {
272             $("#callName").html("Unknown");
273         }
274
275         if ( !! contact.phoneNumbers && contact.phoneNumbers.length) {
276             callNumber = !! contact.phoneNumbers[0].number ? contact.phoneNumbers[0].number : "";
277             $("#callNumber").html(callNumber);
278         } else {
279             $("#callNumber").html("Unknown");
280         }
281
282         if ( !! contact.photoURI) {
283             $("#callPhoto").attr("src", contact.photoURI);
284         }
285     } else {
286         $("#callName").html("Unknown");
287         $("#callNumber").html("Unknown");
288     }
289
290     if (!callingPanelInitialized) {
291         $(".noVolumeSlider").noUiSlider({
292             range: [0, 100],
293             step: 1,
294             start: 50,
295             handles: 1,
296             connect: "lower",
297             orientation: "horizontal",
298             slide: function() {
299                 var VolumeSlider = parseInt($(".noVolumeSlider").val(), 10);
300                 console.log("noVolumeSlider" + VolumeSlider);
301             }
302         });
303         callingPanelInitialized = true;
304     }
305
306     if ($("#callButton").hasClass("callingFalse")) {
307         $("#callButton").removeClass("callingFalse");
308         $("#callButton").addClass("callingTrue");
309     }
310 }
311
312 /**
313  * Class which provides methods to operate with call duration. Component show information about current call (call number or call contact, time duration of call).
314  *
315  * @class CallDuration
316  * @static
317  */
318 var CallDuration = {
319     /**
320      * Holds value of seconds.
321      *
322      * @property sec {Integer}
323      */
324     sec: 0,
325     /**
326      * Holds value of minutes.
327      *
328      * @property min {Integer}
329      */
330     min: 0,
331     /**
332      * Holds value of hours.
333      *
334      * @property hour {Integer}
335      */
336     hour: 0,
337     /**
338      * Holds object of timer.
339      *
340      * @property timeout {Object}
341      */
342     timeout: null,
343     /**
344      * Method provides initialization of call timers.
345      *
346      * @method initialize
347      */
348     startWatch: function() {
349         "use strict";
350         var self = this;
351         if (!this.timeout) {
352             this.timeout = window.setInterval(function() {
353                 self.stopwatch();
354             }, 1000);
355         } else {
356             this.resetIt();
357             this.timeout = window.setInterval(function() {
358                 self.stopwatch();
359             }, 1000);
360         }
361     },
362
363     /**
364      * Method provides reset call timers.
365      *
366      * @method resetIt
367      */
368     resetIt: function() {
369         "use strict";
370         CallDuration.sec = 0;
371         CallDuration.min = 0;
372         CallDuration.hour = 0;
373         window.clearTimeout(CallDuration.timeout);
374         var activeCall = tizen.phone.activeCall();
375         var callStatus = activeCall.state.toLowerCase();
376         if (callStatus === "DIALING".toLowerCase()) {
377             $("#callDuration").html("DIALING");
378         } else if (callStatus === "DISCONNECTED".toLowerCase()) {
379             $("#callDuration").html("ENDED");
380         } else {
381             $("#callDuration").html(
382                 ((CallDuration.min <= 9) ? "0" + CallDuration.min : CallDuration.min) + ":" + ((CallDuration.sec <= 9) ? "0" + CallDuration.sec : CallDuration.sec));
383         }
384
385     },
386     /**
387      * Method provides call stop watch.
388      *
389      * @method stopwatch
390      */
391     stopwatch: function() {
392         "use strict";
393
394         var activeCall = tizen.phone.activeCall();
395         var callStatus = activeCall.state.toLowerCase();
396         if (callStatus === "DIALING".toLowerCase()) {
397             $("#callDuration").html("DIALING");
398         } else if (callStatus === "DISCONNECTED".toLowerCase()) {
399             $("#callDuration").html("ENDED");
400
401         } else {
402             CallDuration.sec++;
403             if (CallDuration.sec === 60) {
404                 CallDuration.sec = 0;
405                 CallDuration.min++;
406             }
407
408             if (CallDuration.min === 60) {
409                 CallDuration.min = 0;
410                 CallDuration.hour++;
411             }
412             $("#callDuration").html(
413                 ((CallDuration.min <= 9) ? "0" + CallDuration.min : CallDuration.min) + ":" + ((CallDuration.sec <= 9) ? "0" + CallDuration.sec : CallDuration.sec));
414         }
415     }
416 };
417
418 /**
419 * This property holds information about mute of call. If is true, phone call is mute.
420 *
421 * @property VolumeMuteStatus
422 * @default false
423 */
424 var VolumeMuteStatus = false;
425
426 /**
427  * Class provides a muting of a call
428  *
429  * @method muteCall
430  * @for Phone
431  */
432 function muteCall() {
433     "use strict";
434     VolumeMuteStatus = VolumeMuteStatus ? false : true;
435
436     // Not working due to TIVI-2448
437     if (tizen.phone) {
438         //tizen.phone.muteCall(VolumeMuteStatus);
439     }
440     if (VolumeMuteStatus) {
441         changeCssBgImageColor(".muteButton", ThemeKeyColorSelected);
442         $(".muteButton").addClass("fontColorSelected");
443     } else {
444         changeCssBgImageColor(".muteButton", "#FFFFFF");
445         $(".muteButton").removeClass("fontColorSelected");
446     }
447 }
448
449 /**
450  * Class which provides methods to call contact.
451  *
452  * @method acceptCall
453  * @param contact {Object} Contact object.
454  * @for Phone
455  */
456 function acceptCall(contact) {
457     "use strict";
458
459     ContactsLibrary.hide();
460     if ($("#settingsTabs").tabs) {
461         $("#settingsTabs").tabs("hidePage");
462     }
463     $("#callBox").removeClass("callBoxHidden");
464     $("#callBox").addClass("callBoxShow");
465     $('#contactsCarouselBox').removeClass("contactsCarouselBoxShow");
466     $('#contactsCarouselBox').addClass("contactsCarouselBoxHide");
467     if (tizen.phone) {
468         CallDuration.resetIt();
469
470         initializeCallInfo(contact);
471         var activeCall = tizen.phone.activeCall();
472         var callStatus = activeCall.state.toLowerCase();
473         if (callStatus !== "ACTIVE".toLowerCase() && callStatus !== "DIALING".toLowerCase()) {
474
475             if (callStatus === "INCOMING".toLowerCase()) {
476                 tizen.phone.answerCall(function(result) {
477                     console.log(result.message);
478                 });
479
480                 CallDuration.startWatch();
481             } else if (callStatus === "DISCONNECTED".toLowerCase()) {
482
483                 var callNumber = contact.phoneNumbers[0] && contact.phoneNumbers[0].number ? contact.phoneNumbers[0].number : "";
484                 tizen.phone.invokeCall(callNumber, function(result) {
485                     console.log(result.message);
486                 });
487
488             }
489
490         } else if (callStatus === "ACTIVE".toLowerCase()) {
491             CallDuration.startWatch();
492         }
493     }
494 }
495
496 /**
497  * Class which provides disconnect call.
498  *
499  * @method disconnectCall
500  * @for Phone
501  */
502 function disconnectCall() {
503     "use strict";
504     $("#callButton").removeClass("callingTrue");
505     $("#callButton").addClass("callingFalse");
506     if (acceptPhoneCallFromOtherWidget !== true) {
507         $("#callBox").removeClass("callBoxShow");
508         $("#callBox").addClass("callBoxHidden");
509         $('#contactsCarouselBox').removeClass("contactsCarouselBoxHide");
510         $('#contactsCarouselBox').addClass("contactsCarouselBoxShow");
511     }
512     CallDuration.resetIt();
513     if (tizen.phone) {
514         tizen.phone.hangupCall(function(result) {
515             console.log(result.message);
516         });
517     }
518     $("#inputPhoneNumber").val('');
519 }
520
521 $(document).ready(
522     function() {
523         "use strict";
524         setTimeout(function() {
525             /* initialize phone widget by remote device status */
526             if (tizen.phone) {
527                 tizen.phone.getSelectedRemoteDevice(function(selectedRemoteDevice){
528                 if (selectedRemoteDevice !== "") {
529                     $("#noPairedDevice").hide();
530                     $("#loadingHistorySpinnerWrapper").show();
531                 } else {
532                     $("#noPairedDevice").show();
533                 }
534                 });
535                 /* initialize phone widget by active call status */
536                 var activeCall = tizen.phone.activeCall();
537                 var callStatus = activeCall.state.toLowerCase();
538                 if (callStatus === "INCOMING".toLowerCase() || callStatus === "DIALING".toLowerCase() || callStatus === "ACTIVE".toLowerCase()) {
539                     var contact;
540                     if (tizen.phone.callState) {
541                         contact = activeCall.contact;
542                     }
543                     acceptPhoneCallFromOtherWidget = true;
544                     acceptCall(contact);
545                 } else if (callStatus === "DISCONNECTED".toLowerCase()) {
546                     disconnectCall();
547                 }
548             }
549             /* start keyboard timer */
550             keyboard.startTimer();
551             /* initialize bootstrap */
552             bootstrap = new Bootstrap(function(status) {
553                 telInput = $("#inputPhoneNumber");
554                 $("#clockElement").ClockPlugin('init', 5);
555                 $("#clockElement").ClockPlugin('startTimer');
556                 $("#topBarIcons").topBarIconsPlugin('init', 'phone');
557                 $('#bottomPanel').bottomPanel('init');
558                 if (!callHistoryCarousel) {
559
560                     callHistoryCarousel = new Carousel();
561                 }
562
563                 if (typeof Phone !== "undefined") {
564                     /* add listener to selected remote device */
565                     tizen.phone.addRemoteDeviceSelectedListener(function(returnID) {
566                         if ((!!returnID && !!returnID.error) || (!!returnID && !!returnID.value && returnID.value === "")) {
567                             $("#loadingHistorySpinnerWrapper").hide();
568                             $(".caroufredsel_wrapper").hide();
569                             $("#noPairedDevice").show();
570                         } else {
571                             $("#noPairedDevice").hide();
572                             $(".caroufredsel_wrapper").show();
573                         }
574                     });
575                     /* initialize contacts and call history, if not accept phone call from another widget */
576                     if (acceptPhoneCallFromOtherWidget !== true) {
577                         window.setTimeout(function() {
578                             Phone.loadContacts(function(err) {
579                                 if (!err) {
580                                     ContactsLibrary.init();
581                                     $("#loadingHistorySpinnerWrapper").show();
582                                     Phone.loadCallHistory(function(err) {
583                                         $("#loadingHistorySpinnerWrapper").hide();
584                                         if (!err) {
585                                             callHistoryCarousel.loadCallHistory(Phone.callHistory(), 0);
586                                         }
587                                     });
588                                 }
589                             });
590
591                         }, 2000);
592                     }
593                     /* add listener to change contacts list  */
594                     tizen.phone.addContactsChangedListener(function() {
595                         if (acceptPhoneCallFromOtherWidget !== true) {
596                             window.setTimeout(function() {
597                                 Phone.loadContacts(function(err) {
598                                     if (!err) {
599                                         ContactsLibrary.init();
600                                     }
601                                 });
602                             }, 1000);
603                         }
604                     });
605                     /* add listener to change call history  */
606                     tizen.phone.addCallHistoryChangedListener(function() {
607                         $("#loadingHistorySpinnerWrapper").show();
608                         if (acceptPhoneCallFromOtherWidget !== true) {
609                             window.setTimeout(function() {
610                                 Phone.loadCallHistory(function(err) {
611                                     $("#loadingHistorySpinnerWrapper").hide();
612                                     if (!err) {
613                                         callHistoryCarousel.loadCallHistory(Phone.callHistory(), 0);
614
615                                     }
616                                 });
617                             }, 1000);
618                         }
619
620                     });
621                 }
622
623                 $("#contactsLibraryButton").bind('click', function() {
624
625                     ContactsLibrary.show();
626
627                 });
628
629                 $(".numbersBox").delegate("#numberButton", "click", function() {
630                     var pressTime = new Date(),
631                         number, oneCharPX = 32;
632                     if (keyboard.intervalExpired(pressTime)) {
633                         number = telInput.attr("value") + $(this).data("id");
634                         telInput.attr("value", number);
635                         $('#inputPhoneNumber').scrollLeft(number.length * oneCharPX);
636                         keyboard.pressedKey = $(this).data("id").toString();
637
638                     } else {
639                         if (keyboard.pressedKey === "-1" || keyboard.pressedKey !== $(this).data("id").toString()) {
640                             number = telInput.attr("value") + $(this).data("id");
641                             telInput.attr("value", number);
642                             $('#inputPhoneNumber').scrollLeft(number.length * oneCharPX);
643                             keyboard.pressedKey = $(this).data("id").toString();
644                         } else {
645                             var phoneNumText = telInput.attr("value");
646                             if (keyboard.pressedKey === $(this).data("id").toString() && keyboard.selectedInput !== null && keyboard.selectedInput.values.length === 1) {
647                                 number = telInput.attr("value") + $(this).data("id");
648                                 telInput.attr("value", number);
649                                 $('#inputPhoneNumber').scrollLeft(number.length * oneCharPX);
650                             } else {
651                                 var numToUpdate = phoneNumText.slice(0, phoneNumText.length - 1);
652                                 numToUpdate += keyboard.nextKey();
653                                 telInput.attr("value", numToUpdate);
654
655                             }
656                         }
657                     }
658                     keyboard.selectInput();
659                     keyboard.startTimer();
660                     return false;
661                 });
662
663                 $(".inputPhoneNumberBox").delegate("#deleteButton", "click", function() {
664                     var number = telInput.attr("value");
665                     number = number.slice(0, number.length - 1);
666                     telInput.attr("value", number);
667                     return false;
668                 });
669
670                 $('#callButton').bind('click', function() {
671                     var phoneNumber = $("#inputPhoneNumber").val();
672                     if ($("#callBox").hasClass("callBoxShow")) {
673                         disconnectCall();
674                     } else if (phoneNumber !== "") {
675                         var contact = Phone.getContactByPhoneNumber(phoneNumber);
676                         if (contact === null) {
677
678                             contact = {
679                                 phoneNumbers: [{
680                                     number: phoneNumber
681                                 }]
682                             };
683
684                         }
685                         acceptCall(contact);
686                     }
687                 });
688                 $('.muteButton').bind('click', function() {
689                     muteCall();
690                 });
691                 if (tizen.phone) {
692                     /* add listener to change call history entry, because if call is ended tizen.phone give back only last history object */
693                     tizen.phone.addCallHistoryEntryAddedListener(function(contact) {
694                         if (acceptPhoneCallFromOtherWidget !== true) {
695
696
697                             var tmpCallHistory = Phone.callHistory();
698                             var tmpContact = [];
699                             tmpContact.push(contact);
700                             tmpContact = Phone.formatCallHistory(tmpContact);
701                             tmpCallHistory.unshift(tmpContact[0]);
702                             Phone.callHistory(tmpCallHistory);
703
704                             callHistoryCarousel.addCallHistory(Phone.callHistory(), 0);
705                         }
706                     });
707                     /* add listener to change call state */
708                     tizen.phone.addCallChangedListener(function(result) {
709                         var contact;
710                         var activeCall = tizen.phone.activeCall();
711                         if ( !! result.contact.name) {
712                             contact = result.contact;
713                         } else {
714                             contact = {
715                                 phoneNumbers: [{
716                                     /* jshint camelcase: false */
717                                     number: activeCall.line_id
718                                     /* jshint camelcase: true */
719                                 }]
720
721                             };
722                         }
723
724                         console.log("result.state " + result.state);
725
726                         switch (result.state.toLowerCase()) {
727                             case "DISCONNECTED".toLowerCase():
728
729                                 disconnectCall(contact);
730
731                                 if (acceptPhoneCallFromOtherWidget === true) {
732
733                                     window.setTimeout(function() {
734                                         if (typeof (tizen.application.getCurrentApplication) !== "undefined") {
735                                             tizen.application.getCurrentApplication().exit();
736                                         }
737                                     }, 1000);
738                                 }
739
740                                 Configuration.set("acceptedCall", "false");
741
742                                 break;
743                             case "ACTIVE".toLowerCase():
744                                 if (Configuration._values.acceptedCall !== "true") {
745                                     /* global self */
746                                     self.incomingCall.acceptIncommingCall();
747                                     CallDuration.startWatch();
748                                     console.log("phone active");
749                                     Configuration.set("acceptedCall", "true");
750                                 }
751                                 break;
752                             case "DIALING".toLowerCase():
753                                 acceptCall(contact);
754                                 break;
755                         }
756                     });
757                 }
758
759             if (typeof(Speech) !== 'undefined') {
760                 /* add listener to voice recognition */
761                 Speech.addVoiceRecognitionListener({
762                     oncall: function() {
763                         if (ContactsLibrary.currentSelectedContact !== "" && $('#library').library("isVisible")) {
764                             acceptCall(ContactsLibrary.currentSelectedContact);
765                         }
766                     }
767                 });
768             } else {
769                 console.warn("Speech API is not available.");
770             }
771
772             });
773         }, 0);
774
775     });
776
777 /**
778  * Class which provides call contact carousel.
779  *
780  * @method callContactCarousel
781  * @param contact {Object} Contact object.
782  * @for Phone
783  *
784  */
785
786 function callContactCarousel(contact) {
787     "use strict";
788
789     acceptCall(contact);
790 }
791
792 /**
793  * Class which provides call by contact ID.
794  *
795  * @method callContactById
796  * @param contactId {String} Contact id.
797  * @for Phone
798  */
799 function callContactById(contactId) {
800     "use strict";
801     $("#contactDetailMobile").addClass("fontColorSelected ");
802     if (contactId !== "" && typeof contactId !== undefined) {
803
804         var contactObject = Phone.getContactById(contactId);
805         if ( !! contactObject) {
806             window.setTimeout(function() {
807                 acceptCall(contactObject);
808                 $("#contactDetailMobile").removeClass("fontColorSelected ");
809             }, 500);
810         } else {
811             console.log("contact not found");
812             $("#contactDetailMobile").removeClass("fontColorSelected ");
813         }
814     }
815 }