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 | |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 36 | import java.util.HashMap; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 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; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 44 | import android.content.IntentFilter; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 45 | import android.content.ServiceConnection; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 46 | import android.os.Bundle; |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 47 | import android.os.Environment; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 48 | import android.os.IBinder; |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 49 | import android.os.RemoteException; |
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 | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 60 | import com.savoirfairelinux.sflphone.model.CallContact; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 61 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 62 | import com.savoirfairelinux.sflphone.model.SipCall.state; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 63 | import com.savoirfairelinux.sflphone.service.CallManagerCallBack; |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 64 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 65 | import com.savoirfairelinux.sflphone.service.SipService; |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 66 | import com.savoirfairelinux.sflphone.views.CallPaneLayout; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 67 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 68 | public class CallActivity extends Activity implements CallInterface, CallFragment.Callbacks, CallListFragment.Callbacks { |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 69 | static final String TAG = "CallActivity"; |
| 70 | private ISipService service; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 71 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 72 | private String pendingAction = null; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 73 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 74 | private ExecutorService infos_fetcher = Executors.newCachedThreadPool(); |
| 75 | CallReceiver receiver; |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 76 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 77 | CallPaneLayout slidingPaneLayout; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 78 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 79 | CallListFragment mCallsFragment; |
| 80 | CallFragment mCurrentCallFragment; |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 81 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 82 | @Override |
| 83 | protected void onCreate(Bundle savedInstanceState) { |
| 84 | super.onCreate(savedInstanceState); |
| 85 | setContentView(R.layout.activity_call_layout); |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 86 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 87 | receiver = new CallReceiver(this); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 88 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 89 | mCallsFragment = new CallListFragment(); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 90 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 91 | getFragmentManager().beginTransaction().replace(R.id.calllist_pane, mCallsFragment).commit(); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 92 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 93 | slidingPaneLayout = (CallPaneLayout) findViewById(R.id.slidingpanelayout); |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 94 | //slidingPaneLayout. |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 95 | // slidingPaneLayout.requestDisallowInterceptTouchEvent(disallowIntercept) |
| 96 | slidingPaneLayout.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 97 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 98 | @Override |
| 99 | public void onPanelSlide(View view, float offSet) { |
| 100 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 101 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 102 | @Override |
| 103 | public void onPanelOpened(View view) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 104 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 105 | switch (view.getId()) { |
| 106 | case R.id.calllist_pane: |
| 107 | // getFragmentManager().findFragmentById(R.id.calllist_pane).setHasOptionsMenu(true); |
| 108 | // getFragmentManager().findFragmentById(R.id.ongoingcall_pane).setHasOptionsMenu(false); |
| 109 | break; |
| 110 | default: |
| 111 | break; |
| 112 | } |
| 113 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 114 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 115 | @Override |
| 116 | public void onPanelClosed(View view) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 117 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 118 | switch (view.getId()) { |
| 119 | case R.id.ongoingcall_pane: |
| 120 | // getFragmentManager().findFragmentById(R.id.calllist_pane).setHasOptionsMenu(false); |
| 121 | // getFragmentManager().findFragmentById(R.id.ongoingcall_pane).setHasOptionsMenu(true); |
| 122 | break; |
| 123 | default: |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | }); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 128 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 129 | Bundle b = getIntent().getExtras(); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 130 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 131 | Intent intent = new Intent(this, SipService.class); |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 132 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 133 | // setCallStateDisplay(mCall.getCallStateString()); |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 134 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 135 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 136 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 137 | } |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 138 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 139 | /* activity gets back to the foreground and user input */ |
| 140 | @Override |
| 141 | protected void onResume() { |
| 142 | Log.i(TAG, "onResume"); |
| 143 | IntentFilter intentFilter = new IntentFilter(); |
| 144 | intentFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 145 | intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
| 146 | intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); |
| 147 | registerReceiver(receiver, intentFilter); |
| 148 | super.onResume(); |
| 149 | } |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 150 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 151 | /* activity no more in foreground */ |
| 152 | @Override |
| 153 | protected void onPause() { |
| 154 | super.onPause(); |
| 155 | unregisterReceiver(receiver); |
| 156 | } |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 157 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 158 | @Override |
| 159 | protected void onDestroy() { |
| 160 | // Log.i(TAG, "Destroying Call Activity for call " + mCall.getCallId()); |
| 161 | // LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver); |
| 162 | unbindService(mConnection); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 163 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 164 | super.onDestroy(); |
| 165 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 166 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 167 | /** Defines callbacks for service binding, passed to bindService() */ |
| 168 | private ServiceConnection mConnection = new ServiceConnection() { |
| 169 | @Override |
| 170 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 171 | service = ISipService.Stub.asInterface(binder); |
| 172 | Log.i(TAG, "Placing call"); |
| 173 | mCurrentCallFragment = new CallFragment(); |
| 174 | mCurrentCallFragment.setArguments(getIntent().getExtras()); |
| 175 | slidingPaneLayout.curFragment = mCurrentCallFragment; |
| 176 | getIntent().getExtras(); |
| 177 | // SipCall info = getIntent().getExtras().getParcelable("CallInfo"); |
| 178 | // mCallPagerAdapter.addCall(info.mCallID, newCall); |
| 179 | getFragmentManager().beginTransaction().replace(R.id.ongoingcall_pane, mCurrentCallFragment).commit(); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 180 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 181 | } |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame] | 182 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 183 | @Override |
| 184 | public void onServiceDisconnected(ComponentName arg0) { |
| 185 | } |
| 186 | }; |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 187 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 188 | @Override |
| 189 | public void incomingCall(Intent call) { |
| 190 | Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show(); |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 191 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 192 | mCallsFragment.update(); |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 193 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 194 | } |
Alexandre Savard | e41f521 | 2012-10-26 14:23:50 -0400 | [diff] [blame] | 195 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 196 | @Override |
| 197 | public void callStateChanged(Intent callState) { |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 198 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 199 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 200 | processCallStateChangedSignal(b.getString("CallID"), b.getString("State")); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 201 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 202 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 203 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 204 | public void processCallStateChangedSignal(String callID, String newState) { |
| 205 | /* |
| 206 | * Bundle bundle = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); String callID = bundle.getString("CallID"); String |
| 207 | * newState = bundle.getString("State"); |
| 208 | */ |
| 209 | // CallFragment fr = mCurrentCallFragment; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 210 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 211 | mCallsFragment.update(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 212 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 213 | mCurrentCallFragment.changeCallState(callID, newState); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 214 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 215 | HashMap<String, SipCall> map; |
| 216 | try { |
| 217 | map = (HashMap<String, SipCall>) service.getCallList(); |
| 218 | if(map.size() == 0){ |
| 219 | finish(); |
| 220 | } |
| 221 | } catch (RemoteException e) { |
| 222 | Log.e(TAG, e.toString()); |
| 223 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 224 | |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 225 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 226 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 227 | // if (newState.equals("INCOMING")) { |
| 228 | // fr.changeCallState(SipCall.state.CALL_STATE_INCOMING); |
| 229 | // |
| 230 | // } else if (newState.equals("RINGING")) { |
| 231 | // fr.changeCallState(SipCall.state.CALL_STATE_RINGING); |
| 232 | // |
| 233 | // } else if (newState.equals("CURRENT")) { |
| 234 | // fr.changeCallState(SipCall.state.CALL_STATE_CURRENT); |
| 235 | // |
| 236 | // } else if (newState.equals("HUNGUP")) { |
| 237 | // // mCallPagerAdapter.remove(callID); |
| 238 | // // if (mCallPagerAdapter.getCount() == 0) { |
| 239 | // // finish(); |
| 240 | // // } |
| 241 | // |
| 242 | // } else if (newState.equals("BUSY")) { |
| 243 | // // mCallPagerAdapter.remove(callID); |
| 244 | // // if (mCallPagerAdapter.getCount() == 0) { |
| 245 | // // finish(); |
| 246 | // // } |
| 247 | // |
| 248 | // } else if (newState.equals("FAILURE")) { |
| 249 | // // mCallPagerAdapter.remove(callID); |
| 250 | // // if (mCallPagerAdapter.getCount() == 0) { |
| 251 | // // finish(); |
| 252 | // // } |
| 253 | // |
| 254 | // } else if (newState.equals("HOLD")) { |
| 255 | // fr.changeCallState(SipCall.state.CALL_STATE_HOLD); |
| 256 | // |
| 257 | // } else if (newState.equals("UNHOLD")) { |
| 258 | // fr.changeCallState(SipCall.state.CALL_STATE_CURRENT); |
| 259 | // |
| 260 | // } else { |
| 261 | // fr.changeCallState(SipCall.state.CALL_STATE_NONE); |
| 262 | // |
| 263 | // } |
Adrien Béraud | c99b843 | 2013-04-25 16:27:46 +1000 | [diff] [blame] | 264 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 265 | Log.w(TAG, "processCallStateChangedSignal " + newState); |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 266 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 267 | } |
Adrien Béraud | 71b2f81 | 2013-04-26 18:51:02 +1000 | [diff] [blame] | 268 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 269 | @Override |
| 270 | public void incomingText(Intent msg) { |
| 271 | Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show(); |
Adrien Béraud | 2955604 | 2013-04-26 17:35:43 +1000 | [diff] [blame] | 272 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 273 | // 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] | 274 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 275 | } |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 276 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 277 | @Override |
| 278 | public ISipService getService() { |
| 279 | return service; |
| 280 | } |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 281 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 282 | @Override |
| 283 | public void onCallSelected(SipCall call) { |
| 284 | mCurrentCallFragment = new CallFragment(); |
| 285 | Bundle b = new Bundle(); |
| 286 | b.putParcelable("CallInfo", call); |
| 287 | mCurrentCallFragment.setArguments(b); |
| 288 | getFragmentManager().beginTransaction().replace(R.id.ongoingcall_pane, mCurrentCallFragment).commit(); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 289 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 290 | slidingPaneLayout.curFragment = mCurrentCallFragment; |
| 291 | slidingPaneLayout.openPane(); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 292 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 293 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 294 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 295 | @Override |
| 296 | public void callContact(SipCall call) { |
| 297 | try { |
| 298 | service.placeCall(call); |
| 299 | } catch (RemoteException e) { |
| 300 | Log.e(TAG, "Cannot call service method", e); |
| 301 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 302 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 303 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 304 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 305 | @Override |
| 306 | public void onCallAccepted(SipCall call) { |
| 307 | int callState = call.getCallStateInt(); |
| 308 | if (callState != state.CALL_STATE_RINGING && callState != state.CALL_STATE_NONE) { |
| 309 | return; |
| 310 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 311 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 312 | try { |
| 313 | service.accept(call.getCallId()); |
| 314 | } catch (RemoteException e) { |
| 315 | Log.e(TAG, "Cannot call service method", e); |
| 316 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 317 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 318 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 319 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 320 | @Override |
| 321 | public void onCallRejected(SipCall call) { |
| 322 | try { |
| 323 | if (call.getCallStateInt() == state.CALL_STATE_RINGING) { |
| 324 | service.refuse(call.getCallId()); |
| 325 | return; |
| 326 | } |
| 327 | } catch (RemoteException e) { |
| 328 | Log.e(TAG, "Cannot call service method", e); |
| 329 | } |
| 330 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 331 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 332 | @Override |
| 333 | public void onCallEnded(SipCall call) { |
| 334 | try { |
| 335 | if (call.getCallStateInt() == state.CALL_STATE_NONE || call.getCallStateInt() == state.CALL_STATE_CURRENT |
| 336 | || call.getCallStateInt() == state.CALL_STATE_HOLD) { |
| 337 | service.hangUp(call.getCallId()); |
| 338 | return; |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 339 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 340 | } else if (call.getCallStateInt() == state.CALL_STATE_RINGING) { |
| 341 | if (call.getCallType() == state.CALL_TYPE_INCOMING) { |
| 342 | service.refuse(call.getCallId()); |
| 343 | return; |
| 344 | } else if (call.getCallType() == state.CALL_TYPE_OUTGOING) { |
| 345 | service.hangUp(call.getCallId()); |
| 346 | return; |
| 347 | } |
| 348 | } |
| 349 | } catch (RemoteException e) { |
| 350 | Log.e(TAG, "Cannot call service method", e); |
| 351 | } |
| 352 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 353 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 354 | @Override |
| 355 | public void onCallSuspended(SipCall call) { |
| 356 | try { |
| 357 | if (call.getCallStateInt() == state.CALL_STATE_CURRENT) { |
| 358 | service.hold(call.getCallId()); |
| 359 | return; |
| 360 | } |
| 361 | } catch (RemoteException e) { |
| 362 | Log.e(TAG, "Cannot call service method", e); |
| 363 | } |
| 364 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 365 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 366 | @Override |
| 367 | public void onCallResumed(SipCall call) { |
| 368 | try { |
| 369 | if (call.getCallStateInt() == state.CALL_STATE_HOLD) { |
| 370 | service.unhold(call.getCallId()); |
| 371 | return; |
| 372 | } |
| 373 | } catch (RemoteException e) { |
| 374 | Log.e(TAG, "Cannot call service method", e); |
| 375 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 376 | |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 377 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 378 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 379 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 380 | @Override |
| 381 | public void onCalltransfered(SipCall call,String to) { |
| 382 | try { |
| 383 | if (call.getCallStateInt() == state.CALL_STATE_CURRENT) { |
| 384 | service.transfer(call.getCallId(), to); |
| 385 | } |
| 386 | } catch (RemoteException e) { |
| 387 | Log.e(TAG, "Cannot call service method", e); |
| 388 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 389 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 390 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 391 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 392 | @Override |
| 393 | public void onRecordCall(SipCall call) { |
| 394 | try { |
| 395 | if (call.getCallStateInt() == state.CALL_STATE_CURRENT) { |
| 396 | service.setRecordPath(Environment.getExternalStorageDirectory().getAbsolutePath()); |
| 397 | Log.w(TAG, "Recording path" + service.getRecordPath()); |
| 398 | service.setRecordingCall(call.getCallId()); |
| 399 | } |
| 400 | } catch (RemoteException e) { |
| 401 | Log.e(TAG, "Cannot call service method", e); |
| 402 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 403 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 404 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 405 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 406 | @Override |
| 407 | public void onSendMessage(SipCall call, String msg) { |
| 408 | try { |
| 409 | if (call.getCallStateInt() == state.CALL_STATE_CURRENT) { |
| 410 | service.sendTextMessage(call.getCallId(), msg, "Me"); |
| 411 | } |
| 412 | } catch (RemoteException e) { |
| 413 | Log.e(TAG, "Cannot call service method", e); |
| 414 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 415 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 416 | } |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 417 | |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 418 | |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 419 | } |