#16928: Added call state in CallList and CallActivity
diff --git a/src/com/savoirfairelinux/sflphone/client/CallActivity.java b/src/com/savoirfairelinux/sflphone/client/CallActivity.java
index 6c4c4c7..7332025 100644
--- a/src/com/savoirfairelinux/sflphone/client/CallActivity.java
+++ b/src/com/savoirfairelinux/sflphone/client/CallActivity.java
@@ -45,6 +45,7 @@
 import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.widget.TextView;
 
 import com.savoirfairelinux.sflphone.R;
 import com.savoirfairelinux.sflphone.client.SipCall;
@@ -66,6 +67,7 @@
 
             if(signalName.equals(CallManagerCallBack.NEW_CALL_CREATED)) {
             } else if(signalName.equals(CallManagerCallBack.CALL_STATE_CHANGED)) {
+                processCallStateChangedSignal(intent);
             } else if(signalName.equals(CallManagerCallBack.INCOMING_CALL)) {
             }
         }
@@ -122,4 +124,31 @@
             finish();
         }
     }
+
+    private void processCallStateChangedSignal(Intent intent) {
+        TextView textView = (TextView)findViewById(R.id.callstate);
+
+        // Bundle bundle = intent.getExtras();
+        Bundle bundle = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
+        String callID = bundle.getString("CallID");
+        String newState = bundle.getString("State");
+
+        if(newState.equals("INCOMING")) {
+            textView.setText("Call State: " + newState);
+        } else if(newState.equals("RINGING")) {
+            textView.setText("Call State: " + newState);
+        } else if(newState.equals("CURRENT")) {
+            textView.setText("Call State: " + newState);
+        } else if(newState.equals("HUNGUP")) {
+            textView.setText("Call State: " + newState);
+        } else if(newState.equals("BUSY")) {
+            textView.setText("Call State: " + newState);
+        } else if(newState.equals("FAILURE")) {
+            textView.setText("Call State: " + newState);
+        } else if(newState.equals("HOLD")) {
+            textView.setText("Call State: " + newState);
+        } else if(newState.equals("UNHOLD")) {
+            textView.setText("Call State: " + newState);
+        }
+    }
 }
diff --git a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
index 15db90d..982c91f 100644
--- a/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
+++ b/src/com/savoirfairelinux/sflphone/client/SFLPhoneHome.java
@@ -484,7 +484,6 @@
                     callOnGoing = true;
                     buttonCall.setEnabled(false);
                     buttonHangup.setEnabled(true);
-                    launchCallActivity();
                 //}
             }
 
@@ -492,14 +491,31 @@
             Log.e(TAG, "Cannot call service method", e);
         }
         */
-        
-        Random random = new Random();
-        String callID = Integer.toString(random.nextInt());
-        SipCall.CallInfo info = new SipCall.CallInfo();
-        info.mCallID = callID;
+        try {
+            String accountID = mAccountList.currentAccountID;
+            EditText editText = (EditText) findViewById(R.id.editTo);
+            String to = "147"; // editText.getText().toString();
+ 
+            Random random = new Random();
+            String callID = Integer.toString(random.nextInt());
+            SipCall.CallInfo info = new SipCall.CallInfo();
 
-        SipCall call = CallList.getCallInstance(info);
-        call.launchCallActivity(this);
+            info.mCallID = callID;
+            info.mDisplayName = "Cool Guy!";
+            info.mPhone = to;
+            info.mEmail = "coolGuy@coolGuy.com";
+
+            SipCall call = CallList.getCallInstance(info);
+            call.launchCallActivity(this);
+        
+            Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
+            service.placeCall(accountID, callID, to);
+            callOnGoing = true;
+            buttonCall.setEnabled(false);
+            buttonHangup.setEnabled(true);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Cannot call service method", e);
+        }
     }
 
     public void processingHangUpAction() {
diff --git a/src/com/savoirfairelinux/sflphone/client/SipCall.java b/src/com/savoirfairelinux/sflphone/client/SipCall.java
index ea775fd..e630672 100644
--- a/src/com/savoirfairelinux/sflphone/client/SipCall.java
+++ b/src/com/savoirfairelinux/sflphone/client/SipCall.java
@@ -48,14 +48,14 @@
     public static CallElementList mCallElementList = null;
     public CallInfo mCallInfo;
 
-    public static int CALL_STATE_INVALID = 0;      // The call is not existent in SFLphone service
-    public static int CALL_STATE_NULL = 1;         // Before any action performed
-    public static int CALL_STATE_CALLING = 2;      // After INVITE is sent
-    public static int CALL_STATE_INCOMING = 3;     // After INVITE is received
-    public static int CALL_STATE_EARLY = 4;        // After response with To tag
-    public static int CALL_STATE_CONNECTING = 5;   // After 2xx is sent/received
-    public static int CALL_STATE_CONFIRMED = 6;    // After ACK is sent/received
-    public static int CALL_STATE_DISCONNECTED = 7; // Session is terminated
+    public static int CALL_STATE_NULL = 0;
+    public static int CALL_STATE_INCOMING = 1;
+    public static int CALL_STATE_RINGING = 2;
+    public static int CALL_STATE_CURRENT = 3;
+    public static int CALL_STATE_BUSY = 4;
+    public static int CALL_STATE_FAILURE = 5;
+    public static int CALL_STATE_HOLD = 6;
+    public static int CALL_STATE_UNHOLD = 7;
 
     public static int MEDIA_STATE_NONE = 0;        // No media currently
     public static int MEDIA_STATE_ACTIVE = 1;      // Media is active
@@ -137,6 +137,62 @@
         mCallElementList = list;
     }
 
+    public void setCallID(String callID) {
+        mCallInfo.mCallID = callID;
+    }
+
+    public String getCallId() {
+        return mCallInfo.mCallID;
+    }
+
+    public void setDisplayName(String displayName) {
+        mCallInfo.mDisplayName = displayName;
+    }
+
+    public String getDisplayName() {
+        return mCallInfo.mDisplayName;
+    }
+
+    public void setPhone(String phone) {
+        mCallInfo.mPhone = phone;
+    }
+
+    public String getPhone() {
+        return mCallInfo.mPhone;
+    }
+
+    public void setEmail(String email) {
+        mCallInfo.mEmail = email;
+    }
+
+    public String getEmail() {
+        return mCallInfo.mEmail;
+    }
+
+    public void setRemoteContact(String remoteContact) {
+        mCallInfo.mRemoteContact = remoteContact;
+    }
+
+    public String getRemoteContact() {
+        return mCallInfo.mRemoteContact;
+    }
+
+    public void setCallState(int callState) {
+        mCallInfo.mCallState = callState;
+    }
+
+    public int getCallState() {
+        return mCallInfo.mCallState;
+    }
+
+    public void setMediaState(int mediaState) {
+        mCallInfo.mMediaState = mediaState;
+    }
+
+    public int getMediaState() {
+        return mCallInfo.mMediaState;
+    }
+
     public void placeCall()
     {
         if(mCallElementList != null)
diff --git a/src/com/savoirfairelinux/sflphone/service/CallManagerCallBack.java b/src/com/savoirfairelinux/sflphone/service/CallManagerCallBack.java
index 25a3a20..b72738c 100644
--- a/src/com/savoirfairelinux/sflphone/service/CallManagerCallBack.java
+++ b/src/com/savoirfairelinux/sflphone/service/CallManagerCallBack.java
@@ -45,7 +45,7 @@
         bundle.putString("To", to);
         Intent intent = new Intent(NEW_CALL_CREATED);
         intent.putExtra(SIGNAL_NAME, NEW_CALL_CREATED);
-        intent.putExtra("newcall", bundle);
+        intent.putExtra("com.savoirfairelinux.sflphone.service.newcall", bundle);
         LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
     }
 
@@ -55,7 +55,7 @@
         bundle.putString("State", state);
         Intent intent = new Intent(CALL_STATE_CHANGED);
         intent.putExtra(SIGNAL_NAME, CALL_STATE_CHANGED); 
-        intent.putExtra("newstate", bundle);
+        intent.putExtra("com.savoirfairelinux.sflphone.service.newstate", bundle);
         LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
     }
 
@@ -66,7 +66,7 @@
         bundle.putString("From", from);
         Intent intent = new Intent(INCOMING_CALL);
         intent.putExtra(SIGNAL_NAME, INCOMING_CALL); 
-        intent.putExtra("newcall", bundle);
+        intent.putExtra("com.savoirfairelinux.sflphone.service.newcall", bundle);
         LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
     }
 }
diff --git a/src/com/savoirfairelinux/sflphone/utils/CallList.java b/src/com/savoirfairelinux/sflphone/utils/CallList.java
index 0f7f66a..2ac5b08 100644
--- a/src/com/savoirfairelinux/sflphone/utils/CallList.java
+++ b/src/com/savoirfairelinux/sflphone/utils/CallList.java
@@ -36,6 +36,7 @@
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
+import android.os.Bundle;
 import android.util.Log;
 
 import java.util.ArrayList;
@@ -82,7 +83,34 @@
 
         if(signalName.equals(CallManagerCallBack.NEW_CALL_CREATED)) {
         } else if(signalName.equals(CallManagerCallBack.CALL_STATE_CHANGED)) {
+            processCallStateChangedSignal(intent);
         } else if(signalName.equals(CallManagerCallBack.INCOMING_CALL)) {
         }
     }
+
+    private void processCallStateChangedSignal(Intent intent) {
+        Bundle bundle = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
+        String callID = bundle.getString("CallID");
+        String newState = bundle.getString("State");
+
+        SipCall.CallInfo info = new SipCall.CallInfo();
+        info.mCallID = callID;
+                
+        SipCall call = getCallInstance(info);
+        if(newState.equals("INCOMING")) {
+            call.setCallState(SipCall.CALL_STATE_INCOMING);
+        } else if(newState.equals("RINGING")) {
+            call.setCallState(SipCall.CALL_STATE_RINGING);
+        } else if(newState.equals("CURRENT")) {
+            call.setCallState(SipCall.CALL_STATE_CURRENT);
+        } else if(newState.equals("BUSY")) {
+            call.setCallState(SipCall.CALL_STATE_BUSY);
+        } else if(newState.equals("FAILURE")) {
+            call.setCallState(SipCall.CALL_STATE_FAILURE);
+        } else if(newState.equals("HOLD")) {
+            call.setCallState(SipCall.CALL_STATE_HOLD);
+        } else if(newState.equals("UNHOLD")) {
+            call.setCallState(SipCall.CALL_STATE_UNHOLD);
+        }
+    }
 }