2 * Copyright (c) 2012, Intel Corporation.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 var phoneNumberTextTemplate = {"font" : "bold 40pt Arial", "lineWidth" : 2.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "center", "textBaseline" : "middle",
11 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 32, "shadowColor" : "rgba(0,100,150, 0.6)"};
13 var incomingTextTemplate = {"font" : "bold 80pt Arial", "fillStyle" : "white", "textAlign" : "center", "textBaseline" : "middle",
14 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 0, "shadowColor" : "rgba(0, 0, 0, 1.0)"};
16 var callTimeTextTemplate = {"font" : "bold 30pt Arial", "fillStyle" : "white", "textAlign" : "left", "textBaseline" : "top",
17 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 0, "shadowColor" : "rgba(0, 0, 0, 1.0)"};
23 function updateNumber(number)
25 currentNumber = number;
27 if (number.length === 10)
29 number = number.slice(0,3) + '-' + number.slice(3,6) + '-' + number.slice(6,10);
32 callPage.getObj("displayedNumber").text = number;
35 function startTimer(timeText)
37 var today = new Date();
38 startTime = today.getTime();
40 timerInterval = setInterval( function() {
41 var today = new Date();
42 var currentTime = today.getTime();
43 callTime = Math.floor((currentTime - startTime) / 1000);
45 var hours = Math.floor(callTime / 3600);
46 callTime -= hours * 3600;
47 var mins = Math.floor(callTime / 60);
48 var secs = callTime - (mins * 60) < 10 ? "0" + (callTime - (mins * 60)).toString() : (callTime - (mins * 60)).toString();
50 hours = hours > 10 ? hours : "0" + hours.toString();
51 mins = mins > 10 ? mins : "0" + mins.toString();
53 callPage.getObj("callTime").text = hours + ":" + mins + ":" + secs;
60 clearInterval(timerInterval);
63 function initButtons(initState)
65 var incomingBar = callPage.getObj("incomingBar");
66 if (initState == "dialing" || initState == "activeCall")
67 var buttonWidth = screenWidth * 0.6;
69 var buttonWidth = (screenWidth * 0.8) / 2;
71 var buttonHeight = screenHeight * 0.15;
75 if (initState == "dialing" || initState == "activeCall")
77 endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.2,
78 "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );
80 callPage.getObj("acceptCallButton").visible = false;
84 acceptCallButton = callPage.addObject(buttonCtx, "button", {"name" : "acceptCallButton", "image": images.incomingAcceptButton, "icon": images.callIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.1,
85 "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight, "visible" : true} );
87 endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100,
88 "xLoc" : acceptCallButton.xLoc + acceptCallButton.width + 20, "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );
90 acceptCallButton.onClick = function(){
92 console.log("Accepting call")
95 console.log("Failed to accept call");
98 currentState = "activeCall";
100 initButtons("activeCall");
107 endCallButton.onClick = function(){
111 console.log("Attempting to hangup a non-active call");
113 currentState = "idle";
114 switchMenu(mainPage);
120 function initCallPage(initState)
123 var incomingBar = callPage.addObject(mainCtx, "shape", {"name" : "incomingBar", "xLoc" : -20, "yLoc" : screenHeight * 0.2, "width" : screenWidth + 40,
124 "height" : screenHeight * 0.6, "fillStyle" : "#51504F", "strokeStyle" : "#B3BF3C", "lineWidth" : 5});
126 var displayedNumber = callPage.addObject(mainCtx, "text", {"name" : "displayedNumber", "xLoc" : screenWidth / 2, "yLoc" : incomingBar.yLoc + incomingBar.height * 0.4, "width" : screenWidth * 0.75,
127 "height" : screenHeight * 0.4, "text" : currentNumber, "template" : incomingTextTemplate});
129 var clockIcon = callPage.addObject(mainCtx, "image", {"name" : "clock", "image": images.clockIcon, "xLoc" : screenWidth * 0.7,
130 "yLoc" : incomingBar.yLoc + 30, "width" : 50, "height" : 50} );
132 var callTime = callPage.addObject(mainCtx, "text", {"name" : "callTime", "xLoc" : clockIcon.xLoc + clockIcon.width + 10, "yLoc" : clockIcon.yLoc, "width" : screenWidth * 0.2,
133 "height" : 100, "text" : "00:00:00", "template" : callTimeTextTemplate});
135 initButtons(initState);