Dialer now shows incoming calls
authorBrian Jones <brian.j.jones@intel.com>
Thu, 23 Aug 2012 00:29:42 +0000 (17:29 -0700)
committerBrian Jones <brian.j.jones@intel.com>
Thu, 23 Aug 2012 00:29:42 +0000 (17:29 -0700)
index.html
js/callPage.js
js/dialer.js
js/mainPage.js
js/menuObject.js

index 9270f5a..c102256 100644 (file)
@@ -10,6 +10,7 @@
 
 <html>
   <head>
+    <script type="text/javascript" src="http://localhost:7681/Tizen.Device.js"></script>        
     <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>        
     <script type="text/javascript" src="js/canvasObject.js"></script>
     <script type="text/javascript" src="js/imageObject.js"></script>
index 55b87f4..fab5590 100644 (file)
@@ -60,15 +60,64 @@ function stopTimer()
     clearInterval(timerInterval);
 }
 
-function initCallPage(initState)
-{         
-    if (initState == "dialing" || initState == "inCall")
-       var buttonWidth = screenWidth * 0.6;
+function initButtons(initState)
+{
+       var incomingBar = callPage.getObj("incomingBar");
+       if (initState == "dialing" || initState == "activeCall")
+               var buttonWidth = screenWidth * 0.6;
+    else
+               var buttonWidth = (screenWidth * 0.8) / 2;
+       
+       var buttonHeight = screenHeight * 0.15;
+       
+        var endCallButton;
+
+    if (initState == "dialing" || initState == "activeCall")
+    {
+               endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.2, 
+                       "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );
+       
+               callPage.getObj("acceptCallButton").visible = false;                                                                                            
+    }
     else
-       var buttonWidth = (screenWidth * 0.8) / 2;
+    {
+               acceptCallButton = callPage.addObject(buttonCtx, "button", {"name" : "acceptCallButton", "image": images.incomingAcceptButton, "icon": images.callIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.1, 
+                       "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight, "visible" : true} );        
+       
+               endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100, 
+                       "xLoc" : acceptCallButton.xLoc + acceptCallButton.width + 20, "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );                                                                                                    
+               
+               acceptCallButton.onClick = function(){
+                   try {
+                       console.log("Accepting call")
+                               activeCall.accept();
+                   } catch (err) {
+                               console.log("Failed to accept call");
+                   }
+                   
+                   currentState = "activeCall";
+                       startTimer();
+                   initButtons("activeCall");
+                   drawMenu(callPage); 
+               };
+
+    }          
+
+    endCallButton.onClick = function(){                            
+       try {
+           activeCall.end();
+       } catch (err) {
+           console.log("Attempting to hangup a non-active call");
+       }
+       currentState = "idle";
+       switchMenu(mainPage);                   
+       stopTimer();
+    };
 
-    var buttonHeight = screenHeight * 0.15;
+}
 
+function initCallPage(initState)
+{         
 
     var incomingBar = callPage.addObject(mainCtx, "shape", {"name" : "incomingBar", "xLoc" : -20, "yLoc" : screenHeight * 0.2, "width" : screenWidth + 40, 
            "height" : screenHeight * 0.6, "fillStyle" : "#51504F", "strokeStyle" : "#B3BF3C", "lineWidth" : 5}); 
@@ -81,35 +130,9 @@ function initCallPage(initState)
 
     var callTime = callPage.addObject(mainCtx, "text", {"name" : "callTime", "xLoc" : clockIcon.xLoc + clockIcon.width + 10, "yLoc" : clockIcon.yLoc, "width" : screenWidth * 0.2, 
            "height" : 100, "text" : "00:00:00", "template" : callTimeTextTemplate});
-
-    var endCallButton;
-
-    if (initState == "dialing" || initState == "inCall")
-    {
-       endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.2, 
-               "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );
-
-       callPage.getObj("acceptCallButton").visible = false;                                                                                            
-    }
-    else
-    {
-       acceptCallButton = callPage.addObject(buttonCtx, "button", {"name" : "acceptCallButton", "image": images.incomingAcceptButton, "icon": images.callIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.1, 
-               "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight, "visible" : true} );        
-
-       endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100, 
-               "xLoc" : acceptCallButton.xLoc + acceptCallButton.width + 20, "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );                                                                                                    
-    }          
-
-    endCallButton.onClick = function(){                            
-       send({
-               "api_namespace" : "tizen.ivi.dialer",
-               "type": "method",
-               "command": "hangup"                                     
-               });     
-       currentState = "idle";
-       switchMenu(mainPage);                   
-       stopTimer();
-    };
+       
+       initButtons(initState);
+   
 }
 
 
index d279b61..0d739be 100644 (file)
@@ -14,7 +14,6 @@ var screenHeight;
 var screenWidth;
 var images = [];
 var objects = [];
-var ws = null;
 var mouseDrag = false, mouseDown = false;
 var prevXMouse, prevYMouse;
 
@@ -34,6 +33,9 @@ var currentPage = mainPage;
 var currentNumber = " ";
 var currentState = "idle";
 
+var activeCall = null;
+var activeService = null;
+
 function onMouseDown(event) 
 {      
 
@@ -100,57 +102,72 @@ function loadImages(sources, callback)
     }
 }
 
-function handleMsg(incomingMsg)
-{
-    if (incomingMsg.event)
-    {
-       switch (incomingMsg.event)
-       {
-           case "incoming_call":
-               currentState = "incomingCall";
-               initCallPage("incomingCall");
-               switchMenu("callPage");
-               break;
-           default:
-               break;
+function init() 
+{   
+    var activeAccount = null;
+    var listener = {
+       "onAccountUpdated": function(account) {}, 
+       "onAccountAdded": function(account) { 
+            if (activeService == null) {
+                activeAccount = account;
+                activeService = tizen.call.getCallService(activeAccount.id);
+            }
+            
+            // TODO: Remove banner warning of no available modems
+            console.log("Modem available for account: " + activeAccount.id);
+       }, 
+       "onAccountRemoved": function(id) {
+            if (activeAccount && activeAccount.id == id) {
+                // grab any account available
+                activeAccount = tizen.account.findServices('')[0];
+                try {
+                    activeService = tizen.call.getCallService(activeAccount.id);
+                } catch (err) {
+                    // TODO: Add banner letting the user know that calls can not
+                    // be made since there are no active modems
+                    console.log("No available modems!");
+                }
+            }
        }
     }
-}
-
-function connect()
-{
-    var host = window.location.hostname;
-    ws = new WebSocket("ws://localhost:9999/");
-
-    ws.onopen = function() {
-       send({
-               "type": "connect",
-               });
-       console.log("Attempting to connect");
-    };
+    tizen.account.addAccountListener(listener);
 
-    ws.onmessage = function (e) {
-       jsonMsg = JSON.parse(e.data);
-       handleMsg(jsonMsg);
-       console.log(e.data);
-    };
+    if (tizen.account.findServices('').length == 0) {
+        // TODO: Add banner letting the user know that calls can not
+        // be made since there are no active modems
+        console.log("No available modems!");
+    }
 
-    ws.onclose = function(e) {
-       alert("Connecition closed");
-       console.log(e);
+    var handler = {
+        onIncoming: function(call) {
+        activeCall = call;
+           currentState = "incomingCall";
+           updateNumber(call.callData.LineIdentification);
+           initCallPage("incomingCall");
+           switchMenu(callPage);
+        },
+        onDialing: function(call) {
+            activeCall = call;
+        },
+        onAlerting: function(call) {
+            activeCall = call;
+        },
+        onDisconnected: function(call, disconnectReason) {
+            activeCall = null;
+        },
+        onDisconnecting: function(call) {
+        },
+        onAccepted: function(call) {
+            activeCall = call;
+        },
+        onActivated: function(call) {
+        },
+        onError: function(call){
+            console.log("onError: "); console.log(call);
+        }
     };
-}
+    tizen.call.addCallHandler(handler);
 
-function send(msg) 
-{
-    jsonMsg = JSON.stringify(msg);
-    ws.send(jsonMsg);
-    console.log("sent message: " + jsonMsg);
-}
-
-function init() 
-{   
-    connect();
     mainCanvas = document.getElementById("mainCanvas");
     bgCanvas = document.getElementById("bgCanvas");
     buttonCanvas = document.getElementById("buttonCanvas");
@@ -217,7 +234,6 @@ function initPages()
     currentPage.drawMenu();
 }
 
-
 $(document).ready(function () {
        init();
        });
index 61e65d8..989c155 100644 (file)
@@ -79,14 +79,13 @@ function addButtonGrid (gridX, gridY, gridWidth, gridHeight)
 
     button.onClick = function(){                           
        var dialNumber = mainPage.getObj("textArea").textObj.text;
-       
-       send({
-               "api_namespace" : "tizen.ivi.dialer",
-               "type": "method",
-               "command": "dial_number",
-               "number": dialNumber
-               });                                                             
-       
+
+        try {
+            activeService.makeCall(dialNumber);
+        } catch (err) {
+            console.log("Attempting to make call without an available modem");
+            return;
+        }
        initCallPage("dialing");
        updateNumber(dialNumber);
        switchMenu(callPage);           
index 083ba97..0626607 100644 (file)
@@ -101,10 +101,23 @@ MenuObject.prototype.addIconGrid = function(iconNames, iconImages, iconWidth, ic
 
 function addBackButton(menuObj, xLoc, yLoc, width, height)
 {
-    menuObj.addObject(buttonCtx, "button", {"name" : "back", "image": images.home, "xLoc" : xLoc, "yLoc" : yLoc, "width" : width, "height" : height, "shadowOffsetX" : 0, "shadowOffsetY" : 0, 
-           "shadowBlur" : 12,  "shadowColor" : "black",
-           "onClick" : function(){switchMenu(mainMenu); send({"type": "command","command": "app_change","key_id": "mainMenu"});}
-           });
+    var obj = {
+        "name" : "back", 
+        "image": images.home, 
+        "xLoc" : xLoc, 
+        "yLoc" : yLoc, 
+        "width" : width, 
+        "height" : height, 
+        "shadowOffsetX" : 0, 
+        "shadowOffsetY" : 0, 
+        "shadowBlur" : 12, 
+        "shadowColor" : "black", 
+        "onClick" : function() { 
+            switchMenu(mainMenu);
+            // TODO: Add call to trigger the homescreen to be raised
+        }
+    }
+    menuObj.addObject(buttonCtx, obj);
 }
 
 MenuObject.prototype.drawMenu = function()