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