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> |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 6 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | * |
| 22 | * Additional permission under GNU GPL version 3 section 7: |
| 23 | * |
| 24 | * If you modify this program, or any covered work, by linking or |
| 25 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 26 | * modified version of that library), containing parts covered by the |
| 27 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 28 | * grants you additional permission to convey the resulting work. |
| 29 | * Corresponding Source for a non-source form of such a combination |
| 30 | * shall include the source code for the parts of OpenSSL used as well |
| 31 | * as that of the covered work. |
| 32 | */ |
| 33 | |
| 34 | package com.savoirfairelinux.sflphone.client; |
| 35 | |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 36 | import java.util.concurrent.ExecutorService; |
| 37 | import java.util.concurrent.Executors; |
| 38 | |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 39 | import android.app.Activity; |
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; |
alision | 84813a1 | 2013-05-27 17:40:39 -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; |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 46 | import android.os.Environment; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 47 | import android.os.IBinder; |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 48 | import android.os.RemoteException; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 49 | import android.support.v4.view.ViewPager; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 50 | import android.support.v4.widget.SlidingPaneLayout; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 51 | import android.util.Log; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 52 | import android.view.View; |
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; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 56 | import com.savoirfairelinux.sflphone.client.receiver.CallReceiver; |
| 57 | import com.savoirfairelinux.sflphone.fragments.CallFragment; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 58 | import com.savoirfairelinux.sflphone.fragments.CallListFragment; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 59 | import com.savoirfairelinux.sflphone.interfaces.CallInterface; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 60 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 61 | import com.savoirfairelinux.sflphone.model.SipCall.state; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 62 | import com.savoirfairelinux.sflphone.service.CallManagerCallBack; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 63 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 64 | import com.savoirfairelinux.sflphone.service.SipService; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 65 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 66 | public class CallActivity extends Activity implements CallInterface, CallFragment.Callbacks, CallListFragment.Callbacks { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 67 | static final String TAG = "CallActivity"; |
| 68 | private ISipService service; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 69 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 70 | private String pendingAction = null; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 71 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 72 | private ExecutorService infos_fetcher = Executors.newCachedThreadPool(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 73 | CallReceiver receiver; |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 74 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 75 | CallListFragment mCallsFragment; |
| 76 | CallFragment mCurrentCallFragment; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 77 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 78 | // private CallPagerAdapter mCallPagerAdapter; |
| 79 | // private ViewPager mViewPager; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 80 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 81 | /* |
| 82 | * private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { |
| 83 | * |
| 84 | * @Override public void onReceive(Context context, Intent intent) { String signalName = intent.getStringExtra(CallManagerCallBack.SIGNAL_NAME); |
| 85 | * Log.d(TAG, "Signal received: " + signalName); |
| 86 | * |
| 87 | * if (signalName.equals(CallManagerCallBack.NEW_CALL_CREATED)) { } else if (signalName.equals(CallManagerCallBack.CALL_STATE_CHANGED)) { |
| 88 | * processCallStateChangedSignal(intent); } else if (signalName.equals(CallManagerCallBack.INCOMING_CALL)) { } } }; |
| 89 | */ |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 90 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 91 | @Override |
| 92 | protected void onCreate(Bundle savedInstanceState) { |
| 93 | super.onCreate(savedInstanceState); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 94 | setContentView(R.layout.activity_call_layout); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 95 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 96 | receiver = new CallReceiver(this); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 97 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 98 | mCallsFragment = new CallListFragment(); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 99 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 100 | getFragmentManager().beginTransaction().replace(R.id.calllist_pane, mCallsFragment).commit(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 101 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 102 | final SlidingPaneLayout slidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.slidingpanelayout); |
| 103 | slidingPaneLayout.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() { |
| 104 | |
| 105 | @Override |
| 106 | public void onPanelSlide(View view, float offSet) { |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void onPanelOpened(View view) { |
| 111 | |
| 112 | switch (view.getId()) { |
| 113 | case R.id.calllist_pane: |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 114 | // getFragmentManager().findFragmentById(R.id.calllist_pane).setHasOptionsMenu(true); |
| 115 | // getFragmentManager().findFragmentById(R.id.ongoingcall_pane).setHasOptionsMenu(false); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 116 | break; |
| 117 | default: |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public void onPanelClosed(View view) { |
| 124 | |
| 125 | switch (view.getId()) { |
| 126 | case R.id.ongoingcall_pane: |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 127 | // getFragmentManager().findFragmentById(R.id.calllist_pane).setHasOptionsMenu(false); |
| 128 | // getFragmentManager().findFragmentById(R.id.ongoingcall_pane).setHasOptionsMenu(true); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 129 | break; |
| 130 | default: |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | }); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 135 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 136 | Bundle b = getIntent().getExtras(); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 137 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 138 | Intent intent = new Intent(this, SipService.class); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 139 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 140 | // setCallStateDisplay(mCall.getCallStateString()); |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 141 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 142 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 143 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 144 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 145 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 146 | /* activity gets back to the foreground and user input */ |
| 147 | @Override |
| 148 | protected void onResume() { |
| 149 | Log.i(TAG, "onResume"); |
| 150 | IntentFilter intentFilter = new IntentFilter(); |
| 151 | intentFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 152 | intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
| 153 | intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); |
| 154 | registerReceiver(receiver, intentFilter); |
| 155 | super.onResume(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 156 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 157 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 158 | /* activity no more in foreground */ |
| 159 | @Override |
| 160 | protected void onPause() { |
| 161 | super.onPause(); |
| 162 | unregisterReceiver(receiver); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 163 | } |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 164 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 165 | @Override |
| 166 | protected void onDestroy() { |
| 167 | // Log.i(TAG, "Destroying Call Activity for call " + mCall.getCallId()); |
| 168 | // LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver); |
| 169 | unbindService(mConnection); |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 170 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 171 | super.onDestroy(); |
| 172 | } |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 173 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 174 | /** Defines callbacks for service binding, passed to bindService() */ |
| 175 | private ServiceConnection mConnection = new ServiceConnection() { |
| 176 | @Override |
| 177 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 178 | service = ISipService.Stub.asInterface(binder); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 179 | Log.i(TAG, "Placing call"); |
| 180 | mCurrentCallFragment = new CallFragment(); |
| 181 | mCurrentCallFragment.setArguments(getIntent().getExtras()); |
| 182 | getIntent().getExtras(); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 183 | // SipCall info = getIntent().getExtras().getParcelable("CallInfo"); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 184 | // mCallPagerAdapter.addCall(info.mCallID, newCall); |
| 185 | getFragmentManager().beginTransaction().replace(R.id.ongoingcall_pane, mCurrentCallFragment).commit(); |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 186 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 187 | } |
Alexandre Savard | e41f521 | 2012-10-26 14:23:50 -0400 | [diff] [blame] | 188 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 189 | @Override |
| 190 | public void onServiceDisconnected(ComponentName arg0) { |
| 191 | } |
| 192 | }; |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 193 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 194 | @Override |
| 195 | public void incomingCall(Intent call) { |
| 196 | Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show(); |
| 197 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 198 | mCallsFragment.update(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 199 | |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public void callStateChanged(Intent callState) { |
| 204 | |
| 205 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 206 | processCallStateChangedSignal(b.getString("CallID"), b.getString("State")); |
| 207 | |
| 208 | } |
| 209 | |
| 210 | public void processCallStateChangedSignal(String callID, String newState) { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 211 | /* |
| 212 | * Bundle bundle = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); String callID = bundle.getString("CallID"); String |
| 213 | * newState = bundle.getString("State"); |
| 214 | */ |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 215 | // CallFragment fr = mCurrentCallFragment; |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 216 | |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 217 | mCallsFragment.update(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 218 | |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 219 | // if (newState.equals("INCOMING")) { |
| 220 | // fr.changeCallState(SipCall.state.CALL_STATE_INCOMING); |
| 221 | // |
| 222 | // } else if (newState.equals("RINGING")) { |
| 223 | // fr.changeCallState(SipCall.state.CALL_STATE_RINGING); |
| 224 | // |
| 225 | // } else if (newState.equals("CURRENT")) { |
| 226 | // fr.changeCallState(SipCall.state.CALL_STATE_CURRENT); |
| 227 | // |
| 228 | // } else if (newState.equals("HUNGUP")) { |
| 229 | // // mCallPagerAdapter.remove(callID); |
| 230 | // // if (mCallPagerAdapter.getCount() == 0) { |
| 231 | // // finish(); |
| 232 | // // } |
| 233 | // |
| 234 | // } else if (newState.equals("BUSY")) { |
| 235 | // // mCallPagerAdapter.remove(callID); |
| 236 | // // if (mCallPagerAdapter.getCount() == 0) { |
| 237 | // // finish(); |
| 238 | // // } |
| 239 | // |
| 240 | // } else if (newState.equals("FAILURE")) { |
| 241 | // // mCallPagerAdapter.remove(callID); |
| 242 | // // if (mCallPagerAdapter.getCount() == 0) { |
| 243 | // // finish(); |
| 244 | // // } |
| 245 | // |
| 246 | // } else if (newState.equals("HOLD")) { |
| 247 | // fr.changeCallState(SipCall.state.CALL_STATE_HOLD); |
| 248 | // |
| 249 | // } else if (newState.equals("UNHOLD")) { |
| 250 | // fr.changeCallState(SipCall.state.CALL_STATE_CURRENT); |
| 251 | // |
| 252 | // } else { |
| 253 | // fr.changeCallState(SipCall.state.CALL_STATE_NONE); |
| 254 | // |
| 255 | // } |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 256 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 257 | Log.w(TAG, "processCallStateChangedSignal " + newState); |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 258 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 259 | } |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 260 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 261 | @Override |
| 262 | public void incomingText(Intent msg) { |
| 263 | Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show(); |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 264 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 265 | // TODO link text message to associate call and display it at the right place |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 266 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 267 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 268 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 269 | @Override |
| 270 | public ISipService getService() { |
| 271 | return service; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 272 | } |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 273 | |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame^] | 274 | @Override |
| 275 | public void onCallSelected(SipCall call) { |
| 276 | mCurrentCallFragment = new CallFragment(); |
| 277 | Bundle b = new Bundle(); |
| 278 | b.putParcelable("CallInfo", call); |
| 279 | mCurrentCallFragment.setArguments(b); |
| 280 | getFragmentManager().beginTransaction().replace(R.id.ongoingcall_pane, mCurrentCallFragment).commit(); |
| 281 | |
| 282 | } |
| 283 | |
| 284 | @Override |
| 285 | public void callContact(SipCall call) { |
| 286 | try { |
| 287 | service.placeCall(call); |
| 288 | } catch (RemoteException e) { |
| 289 | Log.e(TAG, "Cannot call service method", e); |
| 290 | } |
| 291 | |
| 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public void onCallAccepted(SipCall call) { |
| 296 | int callState = call.getCallStateInt(); |
| 297 | if ((callState != state.CALL_STATE_RINGING) && (callState != state.CALL_STATE_NONE)) { |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | try { |
| 302 | service.accept(call.getCallId()); |
| 303 | } catch (RemoteException e) { |
| 304 | Log.e(TAG, "Cannot call service method", e); |
| 305 | } |
| 306 | |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void onCallRejected(SipCall call) { |
| 311 | try { |
| 312 | if (call.getCallStateInt() == state.CALL_STATE_RINGING) { |
| 313 | service.refuse(call.getCallId()); |
| 314 | return; |
| 315 | } |
| 316 | } catch (RemoteException e) { |
| 317 | Log.e(TAG, "Cannot call service method", e); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public void onCallEnded(SipCall call) { |
| 323 | try { |
| 324 | if ((call.getCallStateInt() == state.CALL_STATE_NONE) || (call.getCallStateInt() == state.CALL_STATE_CURRENT) |
| 325 | || (call.getCallStateInt() == state.CALL_STATE_HOLD)) { |
| 326 | service.hangUp(call.getCallId()); |
| 327 | return; |
| 328 | |
| 329 | } else if (call.getCallStateInt() == state.CALL_STATE_RINGING) { |
| 330 | if (call.getCallType() == state.CALL_TYPE_INCOMING) { |
| 331 | service.refuse(call.getCallId()); |
| 332 | return; |
| 333 | } else if (call.getCallType() == state.CALL_TYPE_OUTGOING) { |
| 334 | service.hangUp(call.getCallId()); |
| 335 | return; |
| 336 | } |
| 337 | } |
| 338 | } catch (RemoteException e) { |
| 339 | Log.e(TAG, "Cannot call service method", e); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | @Override |
| 344 | public void onCallSuspended(SipCall call) { |
| 345 | try { |
| 346 | if (call.getCallStateInt() == state.CALL_STATE_CURRENT) { |
| 347 | service.hold(call.getCallId()); |
| 348 | return; |
| 349 | } |
| 350 | } catch (RemoteException e) { |
| 351 | Log.e(TAG, "Cannot call service method", e); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public void onCallResumed(SipCall call) { |
| 357 | try { |
| 358 | if (call.getCallStateInt() == state.CALL_STATE_HOLD) { |
| 359 | service.unhold(call.getCallId()); |
| 360 | return; |
| 361 | } |
| 362 | } catch (RemoteException e) { |
| 363 | Log.e(TAG, "Cannot call service method", e); |
| 364 | } |
| 365 | |
| 366 | |
| 367 | } |
| 368 | |
| 369 | @Override |
| 370 | public void onCalltransfered(SipCall call,String to) { |
| 371 | try { |
| 372 | if (call.getCallStateInt() == state.CALL_STATE_CURRENT) { |
| 373 | service.transfer(call.getCallId(), to); |
| 374 | } |
| 375 | } catch (RemoteException e) { |
| 376 | Log.e(TAG, "Cannot call service method", e); |
| 377 | } |
| 378 | |
| 379 | } |
| 380 | |
| 381 | @Override |
| 382 | public void onRecordCall(SipCall call) { |
| 383 | try { |
| 384 | if (call.getCallStateInt() == state.CALL_STATE_CURRENT) { |
| 385 | service.setRecordPath(Environment.getExternalStorageDirectory().getAbsolutePath()); |
| 386 | Log.w(TAG, "Recording path" + service.getRecordPath()); |
| 387 | service.setRecordingCall(call.getCallId()); |
| 388 | } |
| 389 | } catch (RemoteException e) { |
| 390 | Log.e(TAG, "Cannot call service method", e); |
| 391 | } |
| 392 | |
| 393 | } |
| 394 | |
| 395 | @Override |
| 396 | public void onSendMessage(SipCall call, String msg) { |
| 397 | try { |
| 398 | if (call.getCallStateInt() == state.CALL_STATE_CURRENT) { |
| 399 | service.sendTextMessage(call.getCallId(), msg, "Me"); |
| 400 | } |
| 401 | } catch (RemoteException e) { |
| 402 | Log.e(TAG, "Cannot call service method", e); |
| 403 | } |
| 404 | |
| 405 | } |
| 406 | |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 407 | } |