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 | |
| 35 | import android.app.Activity; |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 36 | import android.app.Fragment; |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 37 | import android.app.FragmentManager; |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 38 | import android.app.FragmentTransaction; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 39 | import android.content.BroadcastReceiver; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 40 | import android.content.ComponentName; |
alision | 17052d4 | 2013-04-22 10:39:38 -0400 | [diff] [blame] | 41 | import android.content.Context; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 42 | import android.content.Intent; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 43 | import android.content.IntentFilter; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 44 | import android.content.ServiceConnection; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 45 | import android.os.Bundle; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 46 | import android.os.IBinder; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 47 | import android.support.v4.content.LocalBroadcastManager; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 48 | import android.util.Log; |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 49 | import android.view.LayoutInflater; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 50 | import android.view.View; |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 51 | import android.view.ViewGroup; |
| 52 | import android.widget.EditText; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 53 | |
| 54 | import com.savoirfairelinux.sflphone.R; |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 55 | import com.savoirfairelinux.sflphone.fragments.IncomingCallFragment; |
| 56 | import com.savoirfairelinux.sflphone.fragments.OngoingCallFragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 57 | import com.savoirfairelinux.sflphone.model.SipCall; |
Alexandre Savard | 3bdce7b | 2012-10-24 18:27:45 -0400 | [diff] [blame] | 58 | import com.savoirfairelinux.sflphone.service.CallManagerCallBack; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 59 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 60 | import com.savoirfairelinux.sflphone.service.SipService; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 61 | |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 62 | public class CallActivity extends Activity //implements IncomingCallFragment.ICallActionListener, OngoingCallFragment.ICallActionListener //OnClickListener |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 63 | { |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 64 | static final String TAG = "CallActivity"; |
| 65 | private ISipService service; |
| 66 | private SipCall mCall; |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 67 | |
| 68 | public interface CallFragment |
| 69 | { |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 70 | void setCall(SipCall c); |
| 71 | } |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 72 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 73 | private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { |
| 74 | @Override |
| 75 | public void onReceive(Context context, Intent intent) |
| 76 | { |
| 77 | String signalName = intent.getStringExtra(CallManagerCallBack.SIGNAL_NAME); |
| 78 | Log.d(TAG, "Signal received: " + signalName); |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 79 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 80 | if (signalName.equals(CallManagerCallBack.NEW_CALL_CREATED)) { |
| 81 | } else if (signalName.equals(CallManagerCallBack.CALL_STATE_CHANGED)) { |
| 82 | processCallStateChangedSignal(intent); |
| 83 | } else if (signalName.equals(CallManagerCallBack.INCOMING_CALL)) { |
| 84 | } |
| 85 | } |
| 86 | }; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 87 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 88 | @Override |
| 89 | protected void onCreate(Bundle savedInstanceState) |
| 90 | { |
| 91 | super.onCreate(savedInstanceState); |
| 92 | setContentView(R.layout.activity_call_layout); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 93 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 94 | Bundle b = getIntent().getExtras(); |
| 95 | // Parcelable value = b.getParcelable("CallInfo"); |
| 96 | SipCall.CallInfo info = b.getParcelable("CallInfo"); |
| 97 | Log.i(TAG, "Starting activity for call " + info.mCallID); |
| 98 | mCall = new SipCall(info); |
Alexandre Savard | 557a574 | 2012-10-24 13:54:53 -0400 | [diff] [blame] | 99 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 100 | Intent intent = new Intent(this, SipService.class); |
| 101 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 102 | setCallStateDisplay(mCall.getCallStateString()); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 103 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 104 | LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED)); |
| 105 | LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.CALL_STATE_CHANGED)); |
| 106 | LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter(CallManagerCallBack.INCOMING_CALL)); |
| 107 | } |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 108 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 109 | @Override |
| 110 | protected void onDestroy() |
| 111 | { |
| 112 | Log.i(TAG, "Destroying Call Activity for call " + mCall.getCallId()); |
| 113 | LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver); |
| 114 | unbindService(mConnection); |
| 115 | super.onDestroy(); |
| 116 | } |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 117 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 118 | /** Defines callbacks for service binding, passed to bindService() */ |
| 119 | private ServiceConnection mConnection = new ServiceConnection() { |
| 120 | @Override |
| 121 | public void onServiceConnected(ComponentName className, IBinder binder) |
| 122 | { |
| 123 | service = ISipService.Stub.asInterface(binder); |
| 124 | } |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 125 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 126 | @Override |
| 127 | public void onServiceDisconnected(ComponentName arg0) |
| 128 | { |
| 129 | } |
| 130 | }; |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 131 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 132 | private void processCallStateChangedSignal(Intent intent) |
| 133 | { |
| 134 | Bundle bundle = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 135 | String callID = bundle.getString("CallID"); |
| 136 | String newState = bundle.getString("State"); |
Alexandre Savard | e41f521 | 2012-10-26 14:23:50 -0400 | [diff] [blame] | 137 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 138 | if (newState.equals("INCOMING")) { |
| 139 | mCall.setCallState(SipCall.CALL_STATE_INCOMING); |
| 140 | setCallStateDisplay(newState); |
| 141 | } else if (newState.equals("RINGING")) { |
| 142 | mCall.setCallState(SipCall.CALL_STATE_RINGING); |
| 143 | setCallStateDisplay(newState); |
| 144 | } else if (newState.equals("CURRENT")) { |
| 145 | mCall.setCallState(SipCall.CALL_STATE_CURRENT); |
| 146 | setCallStateDisplay(newState); |
| 147 | } else if (newState.equals("HUNGUP")) { |
| 148 | mCall.setCallState(SipCall.CALL_STATE_HUNGUP); |
| 149 | setCallStateDisplay(newState); |
| 150 | finish(); |
| 151 | } else if (newState.equals("BUSY")) { |
| 152 | mCall.setCallState(SipCall.CALL_STATE_BUSY); |
| 153 | setCallStateDisplay(newState); |
| 154 | } else if (newState.equals("FAILURE")) { |
| 155 | mCall.setCallState(SipCall.CALL_STATE_FAILURE); |
| 156 | setCallStateDisplay(newState); |
| 157 | } else if (newState.equals("HOLD")) { |
| 158 | mCall.setCallState(SipCall.CALL_STATE_HOLD); |
| 159 | setCallStateDisplay(newState); |
| 160 | } else if (newState.equals("UNHOLD")) { |
| 161 | mCall.setCallState(SipCall.CALL_STATE_CURRENT); |
| 162 | setCallStateDisplay("CURRENT"); |
| 163 | } else { |
| 164 | mCall.setCallState(SipCall.CALL_STATE_NONE); |
| 165 | setCallStateDisplay(newState); |
| 166 | } |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 167 | |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 168 | Log.w(TAG, "processCallStateChangedSignal " + newState); |
| 169 | |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | private void setCallStateDisplay(String newState) |
| 173 | { |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 174 | if (newState == null || newState.equals("NULL")) { |
| 175 | newState = "INCOMING"; |
| 176 | } |
| 177 | |
| 178 | Log.w(TAG, "setCallStateDisplay " + newState); |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 179 | |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 180 | mCall.printCallInfo(); |
| 181 | |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 182 | FragmentManager fm = getFragmentManager(); |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 183 | Fragment newf, f = fm.findFragmentByTag("call_fragment"); |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 184 | boolean replace = true; |
| 185 | if (newState.equals("INCOMING") && !(f instanceof IncomingCallFragment)) { |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 186 | newf = new IncomingCallFragment(); |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 187 | } else if (!newState.equals("INCOMING") && !(f instanceof OngoingCallFragment)) { |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 188 | newf = new OngoingCallFragment(); |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 189 | } else { |
| 190 | replace = false; |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 191 | newf = f; |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 192 | } |
Adrien Béraud | 7b50ba2 | 2013-04-26 23:57:43 +1000 | [diff] [blame] | 193 | |
| 194 | ((CallFragment) newf).setCall(mCall); |
| 195 | |
| 196 | if (replace) { |
| 197 | FragmentTransaction ft = fm.beginTransaction(); |
| 198 | if(f != null) // do not animate if there is no previous fragment |
| 199 | ft.setCustomAnimations(R.animator.slide_in, R.animator.slide_out); |
| 200 | //ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
| 201 | ft.replace(R.id.fragment_layout, newf, "call_fragment").commit(); |
| 202 | } |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 203 | } |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 204 | |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 205 | public void onCallAccepted() |
| 206 | { |
| 207 | mCall.notifyServiceAnswer(service); |
| 208 | } |
| 209 | |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 210 | public void onCallRejected() |
| 211 | { |
| 212 | if (mCall.notifyServiceHangup(service)) |
| 213 | finish(); |
| 214 | } |
| 215 | |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 216 | public void onCallEnded() |
| 217 | { |
| 218 | if (mCall.notifyServiceHangup(service)) |
| 219 | finish(); |
| 220 | } |
| 221 | |
| 222 | public void onCallSuspended() |
| 223 | { |
| 224 | mCall.notifyServiceHold(service); |
| 225 | } |
| 226 | |
| 227 | public void onCallResumed() |
| 228 | { |
| 229 | mCall.notifyServiceUnhold(service); |
| 230 | } |
| 231 | |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 232 | public void onCalltransfered(String to) { |
| 233 | mCall.notifyServiceTransfer(service, to); |
| 234 | |
| 235 | } |
| 236 | |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame^] | 237 | public void onRecordCall() { |
| 238 | mCall.notifyServiceRecord(service); |
| 239 | |
| 240 | } |
| 241 | |
| 242 | public void onSendMessage(String msg) { |
| 243 | mCall.notifyServiceSendMsg(service,msg); |
| 244 | |
| 245 | } |
| 246 | |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 247 | } |