Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 5 | * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | * |
| 21 | * Additional permission under GNU GPL version 3 section 7: |
| 22 | * |
| 23 | * If you modify this program, or any covered work, by linking or |
| 24 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 25 | * modified version of that library), containing parts covered by the |
| 26 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 27 | * grants you additional permission to convey the resulting work. |
| 28 | * Corresponding Source for a non-source form of such a combination |
| 29 | * shall include the source code for the parts of OpenSSL used as well |
| 30 | * as that of the covered work. |
| 31 | */ |
| 32 | |
| 33 | package com.savoirfairelinux.sflphone.client; |
| 34 | |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 35 | import java.util.HashMap; |
| 36 | import java.util.Random; |
| 37 | import java.util.concurrent.ExecutorService; |
| 38 | import java.util.concurrent.Executors; |
| 39 | |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 40 | import android.app.Activity; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 41 | import android.content.ComponentName; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 42 | import android.content.Context; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 43 | import android.content.Intent; |
| 44 | import android.content.ServiceConnection; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 45 | import android.graphics.Bitmap; |
| 46 | import android.graphics.PointF; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 47 | import android.os.Bundle; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 48 | import android.os.IBinder; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 49 | import android.os.Parcelable; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 50 | import android.os.RemoteException; |
| 51 | import android.util.DisplayMetrics; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 52 | import android.util.Log; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 53 | import android.widget.Toast; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 54 | |
| 55 | import com.savoirfairelinux.sflphone.R; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 56 | import com.savoirfairelinux.sflphone.adapters.ContactPictureLoader; |
| 57 | import com.savoirfairelinux.sflphone.client.receiver.CallListReceiver; |
| 58 | import com.savoirfairelinux.sflphone.model.Attractor; |
| 59 | import com.savoirfairelinux.sflphone.model.Bubble; |
| 60 | import com.savoirfairelinux.sflphone.model.BubbleModel; |
| 61 | import com.savoirfairelinux.sflphone.model.BubblesView; |
| 62 | import com.savoirfairelinux.sflphone.model.CallContact; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 63 | import com.savoirfairelinux.sflphone.model.SipCall; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 64 | import com.savoirfairelinux.sflphone.service.ISipClient; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 65 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 66 | import com.savoirfairelinux.sflphone.service.SipService; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 67 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 68 | public class CallActivity extends Activity { |
| 69 | static final String TAG = "CallActivity"; |
| 70 | private ISipService service; |
| 71 | private String pendingAction = null; |
| 72 | private SipCall mCall; |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 73 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 74 | private BubblesView view; |
| 75 | private BubbleModel model; |
| 76 | private PointF screenCenter; |
| 77 | private DisplayMetrics metrics; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 78 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 79 | private HashMap<CallContact, Bubble> contacts = new HashMap<CallContact, Bubble>(); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 80 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 81 | private ExecutorService infos_fetcher = Executors.newCachedThreadPool(); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 82 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 83 | public interface CallFragment { |
| 84 | void setCall(SipCall c); |
| 85 | } |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 86 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 87 | /* |
| 88 | * private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { |
| 89 | * |
| 90 | * @Override public void onReceive(Context context, Intent intent) { String signalName = intent.getStringExtra(CallManagerCallBack.SIGNAL_NAME); |
| 91 | * Log.d(TAG, "Signal received: " + signalName); |
| 92 | * |
| 93 | * if (signalName.equals(CallManagerCallBack.NEW_CALL_CREATED)) { } else if (signalName.equals(CallManagerCallBack.CALL_STATE_CHANGED)) { |
| 94 | * processCallStateChangedSignal(intent); } else if (signalName.equals(CallManagerCallBack.INCOMING_CALL)) { } } }; |
| 95 | */ |
| 96 | private ISipClient callback = new ISipClient.Stub() { |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 97 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 98 | @Override |
| 99 | public void incomingCall(Intent call) throws RemoteException { |
| 100 | Log.i(TAG, "Incoming call transfered from Service"); |
| 101 | SipCall.CallInfo infos = new SipCall.CallInfo(call); |
| 102 | SipCall c = new SipCall(infos); |
| 103 | // |
| 104 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 105 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 106 | @Override |
| 107 | public void callStateChanged(Intent callState) throws RemoteException { |
| 108 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 109 | String cID = b.getString("CallID"); |
| 110 | String state = b.getString("State"); |
| 111 | Log.i(TAG, "callStateChanged" + cID + " " + state); |
| 112 | processCallStateChangedSignal(cID, state); |
| 113 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 114 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 115 | @Override |
| 116 | public void incomingText(Intent msg) throws RemoteException { |
| 117 | Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); |
| 118 | b.getString("CallID"); |
| 119 | String from = b.getString("From"); |
| 120 | String mess = b.getString("Msg"); |
| 121 | Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show(); |
| 122 | } |
| 123 | }; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 124 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 125 | @Override |
| 126 | protected void onCreate(Bundle savedInstanceState) { |
| 127 | super.onCreate(savedInstanceState); |
| 128 | setContentView(R.layout.bubbleview_layout); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 129 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 130 | model = new BubbleModel(getResources().getDisplayMetrics().density); |
| 131 | metrics = getResources().getDisplayMetrics(); |
| 132 | screenCenter = new PointF(metrics.widthPixels / 2, metrics.heightPixels / 3); |
| 133 | // radiusCalls = metrics.widthPixels / 2 - 150; |
| 134 | // model.listBubbles.add(new Bubble(this, metrics.widthPixels / 2, metrics.heightPixels / 4, 150, R.drawable.me)); |
| 135 | // model.listBubbles.add(new Bubble(this, metrics.widthPixels / 2, metrics.heightPixels / 4 * 3, 150, R.drawable.callee)); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 136 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 137 | view = (BubblesView) findViewById(R.id.main_view); |
| 138 | view.setModel(model); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 139 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 140 | Bundle b = getIntent().getExtras(); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 141 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 142 | |
| 143 | SipCall.CallInfo info = b.getParcelable("CallInfo"); |
| 144 | Log.i(TAG, "Starting activity for call " + info.mCallID); |
| 145 | mCall = new SipCall(info); |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 146 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 147 | Intent intent = new Intent(this, SipService.class); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 148 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 149 | // setCallStateDisplay(mCall.getCallStateString()); |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 150 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 151 | pendingAction = b.getString("action"); |
| 152 | if (pendingAction != null && pendingAction.equals("call")) { |
| 153 | CallContact contact = b.getParcelable("CallContact"); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 154 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 155 | Log.i(TAG, "Calling " + contact.getmDisplayName()); |
| 156 | callContact(contact); |
| 157 | // SipCall.CallInfo info = new SipCall.CallInfo(); |
| 158 | // Random random = new Random(); |
| 159 | // String callID = Integer.toString(random.nextInt()); |
| 160 | // Phone phone = contact.getSipPhone(); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 161 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 162 | // info.mCallID = callID; |
| 163 | // info.mAccountID = ""+contact.getId(); |
| 164 | // info.mDisplayName = contact.getmDisplayName(); |
| 165 | // info.mPhone = phone==null?null:phone.toString(); |
| 166 | // info.mEmail = contact.getmEmail(); |
| 167 | // info.mCallType = SipCall.CALL_TYPE_OUTGOING; |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 168 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 169 | // mCall = CallListReceiver.getCallInstance(info); |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 170 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 171 | // mCallbacks.onCallSelected(call); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 172 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 173 | /* |
| 174 | * try { service.placeCall(info.mAccountID, info.mCallID, info.mPhone); } catch (RemoteException e) { Log.e(TAG, |
| 175 | * "Cannot call service method", e); } |
| 176 | */ |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 177 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 178 | } else if (pendingAction.equals("incoming")) { |
| 179 | callIncoming(); |
| 180 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 181 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 182 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 183 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 184 | /* |
| 185 | * LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED)); |
| 186 | * LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED)); |
| 187 | * LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.INCOMING_CALL)); |
| 188 | */ |
| 189 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 190 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 191 | private void callContact(final CallContact contact) { |
| 192 | // TODO off-thread image loading |
| 193 | Bubble contact_bubble; |
| 194 | if (contact.getPhoto_id() > 0) { |
| 195 | Bitmap photo = ContactPictureLoader.loadContactPhoto(getContentResolver(), contact.getId()); |
| 196 | contact_bubble = new Bubble(this, screenCenter.x, screenCenter.y, 150, photo); |
| 197 | } else { |
| 198 | contact_bubble = new Bubble(this, screenCenter.x, screenCenter.y, 150, R.drawable.ic_contact_picture); |
| 199 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 200 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 201 | model.attractors.clear(); |
| 202 | model.attractors.add(new Attractor(new PointF(metrics.widthPixels / 2, metrics.heightPixels * .8f), new Attractor.Callback() { |
| 203 | @Override |
| 204 | public void onBubbleSucked(Bubble b) { |
| 205 | Log.w(TAG, "Bubble sucked ! "); |
| 206 | onCallEnded(); |
| 207 | } |
| 208 | })); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 209 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 210 | contact_bubble.contact = contact; |
| 211 | model.listBubbles.add(contact_bubble); |
| 212 | contacts.put(contact, contact_bubble); |
| 213 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 214 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 215 | private void callIncoming() { |
| 216 | model.attractors.clear(); |
| 217 | model.attractors.add(new Attractor(new PointF(3 * metrics.widthPixels / 4, metrics.heightPixels / 4), new Attractor.Callback() { |
| 218 | @Override |
| 219 | public void onBubbleSucked(Bubble b) { |
| 220 | onCallAccepted(); |
| 221 | } |
| 222 | })); |
| 223 | model.attractors.add(new Attractor(new PointF(metrics.widthPixels / 4, metrics.heightPixels / 4), new Attractor.Callback() { |
| 224 | @Override |
| 225 | public void onBubbleSucked(Bubble b) { |
| 226 | onCallRejected(); |
| 227 | } |
| 228 | })); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 229 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 230 | } |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 231 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 232 | @Override |
| 233 | protected void onDestroy() { |
| 234 | // Log.i(TAG, "Destroying Call Activity for call " + mCall.getCallId()); |
| 235 | // LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver); |
| 236 | unbindService(mConnection); |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 237 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 238 | super.onDestroy(); |
| 239 | } |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 240 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 241 | /** Defines callbacks for service binding, passed to bindService() */ |
| 242 | private ServiceConnection mConnection = new ServiceConnection() { |
| 243 | @Override |
| 244 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 245 | service = ISipService.Stub.asInterface(binder); |
| 246 | try { |
| 247 | service.registerClient(callback); |
| 248 | if (pendingAction != null && pendingAction.contentEquals("call")) { |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 249 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 250 | Log.i(TAG, "Placing call"); |
| 251 | CallContact contact = model.listBubbles.get(0).contact; |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 252 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 253 | String callID = Integer.toString(new Random().nextInt()); |
| 254 | SipCall.CallInfo info = new SipCall.CallInfo(); |
| 255 | info.mCallID = callID; |
| 256 | info.mAccountID = service.getAccountList().get(0).toString(); |
| 257 | info.mDisplayName = contact.getmDisplayName(); |
| 258 | info.mPhone = contact.getSipPhone().getNumber(); |
| 259 | info.mEmail = contact.getmEmail(); |
| 260 | info.mCallType = SipCall.CALL_TYPE_OUTGOING; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 261 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 262 | mCall = CallListReceiver.getCallInstance(info); |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 263 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 264 | service.placeCall(info.mAccountID, info.mCallID, info.mPhone); |
| 265 | pendingAction = null; |
| 266 | } |
| 267 | } catch (RemoteException e) { |
| 268 | Log.e(TAG, e.toString()); |
| 269 | } |
| 270 | } |
Alexandre Savard | e41f521 | 2012-10-26 14:23:50 -0400 | [diff] [blame] | 271 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 272 | @Override |
| 273 | public void onServiceDisconnected(ComponentName arg0) { |
| 274 | } |
| 275 | }; |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 276 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 277 | private void processCallStateChangedSignal(String callID, String newState) { |
| 278 | /* |
| 279 | * Bundle bundle = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); String callID = bundle.getString("CallID"); String |
| 280 | * newState = bundle.getString("State"); |
| 281 | */ |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 282 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 283 | if (newState.equals("INCOMING")) { |
| 284 | mCall.setCallState(SipCall.CALL_STATE_INCOMING); |
| 285 | setCallStateDisplay(newState); |
| 286 | } else if (newState.equals("RINGING")) { |
| 287 | mCall.setCallState(SipCall.CALL_STATE_RINGING); |
| 288 | setCallStateDisplay(newState); |
| 289 | } else if (newState.equals("CURRENT")) { |
| 290 | mCall.setCallState(SipCall.CALL_STATE_CURRENT); |
| 291 | setCallStateDisplay(newState); |
| 292 | } else if (newState.equals("HUNGUP")) { |
| 293 | mCall.setCallState(SipCall.CALL_STATE_HUNGUP); |
| 294 | setCallStateDisplay(newState); |
| 295 | finish(); |
| 296 | } else if (newState.equals("BUSY")) { |
| 297 | mCall.setCallState(SipCall.CALL_STATE_BUSY); |
| 298 | setCallStateDisplay(newState); |
| 299 | } else if (newState.equals("FAILURE")) { |
| 300 | mCall.setCallState(SipCall.CALL_STATE_FAILURE); |
| 301 | setCallStateDisplay(newState); |
| 302 | } else if (newState.equals("HOLD")) { |
| 303 | mCall.setCallState(SipCall.CALL_STATE_HOLD); |
| 304 | setCallStateDisplay(newState); |
| 305 | } else if (newState.equals("UNHOLD")) { |
| 306 | mCall.setCallState(SipCall.CALL_STATE_CURRENT); |
| 307 | setCallStateDisplay("CURRENT"); |
| 308 | } else { |
| 309 | mCall.setCallState(SipCall.CALL_STATE_NONE); |
| 310 | setCallStateDisplay(newState); |
| 311 | } |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 312 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 313 | Log.w(TAG, "processCallStateChangedSignal " + newState); |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 314 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 315 | } |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 316 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 317 | private void setCallStateDisplay(String newState) { |
| 318 | if (newState == null || newState.equals("NULL")) { |
| 319 | newState = "INCOMING"; |
| 320 | } |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 321 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 322 | Log.w(TAG, "setCallStateDisplay " + newState); |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 323 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 324 | /* |
| 325 | * mCall.printCallInfo(); |
| 326 | * |
| 327 | * FragmentManager fm = getFragmentManager(); Fragment newf, f = fm.findFragmentByTag("call_fragment"); boolean replace = true; if |
| 328 | * (newState.equals("INCOMING") && !(f instanceof IncomingCallFragment)) { newf = new IncomingCallFragment(); } else if |
| 329 | * (!newState.equals("INCOMING") && !(f instanceof OngoingCallFragment)) { newf = new OngoingCallFragment(); } else { replace = false; newf = |
| 330 | * f; } |
| 331 | * |
| 332 | * ((CallFragment) newf).setCall(mCall); |
| 333 | * |
| 334 | * if (replace) { FragmentTransaction ft = fm.beginTransaction(); if(f != null) // do not animate if there is no previous fragment |
| 335 | * ft.setCustomAnimations(R.animator.slide_in, R.animator.slide_out); //ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
| 336 | * ft.replace(R.id.fragment_layout, newf, "call_fragment").commit(); } |
| 337 | */ |
| 338 | } |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 339 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 340 | public void onCallAccepted() { |
| 341 | mCall.notifyServiceAnswer(service); |
| 342 | } |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 343 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 344 | public void onCallRejected() { |
| 345 | if (mCall.notifyServiceHangup(service)) |
| 346 | finish(); |
| 347 | } |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 348 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 349 | public void onCallEnded() { |
| 350 | if (mCall.notifyServiceHangup(service)) |
| 351 | finish(); |
| 352 | } |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 353 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 354 | public void onCallSuspended() { |
| 355 | mCall.notifyServiceHold(service); |
| 356 | } |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 357 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 358 | public void onCallResumed() { |
| 359 | mCall.notifyServiceUnhold(service); |
| 360 | } |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 361 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 362 | public void onCalltransfered(String to) { |
| 363 | mCall.notifyServiceTransfer(service, to); |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 364 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 365 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 366 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 367 | public void onRecordCall() { |
| 368 | mCall.notifyServiceRecord(service); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 369 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 370 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 371 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 372 | public void onSendMessage(String msg) { |
| 373 | mCall.notifyServiceSendMsg(service, msg); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 374 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 375 | } |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 376 | |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 377 | } |