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