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 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 34 | import java.util.ArrayList; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 35 | import java.util.HashMap; |
| 36 | |
| 37 | import android.app.Activity; |
| 38 | import android.app.Fragment; |
| 39 | import android.graphics.Bitmap; |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 40 | import android.graphics.BitmapFactory; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 41 | import android.graphics.PointF; |
| 42 | import android.os.Bundle; |
| 43 | import android.os.RemoteException; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 44 | import android.util.Log; |
| 45 | import android.view.LayoutInflater; |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 46 | import android.view.SurfaceHolder; |
| 47 | import android.view.SurfaceHolder.Callback; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 48 | import android.view.View; |
| 49 | import android.view.ViewGroup; |
| 50 | import android.widget.TextView; |
| 51 | |
| 52 | import com.savoirfairelinux.sflphone.R; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 53 | import com.savoirfairelinux.sflphone.model.Attractor; |
| 54 | import com.savoirfairelinux.sflphone.model.Bubble; |
| 55 | import com.savoirfairelinux.sflphone.model.BubbleModel; |
| 56 | import com.savoirfairelinux.sflphone.model.BubblesView; |
| 57 | import com.savoirfairelinux.sflphone.model.CallContact; |
| 58 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 59 | import com.savoirfairelinux.sflphone.service.ISipService; |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame^] | 60 | import com.savoirfairelinux.sflphone.views.CounterTextView; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 61 | |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 62 | public class CallFragment extends Fragment implements Callback { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 63 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 64 | static final String TAG = "CallFragment"; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 65 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 66 | static final float BUBBLE_SIZE = 75; |
| 67 | static final float ATTRACTOR_SIZE = 40; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 68 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 69 | private ArrayList<SipCall> mCalls; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 70 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame^] | 71 | private CounterTextView callStatusTxt; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 72 | private BubblesView view; |
| 73 | private BubbleModel model; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 74 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 75 | private Callbacks mCallbacks = sDummyCallbacks; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 76 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 77 | private HashMap<CallContact, Bubble> contacts = new HashMap<CallContact, Bubble>(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 78 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 79 | private SipCall myself; |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 80 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 81 | private Bitmap hangup_icon; |
| 82 | private Bitmap call_icon; |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 83 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 84 | @Override |
| 85 | public void onCreate(Bundle savedBundle) { |
| 86 | super.onCreate(savedBundle); |
| 87 | model = new BubbleModel(getResources().getDisplayMetrics().density); |
| 88 | Bundle b = getArguments(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 89 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 90 | mCalls = b.getParcelableArrayList("CallsInfo"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 91 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 92 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 93 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 94 | /** |
| 95 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 96 | */ |
| 97 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 98 | @Override |
| 99 | public void onSendMessage(SipCall call, String msg) { |
| 100 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 101 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 102 | @Override |
| 103 | public void callContact(SipCall call) { |
| 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 onCallAccepted(SipCall call) { |
| 108 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 109 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 110 | @Override |
| 111 | public void onCallRejected(SipCall call) { |
| 112 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 113 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 114 | @Override |
| 115 | public void onCallEnded(SipCall call) { |
| 116 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 117 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 118 | @Override |
| 119 | public void onCallSuspended(SipCall call) { |
| 120 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 121 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 122 | @Override |
| 123 | public void onCallResumed(SipCall call) { |
| 124 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 125 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 126 | @Override |
| 127 | public void onCalltransfered(SipCall call, String to) { |
| 128 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 129 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 130 | @Override |
| 131 | public void onRecordCall(SipCall call) { |
| 132 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 133 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 134 | @Override |
| 135 | public ISipService getService() { |
| 136 | return null; |
| 137 | } |
| 138 | }; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 139 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 140 | /** |
| 141 | * The Activity calling this fragment has to implement this interface |
| 142 | * |
| 143 | */ |
| 144 | public interface Callbacks { |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 145 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 146 | public ISipService getService(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 147 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 148 | public void callContact(SipCall call); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 149 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 150 | public void onCallAccepted(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 151 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 152 | public void onCallRejected(SipCall call); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 153 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 154 | public void onCallEnded(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 155 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 156 | public void onCallSuspended(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 157 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 158 | public void onCallResumed(SipCall call); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 159 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 160 | public void onCalltransfered(SipCall call, String to); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 161 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 162 | public void onRecordCall(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 onSendMessage(SipCall call, String msg); |
| 165 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 166 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 167 | @Override |
| 168 | public void onAttach(Activity activity) { |
| 169 | super.onAttach(activity); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 170 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 171 | if (!(activity instanceof Callbacks)) { |
| 172 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 173 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 174 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 175 | // rootView.requestDisallowInterceptTouchEvent(true); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 176 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 177 | mCallbacks = (Callbacks) activity; |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame^] | 178 | myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me"); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 179 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 180 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 181 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 182 | @Override |
| 183 | public void onDetach() { |
| 184 | super.onDetach(); |
| 185 | mCallbacks = sDummyCallbacks; |
| 186 | // rootView.requestDisallowInterceptTouchEvent(false); |
| 187 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 188 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 189 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 190 | public void onStop() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 191 | super.onStop(); |
| 192 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 193 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 194 | @Override |
| 195 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 196 | ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 197 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 198 | view = (BubblesView) rootView.findViewById(R.id.main_view); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 199 | view.setFragment(this); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 200 | view.setModel(model); |
| 201 | view.getHolder().addCallback(this); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 202 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame^] | 203 | callStatusTxt = (CounterTextView) rootView.findViewById(R.id.call_status_txt); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 204 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 205 | hangup_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_hangup); |
| 206 | call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 207 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 208 | // Do nothing here, the view is not initialized yet. |
| 209 | return rootView; |
| 210 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 211 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 212 | private void initNormalStateDisplay() { |
| 213 | Log.i(TAG, "Start normal display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 214 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 215 | callStatusTxt.setText("0 min"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 216 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 217 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 218 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 219 | int angle_part = 360 / mCalls.size(); |
| 220 | double dX = 0; |
| 221 | double dY = 0; |
| 222 | int radiusCalls = model.width / 2 - 150; |
| 223 | for (int i = 0; i < mCalls.size(); ++i) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 224 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 225 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 226 | getBubbleFor(mCalls.get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
| 227 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 228 | |
| 229 | model.clearAttractors(); |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame^] | 230 | // model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .1f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 231 | // @Override |
| 232 | // public boolean onBubbleSucked(Bubble b) { |
| 233 | // Log.w(TAG, "Bubble sucked ! "); |
| 234 | // if (mCalls.size() == 1) { |
| 235 | // mCallbacks.onCallEnded(b.associated_call); |
| 236 | // } else { |
| 237 | // try { |
| 238 | // mCallbacks.getService().detachParticipant(b.associated_call.getCallId()); |
| 239 | // } catch (RemoteException e) { |
| 240 | // e.printStackTrace(); |
| 241 | // } |
| 242 | // } |
| 243 | // |
| 244 | // bubbleRemoved(b); |
| 245 | // return true; |
| 246 | // } |
| 247 | // }, hangup_icon)); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 248 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 249 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 250 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 251 | private void initIncomingCallDisplay() { |
| 252 | Log.i(TAG, "Start incoming display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 253 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 254 | callStatusTxt.setText("Incomming call"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 255 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 256 | Bubble contact_bubble = getBubbleFor(mCalls.get(0), model.width / 2, model.height / 2); |
| 257 | contacts.put(mCalls.get(0).getContact(), contact_bubble); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 258 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 259 | model.clearAttractors(); |
| 260 | model.addAttractor(new Attractor(new PointF(4 * model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 261 | @Override |
| 262 | public boolean onBubbleSucked(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 263 | mCallbacks.onCallAccepted(mCalls.get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 264 | return false; |
| 265 | } |
| 266 | }, call_icon)); |
| 267 | model.addAttractor(new Attractor(new PointF(model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 268 | @Override |
| 269 | public boolean onBubbleSucked(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 270 | mCallbacks.onCallRejected(mCalls.get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 271 | bubbleRemoved(b); |
| 272 | return true; |
| 273 | } |
| 274 | }, hangup_icon)); |
| 275 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 276 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 277 | private void initOutGoingCallDisplay() { |
| 278 | Log.i(TAG, "Start outgoing display"); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 279 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 280 | callStatusTxt.setText("Calling..."); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 281 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 282 | // TODO off-thread image loading |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 283 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 284 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 285 | getBubbleFor(mCalls.get(0), (int) (model.width / 2), (int) (model.height / 3)); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 286 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 287 | model.clearAttractors(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 288 | model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .1f), 40, new Attractor.Callback() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 289 | @Override |
| 290 | public boolean onBubbleSucked(Bubble b) { |
| 291 | Log.w(TAG, "Bubble sucked ! "); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 292 | mCallbacks.onCallEnded(mCalls.get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 293 | bubbleRemoved(b); |
| 294 | return true; |
| 295 | } |
| 296 | }, hangup_icon)); |
| 297 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 298 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 299 | /** |
| 300 | * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location. |
| 301 | * |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 302 | * @param call |
| 303 | * The call associated to a contact |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 304 | * @param x |
| 305 | * Initial or new x position. |
| 306 | * @param y |
| 307 | * Initial or new y position. |
| 308 | * @return Bubble corresponding to the contact. |
| 309 | */ |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 310 | private Bubble getBubbleFor(SipCall call, float x, float y) { |
| 311 | Bubble contact_bubble = contacts.get(call.getContact()); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 312 | if (contact_bubble != null) { |
| 313 | contact_bubble.attractor.set(x, y); |
| 314 | return contact_bubble; |
| 315 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 316 | |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 317 | contact_bubble = new Bubble(getActivity(), call, x, y, BUBBLE_SIZE); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 318 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 319 | model.addBubble(contact_bubble); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 320 | contacts.put(call.getContact(), contact_bubble); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 321 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 322 | return contact_bubble; |
| 323 | } |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 324 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 325 | /** |
| 326 | * Should be called when a bubble is removed from the model |
| 327 | */ |
| 328 | void bubbleRemoved(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 329 | if (b.associated_call == null) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 330 | return; |
| 331 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 332 | contacts.remove(b.associated_call.getContact()); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 333 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 334 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 335 | public void changeCallState(String callID, String newState) { |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 336 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 337 | Log.w(TAG, "Changing call state of " + callID); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 338 | if (mCalls.size() == 1) { |
| 339 | if (callID.equals(mCalls.get(0).getCallId())) |
| 340 | mCalls.get(0).setCallState(newState); |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 341 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 342 | if (mCalls.get(0).isOngoing()) { |
| 343 | initNormalStateDisplay(); |
| 344 | } |
| 345 | } else { |
| 346 | for (int i = 0; i < mCalls.size(); ++i) { |
| 347 | mCalls.get(i).printCallInfo(); |
| 348 | |
| 349 | if (callID.equals(mCalls.get(i).getCallId())) |
| 350 | mCalls.get(i).setCallState(newState); |
| 351 | |
| 352 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 353 | } |
| 354 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 355 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 356 | public boolean draggingBubble() { |
| 357 | return view == null ? false : view.isDraggingBubble(); |
| 358 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 359 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 360 | @Override |
| 361 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 362 | // Log.i(TAG, "Init fragment " + mCall.getCallId()); |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 363 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 364 | // mCall.printCallInfo(); |
| 365 | if (mCalls.size() == 1) { |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 366 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 367 | if (mCalls.get(0).isIncoming() && mCalls.get(0).isRinging()) { |
| 368 | initIncomingCallDisplay(); |
| 369 | } else { |
| 370 | if (mCalls.get(0).isRinging()) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 371 | initOutGoingCallDisplay(); |
| 372 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 373 | try { |
| 374 | if (mCalls.get(0).isOutGoing() && mCallbacks.getService().getCall(mCalls.get(0).getCallId()) == null) { |
| 375 | mCallbacks.getService().placeCall(mCalls.get(0)); |
| 376 | initOutGoingCallDisplay(); |
| 377 | } else if (mCalls.get(0).isOutGoing() && mCalls.get(0).isRinging()) { |
| 378 | initOutGoingCallDisplay(); |
| 379 | } |
| 380 | } catch (RemoteException e) { |
| 381 | Log.e(TAG, e.toString()); |
| 382 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 383 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 384 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 385 | if (mCalls.get(0).isOngoing()) { |
| 386 | initNormalStateDisplay(); |
| 387 | } |
| 388 | } else { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 389 | initNormalStateDisplay(); |
| 390 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 391 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 392 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 393 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 394 | @Override |
| 395 | public void surfaceCreated(SurfaceHolder holder) { |
| 396 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 397 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 398 | @Override |
| 399 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 400 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 401 | |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 402 | public BubblesView getBubbleView() { |
| 403 | return view; |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 404 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 405 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 406 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 407 | } |