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,callCanvas;
11 var mainCtx, bgCtx, buttonCtx, mouseCtx, callCtx;
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);
75 $(callCanvas).attr('width', screenWidth);
76 $(callCanvas).attr('height', screenHeight);
82 function loadImages(sources, callback)
87 for (var src in sources)
91 for (var src in sources)
93 images[src] = new Image();
94 images[src].onload = function(){
95 if (++loadedImages >= numImages) {
99 images[src].src = sources[src];
105 document.documentElement.style.overflow = 'hidden';
106 var activeAccount = null;
108 "onAccountUpdated": function(account) {},
109 "onAccountAdded": function(account) {
110 if (activeService == null) {
111 activeAccount = account;
112 activeService = tizen.call.getCallService(activeAccount.id);
117 switchMenu(mainPage);
118 clicksDisabled = false;
121 console.log("Modem available for account: " + activeAccount.id);
123 "onAccountRemoved": function(id) {
124 if (activeAccount && activeAccount.id == id) {
125 // grab any account available
126 activeAccount = tizen.account.findServices('')[0];
128 activeService = tizen.call.getCallService(activeAccount.id);
132 switchMenu(mainPage);
133 console.log("No available modems!");
138 mainCanvas = document.getElementById("mainCanvas");
139 bgCanvas = document.getElementById("bgCanvas");
140 buttonCanvas = document.getElementById("buttonCanvas");
141 mouseClicksLayer = document.getElementById("mouseClicks");
142 callCanvas = document.getElementById("callCanvas");
144 mainCtx = mainCanvas.getContext("2d");
145 bgCtx = bgCanvas.getContext("2d");
146 buttonCtx = buttonCanvas.getContext("2d");
147 mouseCtx = mouseClicksLayer.getContext("2d");
148 callCtx = callCanvas.getContext("2d");
151 phoneIcon: "images/bluetooth-smartphone.png",
152 callButton: "images/ivi_btn-call.png",
153 callButtonActive: "images/ivi_btn-call-active.png",
154 closeButton: "images/ivi_btn-close.png",
155 deleteButton: "images/ivi_btn-delete.png",
156 deleteButtonActive: "images/ivi_btn-delete-active.png",
157 endCallButton: "images/ivi_btn-endcall.png",
158 endCallButtonActive: "images/ivi_btn-endcall-active.png",
159 incomingAcceptButton: "images/ivi_btn-incomingcall-accept.png",
160 incomingAcceptButtonActive: "images/ivi_btn-incomingcall-accept-active.png",
161 incomingDeclineButton: "images/ivi_btn-incomingcall-decline.png",
162 incomingDeclineButtonActive: "images/ivi_btn-incomingcall-decline-active.png",
163 listItem: "images/ivi_btn-list.png",
164 listItemActive: "images/ivi_btn-list-active.png",
165 numberButton: "images/ivi_btn-numbers.png",
166 numberButtonActive: "images/ivi_btn-numbers-active.png",
167 buttonBG: "images/ivi_buttonarea.png",
168 callIcon: "images/ivi_icon-call.png",
169 deleteIcon: "images/ivi_icon-delete.png",
170 endCallIcon: "images/ivi_icon-endcall.png",
171 deleteListItemIcon: "images/ivi_icon-list-delete.png",
172 deleteListItemIconActive: "images/ivi_icon-list-delete-active.png",
173 clockIcon: "images/ivi_icon-time.png",
174 textArea: "images/ivi_textarea.png",
175 bgImage: "images/ivi-v1_ivi-background.jpg"
178 loadImages(sources, resizeCanvas);
183 $(window).bind('resize', resizeCanvas);
185 mouseClicksLayer.addEventListener('mousedown', onMouseDown);
186 mouseClicksLayer.addEventListener('mouseup', onMouseUp);
188 tizen.account.addAccountListener(listener);
189 setTimeout(function(){
190 if (tizen.account.findServices('').length == 0)
194 switchMenu(mainPage);
195 console.log("No available modems!");
200 onIncoming: function(call) {
202 currentState = "incomingCall";
203 initCallPage(currentState);
204 updateNumber(call.callData.LineIdentification);
205 updateCallStateText("Incoming Call...");
207 //switchMenu(callPage);
209 onDialing: function(call) {
212 onAlerting: function(call) {
215 onDisconnected: function(call, disconnectReason) {
216 if (currentState !== "idle")
218 currentState = "idle";
223 //switchMenu(mainPage);
225 onDisconnecting: function(call) {
226 if (currentState !== "idle")
228 currentState = "idle";
232 //switchMenu(mainPage);
234 onAccepted: function(call) {
236 initButtons("activeCall");
237 updateCallStateText("Active");
241 onActivated: function(call) {
243 initButtons("activeCall");
244 updateCallStateText("Active");
248 onError: function(call){
249 console.log("onError: "); console.log(call);
252 tizen.call.addCallHandler(handler);
255 function switchMenu(nextMenu)
257 //currentPage.visible = false;
258 currentPage = nextMenu;
259 currentPage.visible = true;
260 currentPage.drawMenu();
266 initCallPage(currentState);
267 // initDisabledPage();
269 bgCtx.drawImage(images.bgImage, 0, 0, screenWidth, screenHeight);
270 currentPage.drawMenu();
273 $(document).ready(function () {