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