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;
17 var mouseDrag = false, mouseDown = false;
18 var prevXMouse, prevYMouse;
20 var mainPageTitleTemplate = {"font" : "bold 40pt Arial", "lineWidth" : 2.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "center",
21 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 32, "shadowColor" : "rgba(0, 0, 110, 1.0)"};
23 var mainPageButtonTemplate = {"font" : "bold 20pt Arial", "lineWidth" : 1.5, "strokeStyle" : "white", "textAlign" : "center", "textBaseline" : "middle",
24 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 10, "shadowColor" : "black"};
26 var buttonTextTemplate = {"font" : "bold 30pt Arial", "fillStyle" : "white", "textAlign" : "center", "textBaseline" : "middle",
27 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 12, "shadowColor" : "rgba(50, 50, 50, 1.0)"};
29 var mainPage = new MenuObject({"name" : "main", "xLoc" : 0, "yLoc" : 0, "visible" : true});
30 var callPage = new MenuObject({"name" : "incomingCall", "xLoc" : 0, "yLoc" : 0, "visible" : true});
32 var currentPage = mainPage;
33 var currentNumber = " ";
34 var currentState = "idle";
36 var activeCall = null;
37 var activeService = null;
39 function onMouseDown(event)
42 var selectedObj = objectsAtLocation(currentPage, event.clientX, event.clientY);
44 if (selectedObj && selectedObj.onClick)
45 selectedObj.onClick(event);
47 prevXMouse = event.clientX;
48 prevYMouse = event.clientY;
51 function onMouseMove(event)
53 var selectedObj = objectsAtLocation(currentPage, event.clientX, event.clientY);
54 if (selectedObj && selectedObj.onMove)
55 selectedObj.onMove(event);
57 prevXMouse = event.clientX;
58 prevYMouse = event.clientY;
61 function onMouseUp(event)
66 function resizeCanvas()
68 screenWidth = $(window).width();
69 screenHeight = $(window).height();
71 $(mainCanvas).attr('width', screenWidth);
72 $(mainCanvas).attr('height', screenHeight);
73 $(bgCanvas).attr('width', screenWidth);
74 $(bgCanvas).attr('height', screenHeight);
75 $(buttonCanvas).attr('width', screenWidth);
76 $(buttonCanvas).attr('height', screenHeight);
77 $(mouseClicksLayer).attr('width', screenWidth);
78 $(mouseClicksLayer).attr('height', screenHeight);
84 function loadImages(sources, callback)
89 for (var src in sources)
93 for (var src in sources)
95 images[src] = new Image();
96 images[src].onload = function(){
97 if (++loadedImages >= numImages) {
101 images[src].src = sources[src];
107 var activeAccount = null;
109 "onAccountUpdated": function(account) {},
110 "onAccountAdded": function(account) {
111 if (activeService == null) {
112 activeAccount = account;
113 activeService = tizen.call.getCallService(activeAccount.id);
116 // TODO: Remove banner warning of no available modems
117 console.log("Modem available for account: " + activeAccount.id);
119 "onAccountRemoved": function(id) {
120 if (activeAccount && activeAccount.id == id) {
121 // grab any account available
122 activeAccount = tizen.account.findServices('')[0];
124 activeService = tizen.call.getCallService(activeAccount.id);
126 // TODO: Add banner letting the user know that calls can not
127 // be made since there are no active modems
128 console.log("No available modems!");
133 tizen.account.addAccountListener(listener);
135 if (tizen.account.findServices('').length == 0) {
136 // TODO: Add banner letting the user know that calls can not
137 // be made since there are no active modems
138 console.log("No available modems!");
142 onIncoming: function(call) {
144 currentState = "incomingCall";
145 updateNumber(call.callData.LineIdentification);
146 initCallPage("incomingCall");
147 switchMenu(callPage);
149 onDialing: function(call) {
152 onAlerting: function(call) {
155 onDisconnected: function(call, disconnectReason) {
158 onDisconnecting: function(call) {
160 onAccepted: function(call) {
163 onActivated: function(call) {
165 onError: function(call){
166 console.log("onError: "); console.log(call);
169 tizen.call.addCallHandler(handler);
171 mainCanvas = document.getElementById("mainCanvas");
172 bgCanvas = document.getElementById("bgCanvas");
173 buttonCanvas = document.getElementById("buttonCanvas");
174 mouseClicksLayer = document.getElementById("mouseClicks");
176 mainCtx = mainCanvas.getContext("2d");
177 bgCtx = bgCanvas.getContext("2d");
178 buttonCtx = buttonCanvas.getContext("2d");
181 phoneIcon: "images/bluetooth-smartphone.png",
182 callButton: "images/ivi_btn-call.png",
183 callButtonPressed: "images/ivi_btn-call-active.png",
184 closeButton: "images/ivi_btn-close.png",
185 deleteButton: "images/ivi_btn-delete.png",
186 deleteButtonActive: "images/ivi_btn-delete-active.png",
187 endCallButton: "images/ivi_btn-endcall.png",
188 endCallButtonActive: "images/ivi_btn-endcall-active.png",
189 incomingAcceptButton: "images/ivi_btn-incomingcall-accept.png",
190 incomingAcceptButtonActive: "images/ivi_btn-incomingcall-accept-active.png",
191 incomingDeclineButton: "images/ivi_btn-incomingcall-decline.png",
192 incomingDeclineButtonActive: "images/ivi_btn-incomingcall-decline-active.png",
193 listItem: "images/ivi_btn-list.png",
194 listItemActive: "images/ivi_btn-list-active.png",
195 numberButton: "images/ivi_btn-numbers.png",
196 numberButtonActive: "images/ivi_btn-numbers-active.png",
197 buttonBG: "images/ivi_buttonarea.png",
198 callIcon: "images/ivi_icon-call.png",
199 deleteIcon: "images/ivi_icon-delete.png",
200 endCallIcon: "images/ivi_icon-endcall.png",
201 deleteListItemIcon: "images/ivi_icon-list-delete.png",
202 deleteListItemIconActive: "images/ivi_icon-list-delete-active.png",
203 clockIcon: "images/ivi_icon-time.png",
204 textArea: "images/ivi_textarea.png",
205 bgImage: "images/ivi-v1_ivi-background.jpg"
208 loadImages(sources, resizeCanvas);
213 $(window).bind('resize', resizeCanvas);
215 mouseClicksLayer.addEventListener('mousedown', onMouseDown);
216 mouseClicksLayer.addEventListener('mousemove', onMouseMove);
217 mouseClicksLayer.addEventListener('mouseup', onMouseUp);
220 function switchMenu(nextMenu)
222 currentPage.visible = false;
223 currentPage = nextMenu;
224 currentPage.visible = true;
225 currentPage.drawMenu();
231 initCallPage(currentState);
233 bgCtx.drawImage(images.bgImage, 0, 0, screenWidth, screenHeight);
234 currentPage.drawMenu();
237 $(document).ready(function () {