alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 1 | /* |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 2 | * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 32 | package com.savoirfairelinux.sflphone.fragments; |
| 33 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 34 | import java.util.ArrayList; |
| 35 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 36 | import android.app.Activity; |
| 37 | import android.app.Fragment; |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 38 | import android.app.FragmentManager; |
| 39 | import android.content.Intent; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 40 | import android.graphics.Bitmap; |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 41 | import android.graphics.BitmapFactory; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 42 | import android.graphics.PointF; |
| 43 | import android.os.Bundle; |
| 44 | import android.os.RemoteException; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 45 | import android.util.Log; |
| 46 | import android.view.LayoutInflater; |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 47 | import android.view.SurfaceHolder; |
| 48 | import android.view.SurfaceHolder.Callback; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 49 | import android.view.View; |
| 50 | import android.view.ViewGroup; |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 51 | import android.widget.TextView; |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 52 | import android.widget.Toast; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 53 | |
| 54 | import com.savoirfairelinux.sflphone.R; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 55 | import com.savoirfairelinux.sflphone.model.Attractor; |
| 56 | import com.savoirfairelinux.sflphone.model.Bubble; |
| 57 | import com.savoirfairelinux.sflphone.model.BubbleModel; |
| 58 | import com.savoirfairelinux.sflphone.model.BubblesView; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 59 | import com.savoirfairelinux.sflphone.model.Conference; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 60 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 61 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 62 | |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 63 | public class CallFragment extends Fragment implements Callback { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 64 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 65 | static final String TAG = "CallFragment"; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 66 | |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 67 | float BUBBLE_SIZE = 75; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 68 | static final float ATTRACTOR_SIZE = 40; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 69 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 70 | public static final int REQUEST_TRANSFER = 10; |
| 71 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 72 | private Conference conf; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 73 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 74 | private TextView callStatusTxt; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 75 | private BubblesView view; |
| 76 | private BubbleModel model; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 77 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 78 | private Callbacks mCallbacks = sDummyCallbacks; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 79 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 80 | private SipCall myself; |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 81 | |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 82 | boolean accepted = false; |
| 83 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 84 | private Bitmap hangup_icon, transfer_icon; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 85 | private Bitmap call_icon; |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 86 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 87 | @Override |
| 88 | public void onCreate(Bundle savedBundle) { |
| 89 | super.onCreate(savedBundle); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 90 | Bundle b = getArguments(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 91 | conf = new Conference((Conference) b.getParcelable("conference")); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 92 | model = new BubbleModel(getResources().getDisplayMetrics().density); |
alision | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 93 | BUBBLE_SIZE = getResources().getDimension(R.dimen.bubble_size); |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 94 | Log.e(TAG, "BUBBLE_SIZE " + BUBBLE_SIZE); |
alision | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 95 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 96 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 97 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 98 | /** |
| 99 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 100 | */ |
| 101 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 102 | @Override |
| 103 | public void onSendMessage(SipCall call, String msg) { |
| 104 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 105 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 106 | @Override |
| 107 | public void callContact(SipCall call) { |
| 108 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 109 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 110 | @Override |
| 111 | public void onCallAccepted(SipCall call) { |
| 112 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 113 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 114 | @Override |
| 115 | public void onCallRejected(SipCall call) { |
| 116 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 117 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 118 | @Override |
| 119 | public void onCallEnded(SipCall call) { |
| 120 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 121 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 122 | @Override |
| 123 | public void onCallSuspended(SipCall call) { |
| 124 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 125 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 126 | @Override |
| 127 | public void onCallResumed(SipCall call) { |
| 128 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 129 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 130 | @Override |
| 131 | public void onCalltransfered(SipCall call, String to) { |
| 132 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 133 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 134 | @Override |
| 135 | public void onRecordCall(SipCall call) { |
| 136 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 137 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 138 | @Override |
| 139 | public ISipService getService() { |
| 140 | return null; |
| 141 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 142 | |
| 143 | @Override |
| 144 | public void replaceCurrentCallDisplayed() { |
| 145 | } |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 146 | |
| 147 | @Override |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 148 | public void startTimer() { |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 149 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 150 | }; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 151 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 152 | /** |
| 153 | * The Activity calling this fragment has to implement this interface |
| 154 | * |
| 155 | */ |
| 156 | public interface Callbacks { |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 157 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 158 | public ISipService getService(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 159 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 160 | public void callContact(SipCall call); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 161 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 162 | public void onCallAccepted(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 163 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 164 | public void onCallRejected(SipCall call); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 165 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 166 | public void onCallEnded(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 167 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 168 | public void onCallSuspended(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 169 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 170 | public void onCallResumed(SipCall call); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 171 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 172 | public void onCalltransfered(SipCall call, String to); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 173 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 174 | public void onRecordCall(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 175 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 176 | public void onSendMessage(SipCall call, String msg); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 177 | |
| 178 | public void replaceCurrentCallDisplayed(); |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 179 | |
| 180 | public void startTimer(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 181 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 182 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 183 | @Override |
| 184 | public void onAttach(Activity activity) { |
| 185 | super.onAttach(activity); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 186 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 187 | if (!(activity instanceof Callbacks)) { |
| 188 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 189 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 190 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 191 | // rootView.requestDisallowInterceptTouchEvent(true); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 192 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 193 | mCallbacks = (Callbacks) activity; |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 194 | myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me"); |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 195 | |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 196 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 197 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 198 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 199 | @Override |
| 200 | public void onDetach() { |
| 201 | super.onDetach(); |
| 202 | mCallbacks = sDummyCallbacks; |
| 203 | // rootView.requestDisallowInterceptTouchEvent(false); |
| 204 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 205 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 206 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 207 | public void onStop() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 208 | super.onStop(); |
| 209 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 210 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 211 | @Override |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 212 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 213 | super.onActivityResult(requestCode, resultCode, data); |
| 214 | SipCall transfer = null; |
| 215 | if (requestCode == REQUEST_TRANSFER) { |
| 216 | switch (resultCode) { |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 217 | case TransferDFragment.RESULT_TRANSFER_CONF: |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 218 | Conference c = data.getParcelableExtra("target"); |
| 219 | transfer = data.getParcelableExtra("transfer"); |
| 220 | try { |
| 221 | |
| 222 | mCallbacks.getService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId()); |
| 223 | |
| 224 | } catch (RemoteException e) { |
| 225 | // TODO Auto-generated catch block |
| 226 | e.printStackTrace(); |
| 227 | } |
| 228 | Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show(); |
| 229 | break; |
| 230 | |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 231 | case TransferDFragment.RESULT_TRANSFER_NUMBER: |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 232 | String to = data.getStringExtra("to_number"); |
| 233 | transfer = data.getParcelableExtra("transfer"); |
| 234 | try { |
| 235 | Toast.makeText(getActivity(), "Transferring " + transfer.getContact().getmDisplayName() + " to " + to, Toast.LENGTH_SHORT).show(); |
| 236 | mCallbacks.getService().transfer(transfer.getCallId(), to); |
| 237 | mCallbacks.getService().hangUp(transfer.getCallId()); |
| 238 | } catch (RemoteException e) { |
| 239 | // TODO Auto-generated catch block |
| 240 | e.printStackTrace(); |
| 241 | } |
| 242 | break; |
Adrien Béraud | 9751284 | 2013-09-19 13:37:19 +1000 | [diff] [blame^] | 243 | case Activity.RESULT_CANCELED: |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 244 | default: |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 245 | model.clear(); |
| 246 | initNormalStateDisplay(); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 247 | break; |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | @Override |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 253 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 254 | ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 255 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 256 | view = (BubblesView) rootView.findViewById(R.id.main_view); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 257 | view.setFragment(this); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 258 | view.setModel(model); |
| 259 | view.getHolder().addCallback(this); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 260 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 261 | callStatusTxt = (TextView) rootView.findViewById(R.id.call_status_txt); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 262 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 263 | hangup_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_hangup); |
| 264 | call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 265 | transfer_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_phones_call_transfer_icon); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 266 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 267 | // Do nothing here, the view is not initialized yet. |
| 268 | return rootView; |
| 269 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 270 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 271 | private void initNormalStateDisplay() { |
| 272 | Log.i(TAG, "Start normal display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 273 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 274 | mCallbacks.startTimer(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 275 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 276 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 277 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 278 | int angle_part = 360 / conf.getParticipants().size(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 279 | double dX = 0; |
| 280 | double dY = 0; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 281 | int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 282 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 283 | |
| 284 | if (conf.getParticipants().get(i) == null) { |
| 285 | Log.i(TAG, i + " null "); |
| 286 | continue; |
| 287 | } |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 288 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 289 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 290 | getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 291 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 292 | |
| 293 | model.clearAttractors(); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 294 | model.addAttractor(new Attractor(new PointF(model.width * .2f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 295 | @Override |
| 296 | public boolean onBubbleSucked(Bubble b) { |
| 297 | Log.w(TAG, "Bubble sucked ! "); |
| 298 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 299 | if (b.associated_call.getContact().isUser()) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 300 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 301 | try { |
| 302 | if (conf.hasMultipleParticipants()) |
| 303 | mCallbacks.getService().hangUpConference(conf.getId()); |
| 304 | else |
| 305 | mCallbacks.onCallEnded(conf.getParticipants().get(0)); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 306 | |
| 307 | model.clearAttractors(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 308 | } catch (RemoteException e) { |
| 309 | e.printStackTrace(); |
| 310 | } |
| 311 | |
| 312 | } else { |
| 313 | mCallbacks.onCallEnded(b.associated_call); |
| 314 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 315 | bubbleRemoved(b); |
| 316 | return true; |
| 317 | } |
| 318 | }, hangup_icon)); |
| 319 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 320 | model.addAttractor(new Attractor(new PointF(model.width * .8f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 321 | @Override |
| 322 | public boolean onBubbleSucked(Bubble b) { |
| 323 | Log.w(TAG, "Bubble sucked ! "); |
| 324 | makeTransfer(b); |
| 325 | return true; |
| 326 | } |
| 327 | }, transfer_icon)); |
| 328 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 329 | // if (conf.hasMultipleParticipants()) { |
| 330 | // model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .9f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 331 | // @Override |
| 332 | // public boolean onBubbleSucked(Bubble b) { |
| 333 | // |
| 334 | // try { |
| 335 | // mCallbacks.getService().detachParticipant(b.associated_call.getCallId()); |
| 336 | // } catch (RemoteException e) { |
| 337 | // e.printStackTrace(); |
| 338 | // } |
| 339 | // |
| 340 | // bubbleRemoved(b); |
| 341 | // return true; |
| 342 | // } |
| 343 | // }, separate_icon)); |
| 344 | // } |
| 345 | |
| 346 | // if(mCalls.size() == 1 && mCalls.get(0).isOnHold()){ |
| 347 | // mCallbacks.onCallResumed(mCalls.get(0)); |
| 348 | // } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 349 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 350 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 351 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 352 | private void initIncomingCallDisplay() { |
| 353 | Log.i(TAG, "Start incoming display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 354 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 355 | mCallbacks.startTimer(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 356 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 357 | getBubbleFor(conf.getParticipants().get(0), model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 358 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 359 | model.clearAttractors(); |
| 360 | model.addAttractor(new Attractor(new PointF(4 * model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 361 | @Override |
| 362 | public boolean onBubbleSucked(Bubble b) { |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 363 | |
| 364 | if (!accepted) { |
| 365 | mCallbacks.onCallAccepted(conf.getParticipants().get(0)); |
| 366 | accepted = true; |
| 367 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 368 | return false; |
| 369 | } |
| 370 | }, call_icon)); |
| 371 | model.addAttractor(new Attractor(new PointF(model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 372 | @Override |
| 373 | public boolean onBubbleSucked(Bubble b) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 374 | mCallbacks.onCallRejected(conf.getParticipants().get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 375 | bubbleRemoved(b); |
| 376 | return true; |
| 377 | } |
| 378 | }, hangup_icon)); |
| 379 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 380 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 381 | private void initOutGoingCallDisplay() { |
| 382 | Log.i(TAG, "Start outgoing display"); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 383 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 384 | mCallbacks.startTimer(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 385 | |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 386 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 387 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 388 | // TODO off-thread image loading |
| 389 | int angle_part = 360 / conf.getParticipants().size(); |
| 390 | double dX = 0; |
| 391 | double dY = 0; |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 392 | int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 393 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 394 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 395 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 396 | getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
| 397 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 398 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 399 | model.clearAttractors(); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 400 | |
Alexandre Lision | b12f3b5 | 2013-09-09 10:50:51 -0400 | [diff] [blame] | 401 | model.addAttractor(new Attractor(new PointF(model.width / 2f, model.height * .9f), 40, new Attractor.Callback() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 402 | @Override |
| 403 | public boolean onBubbleSucked(Bubble b) { |
| 404 | Log.w(TAG, "Bubble sucked ! "); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 405 | mCallbacks.onCallEnded(conf.getParticipants().get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 406 | bubbleRemoved(b); |
| 407 | return true; |
| 408 | } |
| 409 | }, hangup_icon)); |
| 410 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 411 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 412 | /** |
| 413 | * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location. |
| 414 | * |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 415 | * @param call |
| 416 | * The call associated to a contact |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 417 | * @param x |
| 418 | * Initial or new x position. |
| 419 | * @param y |
| 420 | * Initial or new y position. |
| 421 | * @return Bubble corresponding to the contact. |
| 422 | */ |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 423 | private Bubble getBubbleFor(SipCall call, float x, float y) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 424 | Bubble contact_bubble = model.getBubble(call); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 425 | if (contact_bubble != null) { |
| 426 | contact_bubble.attractor.set(x, y); |
| 427 | return contact_bubble; |
| 428 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 429 | |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 430 | contact_bubble = new Bubble(getActivity(), call, x, y, BUBBLE_SIZE); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 431 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 432 | model.addBubble(contact_bubble); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 433 | return contact_bubble; |
| 434 | } |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 435 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 436 | /** |
| 437 | * Should be called when a bubble is removed from the model |
| 438 | */ |
| 439 | void bubbleRemoved(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 440 | if (b.associated_call == null) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 441 | return; |
| 442 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 443 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 444 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 445 | public void changeCallState(String callID, String newState) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 446 | Log.w(TAG, "Call :" + callID + newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 447 | if (newState.contentEquals("FAILURE")) { |
| 448 | try { |
| 449 | mCallbacks.getService().hangUp(callID); |
| 450 | } catch (RemoteException e) { |
| 451 | e.printStackTrace(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 452 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 453 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 454 | if (conf.getParticipants() == null) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 455 | Log.w(TAG, "IT IS NULL"); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 456 | return; |
| 457 | } |
| 458 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 459 | Log.w(TAG, "conf.getParticipants().size():" + conf.getParticipants().size()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 460 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 461 | // conf.getParticipants().get(i).printCallInfo(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 462 | Log.w(TAG, "Call id:" + conf.getParticipants().get(i).getCallId()); |
| 463 | Log.w(TAG, "Searching:" + callID); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 464 | if (callID.equals(conf.getParticipants().get(i).getCallId())) { |
| 465 | if (newState.contentEquals("HUNGUP")) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 466 | Log.w(TAG, "Call hungup:" + conf.getParticipants().get(i).getContact().getmDisplayName()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 467 | model.removeBubble(conf.getParticipants().get(i)); |
| 468 | conf.getParticipants().remove(i); |
| 469 | } else { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 470 | Log.w(TAG, "Call:" + conf.getParticipants().get(i).getContact().getmDisplayName() + " state:" + newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 471 | conf.getParticipants().get(i).setCallState(newState); |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | if (conf.isOnGoing()) |
| 477 | initNormalStateDisplay(); |
| 478 | |
| 479 | if (conf.getParticipants().size() == 0) { |
| 480 | mCallbacks.replaceCurrentCallDisplayed(); |
| 481 | } |
| 482 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 483 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 484 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 485 | public boolean draggingBubble() { |
| 486 | return view == null ? false : view.isDraggingBubble(); |
| 487 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 488 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 489 | @Override |
| 490 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 491 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 492 | if (conf.getParticipants().size() == 1) { |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 493 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 494 | if (conf.getParticipants().get(0).isIncoming() && conf.getParticipants().get(0).isRinging()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 495 | initIncomingCallDisplay(); |
| 496 | } else { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 497 | if (conf.getParticipants().get(0).isRinging()) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 498 | initOutGoingCallDisplay(); |
| 499 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 500 | try { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 501 | if (conf.getParticipants().get(0).isOutGoing() |
| 502 | && mCallbacks.getService().getCall(conf.getParticipants().get(0).getCallId()) == null) { |
| 503 | mCallbacks.getService().placeCall(conf.getParticipants().get(0)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 504 | initOutGoingCallDisplay(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 505 | } else if (conf.getParticipants().get(0).isOutGoing() && conf.getParticipants().get(0).isRinging()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 506 | initOutGoingCallDisplay(); |
| 507 | } |
| 508 | } catch (RemoteException e) { |
| 509 | Log.e(TAG, e.toString()); |
| 510 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 511 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 512 | if (conf.getParticipants().get(0).isOngoing()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 513 | initNormalStateDisplay(); |
| 514 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 515 | } else if (conf.getParticipants().size() > 1) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 516 | initNormalStateDisplay(); |
| 517 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 518 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 519 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 520 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 521 | public void makeTransfer(Bubble contact) { |
| 522 | FragmentManager fm = getFragmentManager(); |
| 523 | TransferDFragment editName = new TransferDFragment(); |
| 524 | |
| 525 | Bundle b = new Bundle(); |
| 526 | b.putParcelableArrayList("calls", new ArrayList<Conference>()); |
| 527 | b.putParcelable("call_selected", contact.associated_call); |
| 528 | editName.setArguments(b); |
| 529 | editName.setTargetFragment(this, REQUEST_TRANSFER); |
| 530 | editName.show(fm, ""); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 531 | } |
| 532 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 533 | @Override |
| 534 | public void surfaceCreated(SurfaceHolder holder) { |
| 535 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 536 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 537 | @Override |
| 538 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 539 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 540 | |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 541 | public BubblesView getBubbleView() { |
| 542 | return view; |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 543 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 544 | } |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 545 | |
| 546 | public void updateTime() { |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 547 | long duration = System.currentTimeMillis() / 1000 - this.conf.getParticipants().get(0).getTimestamp_start(); |
| 548 | callStatusTxt.setText(String.format("%d:%02d:%02d", duration/3600, duration%3600/60, duration%60)); |
| 549 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 550 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 551 | } |