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; |
| 53 | import com.savoirfairelinux.sflphone.adapters.ContactPictureLoader; |
| 54 | import com.savoirfairelinux.sflphone.model.Attractor; |
| 55 | import com.savoirfairelinux.sflphone.model.Bubble; |
| 56 | import com.savoirfairelinux.sflphone.model.BubbleModel; |
| 57 | import com.savoirfairelinux.sflphone.model.BubblesView; |
| 58 | import com.savoirfairelinux.sflphone.model.CallContact; |
| 59 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 60 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 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 | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 71 | private TextView callStatusTxt; |
| 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 | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 178 | myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), ""); |
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); |
| 199 | view.setModel(model); |
| 200 | view.getHolder().addCallback(this); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 201 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 202 | callStatusTxt = (TextView) rootView.findViewById(R.id.call_status_txt); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 203 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 204 | hangup_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_hangup); |
| 205 | call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 206 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 207 | // Do nothing here, the view is not initialized yet. |
| 208 | return rootView; |
| 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 | private void initNormalStateDisplay() { |
| 212 | Log.i(TAG, "Start normal display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 213 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 214 | callStatusTxt.setText("0 min"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 215 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 216 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 217 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 218 | int angle_part = 360 / mCalls.size(); |
| 219 | double dX = 0; |
| 220 | double dY = 0; |
| 221 | int radiusCalls = model.width / 2 - 150; |
| 222 | for (int i = 0; i < mCalls.size(); ++i) { |
| 223 | dX = Math.cos(Math.toRadians(angle_part * i) - 90) * radiusCalls; |
| 224 | dY = Math.sin(Math.toRadians(angle_part * i) - 90) * radiusCalls; |
| 225 | getBubbleFor(mCalls.get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
| 226 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 227 | |
| 228 | model.clearAttractors(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 229 | model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .1f), ATTRACTOR_SIZE, new Attractor.Callback() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 230 | @Override |
| 231 | public boolean onBubbleSucked(Bubble b) { |
| 232 | Log.w(TAG, "Bubble sucked ! "); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 233 | if(mCalls.size() == 1){ |
| 234 | mCallbacks.onCallEnded(b.associated_call); |
| 235 | } else { |
| 236 | try { |
| 237 | mCallbacks.getService().detachParticipant(b.associated_call.getCallId()); |
| 238 | } catch (RemoteException e) { |
| 239 | e.printStackTrace(); |
| 240 | } |
| 241 | } |
| 242 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 243 | bubbleRemoved(b); |
| 244 | return true; |
| 245 | } |
| 246 | }, hangup_icon)); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 247 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 248 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 249 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 250 | private void initIncomingCallDisplay() { |
| 251 | Log.i(TAG, "Start incoming display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 252 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 253 | callStatusTxt.setText("Incomming call"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 254 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 255 | Bubble contact_bubble = getBubbleFor(mCalls.get(0), model.width / 2, model.height / 2); |
| 256 | contacts.put(mCalls.get(0).getContact(), contact_bubble); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 257 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 258 | model.clearAttractors(); |
| 259 | model.addAttractor(new Attractor(new PointF(4 * model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 260 | @Override |
| 261 | public boolean onBubbleSucked(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 262 | mCallbacks.onCallAccepted(mCalls.get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 263 | return false; |
| 264 | } |
| 265 | }, call_icon)); |
| 266 | model.addAttractor(new Attractor(new PointF(model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 267 | @Override |
| 268 | public boolean onBubbleSucked(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 269 | mCallbacks.onCallRejected(mCalls.get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 270 | bubbleRemoved(b); |
| 271 | return true; |
| 272 | } |
| 273 | }, hangup_icon)); |
| 274 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 275 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 276 | private void initOutGoingCallDisplay() { |
| 277 | Log.i(TAG, "Start outgoing display"); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 278 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 279 | callStatusTxt.setText("Calling..."); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 280 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 281 | // TODO off-thread image loading |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 282 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 283 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 284 | getBubbleFor(mCalls.get(0), (int) (model.width / 2), (int) (model.height / 3)); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 285 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 286 | model.clearAttractors(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 287 | 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] | 288 | @Override |
| 289 | public boolean onBubbleSucked(Bubble b) { |
| 290 | Log.w(TAG, "Bubble sucked ! "); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 291 | mCallbacks.onCallEnded(mCalls.get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 292 | bubbleRemoved(b); |
| 293 | return true; |
| 294 | } |
| 295 | }, hangup_icon)); |
| 296 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 297 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 298 | /** |
| 299 | * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location. |
| 300 | * |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 301 | * @param call |
| 302 | * The call associated to a contact |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 303 | * @param x |
| 304 | * Initial or new x position. |
| 305 | * @param y |
| 306 | * Initial or new y position. |
| 307 | * @return Bubble corresponding to the contact. |
| 308 | */ |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 309 | private Bubble getBubbleFor(SipCall call, float x, float y) { |
| 310 | Bubble contact_bubble = contacts.get(call.getContact()); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 311 | if (contact_bubble != null) { |
| 312 | contact_bubble.attractor.set(x, y); |
| 313 | return contact_bubble; |
| 314 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 315 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 316 | // TODO off-thread image loading |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 317 | if (call.getContact().getPhoto_id() > 0) { |
| 318 | Bitmap photo = ContactPictureLoader.loadContactPhoto(getActivity().getContentResolver(), call.getContact().getId()); |
| 319 | contact_bubble = new Bubble(call, x, y, BUBBLE_SIZE, photo); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 320 | } else { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 321 | contact_bubble = new Bubble(call, x, y, BUBBLE_SIZE, getActivity(), R.drawable.ic_contact_picture); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 322 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 323 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 324 | model.addBubble(contact_bubble); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 325 | contacts.put(call.getContact(), contact_bubble); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 326 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 327 | return contact_bubble; |
| 328 | } |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 329 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 330 | /** |
| 331 | * Should be called when a bubble is removed from the model |
| 332 | */ |
| 333 | void bubbleRemoved(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 334 | if (b.associated_call == null) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 335 | return; |
| 336 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 337 | contacts.remove(b.associated_call.getContact()); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 338 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 339 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 340 | public void changeCallState(String callID, String newState) { |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 341 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 342 | Log.w(TAG, "Changing call state of " + callID); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 343 | if (mCalls.size() == 1) { |
| 344 | if (callID.equals(mCalls.get(0).getCallId())) |
| 345 | mCalls.get(0).setCallState(newState); |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 346 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 347 | if (mCalls.get(0).isOngoing()) { |
| 348 | initNormalStateDisplay(); |
| 349 | } |
| 350 | } else { |
| 351 | for (int i = 0; i < mCalls.size(); ++i) { |
| 352 | mCalls.get(i).printCallInfo(); |
| 353 | |
| 354 | if (callID.equals(mCalls.get(i).getCallId())) |
| 355 | mCalls.get(i).setCallState(newState); |
| 356 | |
| 357 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 358 | } |
| 359 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 360 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 361 | public boolean draggingBubble() { |
| 362 | return view == null ? false : view.isDraggingBubble(); |
| 363 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 364 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 365 | @Override |
| 366 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 367 | // Log.i(TAG, "Init fragment " + mCall.getCallId()); |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 368 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 369 | // mCall.printCallInfo(); |
| 370 | if (mCalls.size() == 1) { |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 371 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 372 | if (mCalls.get(0).isIncoming() && mCalls.get(0).isRinging()) { |
| 373 | initIncomingCallDisplay(); |
| 374 | } else { |
| 375 | if (mCalls.get(0).isRinging()) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 376 | initOutGoingCallDisplay(); |
| 377 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 378 | try { |
| 379 | if (mCalls.get(0).isOutGoing() && mCallbacks.getService().getCall(mCalls.get(0).getCallId()) == null) { |
| 380 | mCallbacks.getService().placeCall(mCalls.get(0)); |
| 381 | initOutGoingCallDisplay(); |
| 382 | } else if (mCalls.get(0).isOutGoing() && mCalls.get(0).isRinging()) { |
| 383 | initOutGoingCallDisplay(); |
| 384 | } |
| 385 | } catch (RemoteException e) { |
| 386 | Log.e(TAG, e.toString()); |
| 387 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 388 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 389 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame^] | 390 | if (mCalls.get(0).isOngoing()) { |
| 391 | initNormalStateDisplay(); |
| 392 | } |
| 393 | } else { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 394 | initNormalStateDisplay(); |
| 395 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 396 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 397 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 398 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 399 | @Override |
| 400 | public void surfaceCreated(SurfaceHolder holder) { |
| 401 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 402 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 403 | @Override |
| 404 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 405 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 406 | |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 407 | public BubblesView getBubbleView() { |
| 408 | return view; |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 409 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 410 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 411 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 412 | } |