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