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 mainCanvas, bgCanvas, buttonCanvas;
11 var mainCtx, bgCtx, buttonCtx, mouseCtx;
17 var mouseDrag = false, mouseDown = false;
18 var prevXMouse, prevYMouse;
19 var clicksDisabled = true;
21 var mainPageTitleTemplate = {"font" : "bold 40pt Arial", "lineWidth" : 2.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "center",
22 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 32, "shadowColor" : "rgba(0, 0, 110, 1.0)"};
24 var mainPageButtonTemplate = {"font" : "bold 20pt Arial", "lineWidth" : 1.5, "strokeStyle" : "white", "textAlign" : "center", "textBaseline" : "middle",
25 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 10, "shadowColor" : "black"};
27 var buttonTextTemplate = {"font" : "bold 30pt Arial", "fillStyle" : "white", "textAlign" : "center", "textBaseline" : "middle",
28 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 12, "shadowColor" : "rgba(50, 50, 50, 1.0)"};
30 var mainPage = new MenuObject({"name" : "main", "xLoc" : 0, "yLoc" : 0, "visible" : true});
31 var callPage = new MenuObject({"name" : "incomingCall", "xLoc" : 0, "yLoc" : 0, "visible" : true});
33 var currentPage = mainPage;
34 var currentNumber = " ";
35 var currentState = "idle";
37 var activeCall = null;
38 var activeService = null;
42 function onMouseDown(event)
46 selectedObj = objectsAtLocation(currentPage, event.clientX, event.clientY);
48 if (selectedObj && selectedObj.onClick)
49 selectedObj.onClick(event);
51 prevXMouse = event.clientX;
52 prevYMouse = event.clientY;
56 function onMouseUp(event)
58 if (selectedObj && selectedObj.onRelease)
59 selectedObj.onRelease(event);
62 function resizeCanvas()
64 screenWidth = $(window).width();
65 screenHeight = $(window).height();
67 $(mainCanvas).attr('width', screenWidth);
68 $(mainCanvas).attr('height', screenHeight);
69 $(bgCanvas).attr('width', screenWidth);
70 $(bgCanvas).attr('height', screenHeight);
71 $(buttonCanvas).attr('width', screenWidth);
72 $(buttonCanvas).attr('height', screenHeight);
73 $(mouseClicksLayer).attr('width', screenWidth);
74 $(mouseClicksLayer).attr('height', screenHeight);
80 function loadImages(sources, callback)
85 for (var src in sources)
89 for (var src in sources)
91 images[src] = new Image();
92 images[src].onload = function(){
93 if (++loadedImages >= numImages) {
97 images[src].src = sources[src];
103 var activeAccount = null;
105 "onAccountUpdated": function(account) {},
106 "onAccountAdded": function(account) {
107 if (activeService == null) {
108 activeAccount = account;
109 activeService = tizen.call.getCallService(activeAccount.id);
114 switchMenu(mainPage);
115 clicksDisabled = false;
118 console.log("Modem available for account: " + activeAccount.id);
120 "onAccountRemoved": function(id) {
121 if (activeAccount && activeAccount.id == id) {
122 // grab any account available
123 activeAccount = tizen.account.findServices('')[0];
125 activeService = tizen.call.getCallService(activeAccount.id);
129 switchMenu(mainPage);
130 console.log("No available modems!");
135 mainCanvas = document.getElementById("mainCanvas");
136 bgCanvas = document.getElementById("bgCanvas");
137 buttonCanvas = document.getElementById("buttonCanvas");
138 mouseClicksLayer = document.getElementById("mouseClicks");
140 mainCtx = mainCanvas.getContext("2d");
141 bgCtx = bgCanvas.getContext("2d");
142 buttonCtx = buttonCanvas.getContext("2d");
143 mouseCtx = mouseClicksLayer.getContext("2d");
146 phoneIcon: "images/bluetooth-smartphone.png",
147 callButton: "images/ivi_btn-call.png",
148 callButtonActive: "images/ivi_btn-call-active.png",
149 closeButton: "images/ivi_btn-close.png",
150 deleteButton: "images/ivi_btn-delete.png",
151 deleteButtonActive: "images/ivi_btn-delete-active.png",
152 endCallButton: "images/ivi_btn-endcall.png",
153 endCallButtonActive: "images/ivi_btn-endcall-active.png",
154 incomingAcceptButton: "images/ivi_btn-incomingcall-accept.png",
155 incomingAcceptButtonActive: "images/ivi_btn-incomingcall-accept-active.png",
156 incomingDeclineButton: "images/ivi_btn-incomingcall-decline.png",
157 incomingDeclineButtonActive: "images/ivi_btn-incomingcall-decline-active.png",
158 listItem: "images/ivi_btn-list.png",
159 listItemActive: "images/ivi_btn-list-active.png",
160 numberButton: "images/ivi_btn-numbers.png",
161 numberButtonActive: "images/ivi_btn-numbers-active.png",
162 buttonBG: "images/ivi_buttonarea.png",
163 callIcon: "images/ivi_icon-call.png",
164 deleteIcon: "images/ivi_icon-delete.png",
165 endCallIcon: "images/ivi_icon-endcall.png",
166 deleteListItemIcon: "images/ivi_icon-list-delete.png",
167 deleteListItemIconActive: "images/ivi_icon-list-delete-active.png",
168 clockIcon: "images/ivi_icon-time.png",
169 textArea: "images/ivi_textarea.png",
170 bgImage: "images/ivi-v1_ivi-background.jpg"
173 loadImages(sources, resizeCanvas);
178 $(window).bind('resize', resizeCanvas);
180 mouseClicksLayer.addEventListener('mousedown', onMouseDown);
181 mouseClicksLayer.addEventListener('mouseup', onMouseUp);
183 tizen.account.addAccountListener(listener);
184 setTimeout(function(){
185 if (tizen.account.findServices('').length == 0)
189 switchMenu(mainPage);
190 console.log("No available modems!");
195 onIncoming: function(call) {
197 currentState = "incomingCall";
198 initCallPage(currentState);
199 updateNumber(call.callData.LineIdentification);
200 updateCallStateText("Incoming Call...");
201 switchMenu(callPage);
203 onDialing: function(call) {
206 onAlerting: function(call) {
209 onDisconnected: function(call, disconnectReason) {
212 switchMenu(mainPage);
214 onDisconnecting: function(call) {
216 switchMenu(mainPage);
218 onAccepted: function(call) {
220 updateCallStateText("Active");
223 onActivated: function(call) {
224 updateCallStateText("Active");
227 onError: function(call){
228 console.log("onError: "); console.log(call);
231 tizen.call.addCallHandler(handler);
234 function switchMenu(nextMenu)
236 currentPage.visible = false;
237 currentPage = nextMenu;
238 currentPage.visible = true;
239 currentPage.drawMenu();
245 initCallPage(currentState);
246 // initDisabledPage();
248 bgCtx.drawImage(images.bgImage, 0, 0, screenWidth, screenHeight);
249 currentPage.drawMenu();
252 $(document).ready(function () {