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 | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 34 | import android.app.Activity; |
| 35 | import android.app.Fragment; |
| 36 | import android.graphics.Bitmap; |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 37 | import android.graphics.BitmapFactory; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 38 | import android.graphics.PointF; |
| 39 | import android.os.Bundle; |
| 40 | import android.os.RemoteException; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 41 | import android.util.Log; |
| 42 | import android.view.LayoutInflater; |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 43 | import android.view.SurfaceHolder; |
| 44 | import android.view.SurfaceHolder.Callback; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 45 | import android.view.View; |
| 46 | import android.view.ViewGroup; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 47 | |
| 48 | import com.savoirfairelinux.sflphone.R; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 49 | import com.savoirfairelinux.sflphone.model.Attractor; |
| 50 | import com.savoirfairelinux.sflphone.model.Bubble; |
| 51 | import com.savoirfairelinux.sflphone.model.BubbleModel; |
| 52 | import com.savoirfairelinux.sflphone.model.BubblesView; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 53 | import com.savoirfairelinux.sflphone.model.Conference; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 54 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 55 | import com.savoirfairelinux.sflphone.service.ISipService; |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 56 | import com.savoirfairelinux.sflphone.views.CounterTextView; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 57 | |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 58 | public class CallFragment extends Fragment implements Callback { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 59 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 60 | static final String TAG = "CallFragment"; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 61 | |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame^] | 62 | float BUBBLE_SIZE = 75; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 63 | static final float ATTRACTOR_SIZE = 40; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 64 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 65 | private Conference conf; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 66 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 67 | private CounterTextView callStatusTxt; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 68 | private BubblesView view; |
| 69 | private BubbleModel model; |
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 Callbacks mCallbacks = sDummyCallbacks; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 72 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 73 | private SipCall myself; |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 74 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 75 | private Bitmap hangup_icon, separate_icon; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 76 | private Bitmap call_icon; |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 77 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 78 | @Override |
| 79 | public void onCreate(Bundle savedBundle) { |
| 80 | super.onCreate(savedBundle); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 81 | Bundle b = getArguments(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 82 | conf = new Conference((Conference) b.getParcelable("conference")); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 83 | model = new BubbleModel(getResources().getDisplayMetrics().density); |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame^] | 84 | BUBBLE_SIZE = 50 * getResources().getDisplayMetrics().density; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 85 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 86 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 87 | /** |
| 88 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 89 | */ |
| 90 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 91 | @Override |
| 92 | public void onSendMessage(SipCall call, String msg) { |
| 93 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 94 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 95 | @Override |
| 96 | public void callContact(SipCall call) { |
| 97 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 98 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 99 | @Override |
| 100 | public void onCallAccepted(SipCall call) { |
| 101 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 102 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 103 | @Override |
| 104 | public void onCallRejected(SipCall call) { |
| 105 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 106 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 107 | @Override |
| 108 | public void onCallEnded(SipCall call) { |
| 109 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 110 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 111 | @Override |
| 112 | public void onCallSuspended(SipCall call) { |
| 113 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 114 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 115 | @Override |
| 116 | public void onCallResumed(SipCall call) { |
| 117 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 118 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 119 | @Override |
| 120 | public void onCalltransfered(SipCall call, String to) { |
| 121 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 122 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 123 | @Override |
| 124 | public void onRecordCall(SipCall call) { |
| 125 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 126 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 127 | @Override |
| 128 | public ISipService getService() { |
| 129 | return null; |
| 130 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 131 | |
| 132 | @Override |
| 133 | public void replaceCurrentCallDisplayed() { |
| 134 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 135 | }; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 136 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 137 | /** |
| 138 | * The Activity calling this fragment has to implement this interface |
| 139 | * |
| 140 | */ |
| 141 | public interface Callbacks { |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 142 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 143 | public ISipService getService(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 144 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 145 | public void callContact(SipCall call); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 146 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 147 | public void onCallAccepted(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 148 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 149 | public void onCallRejected(SipCall call); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 150 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 151 | public void onCallEnded(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 152 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 153 | public void onCallSuspended(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 onCallResumed(SipCall call); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 156 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 157 | public void onCalltransfered(SipCall call, String to); |
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 onRecordCall(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 160 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 161 | public void onSendMessage(SipCall call, String msg); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 162 | |
| 163 | public void replaceCurrentCallDisplayed(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 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; |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 177 | myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me"); |
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 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 187 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 188 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 189 | public void onStop() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 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); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 198 | view.setFragment(this); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 199 | view.setModel(model); |
| 200 | view.getHolder().addCallback(this); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 201 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 202 | callStatusTxt = (CounterTextView) 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 | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 206 | separate_icon = BitmapFactory.decodeResource(getResources(), R.drawable.icon_separate); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 207 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 208 | // Do nothing here, the view is not initialized yet. |
| 209 | return rootView; |
| 210 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 211 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 212 | private void initNormalStateDisplay() { |
| 213 | Log.i(TAG, "Start normal display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 214 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 215 | callStatusTxt.setText("0 min"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 216 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 217 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 218 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 219 | int angle_part = 360 / conf.getParticipants().size(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 220 | double dX = 0; |
| 221 | double dY = 0; |
| 222 | int radiusCalls = model.width / 2 - 150; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 223 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 224 | |
| 225 | if (conf.getParticipants().get(i) == null) { |
| 226 | Log.i(TAG, i + " null "); |
| 227 | continue; |
| 228 | } |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 229 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 230 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 231 | getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 232 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 233 | |
| 234 | model.clearAttractors(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 235 | model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .1f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 236 | @Override |
| 237 | public boolean onBubbleSucked(Bubble b) { |
| 238 | Log.w(TAG, "Bubble sucked ! "); |
| 239 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 240 | if (b.associated_call.getContact().isUser()) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 241 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 242 | try { |
| 243 | if (conf.hasMultipleParticipants()) |
| 244 | mCallbacks.getService().hangUpConference(conf.getId()); |
| 245 | else |
| 246 | mCallbacks.onCallEnded(conf.getParticipants().get(0)); |
| 247 | } catch (RemoteException e) { |
| 248 | e.printStackTrace(); |
| 249 | } |
| 250 | |
| 251 | } else { |
| 252 | mCallbacks.onCallEnded(b.associated_call); |
| 253 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 254 | bubbleRemoved(b); |
| 255 | return true; |
| 256 | } |
| 257 | }, hangup_icon)); |
| 258 | |
| 259 | // if (conf.hasMultipleParticipants()) { |
| 260 | // model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .9f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 261 | // @Override |
| 262 | // public boolean onBubbleSucked(Bubble b) { |
| 263 | // |
| 264 | // try { |
| 265 | // mCallbacks.getService().detachParticipant(b.associated_call.getCallId()); |
| 266 | // } catch (RemoteException e) { |
| 267 | // e.printStackTrace(); |
| 268 | // } |
| 269 | // |
| 270 | // bubbleRemoved(b); |
| 271 | // return true; |
| 272 | // } |
| 273 | // }, separate_icon)); |
| 274 | // } |
| 275 | |
| 276 | // if(mCalls.size() == 1 && mCalls.get(0).isOnHold()){ |
| 277 | // mCallbacks.onCallResumed(mCalls.get(0)); |
| 278 | // } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 279 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 280 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 281 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 282 | private void initIncomingCallDisplay() { |
| 283 | Log.i(TAG, "Start incoming display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 284 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 285 | callStatusTxt.setText("Incoming call"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 286 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 287 | getBubbleFor(conf.getParticipants().get(0), model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 288 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 289 | model.clearAttractors(); |
| 290 | model.addAttractor(new Attractor(new PointF(4 * model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 291 | @Override |
| 292 | public boolean onBubbleSucked(Bubble b) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 293 | mCallbacks.onCallAccepted(conf.getParticipants().get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 294 | return false; |
| 295 | } |
| 296 | }, call_icon)); |
| 297 | model.addAttractor(new Attractor(new PointF(model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 298 | @Override |
| 299 | public boolean onBubbleSucked(Bubble b) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 300 | mCallbacks.onCallRejected(conf.getParticipants().get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 301 | bubbleRemoved(b); |
| 302 | return true; |
| 303 | } |
| 304 | }, hangup_icon)); |
| 305 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 306 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 307 | private void initOutGoingCallDisplay() { |
| 308 | Log.i(TAG, "Start outgoing display"); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 309 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 310 | callStatusTxt.setText("Calling..."); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 311 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 312 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 313 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 314 | // TODO off-thread image loading |
| 315 | int angle_part = 360 / conf.getParticipants().size(); |
| 316 | double dX = 0; |
| 317 | double dY = 0; |
| 318 | int radiusCalls = model.width / 2 - 150; |
| 319 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 320 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 321 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 322 | getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
| 323 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 324 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 325 | model.clearAttractors(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 326 | 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] | 327 | @Override |
| 328 | public boolean onBubbleSucked(Bubble b) { |
| 329 | Log.w(TAG, "Bubble sucked ! "); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 330 | mCallbacks.onCallEnded(conf.getParticipants().get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 331 | bubbleRemoved(b); |
| 332 | return true; |
| 333 | } |
| 334 | }, hangup_icon)); |
| 335 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 336 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 337 | /** |
| 338 | * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location. |
| 339 | * |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 340 | * @param call |
| 341 | * The call associated to a contact |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 342 | * @param x |
| 343 | * Initial or new x position. |
| 344 | * @param y |
| 345 | * Initial or new y position. |
| 346 | * @return Bubble corresponding to the contact. |
| 347 | */ |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 348 | private Bubble getBubbleFor(SipCall call, float x, float y) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 349 | Bubble contact_bubble = model.getBubble(call); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 350 | if (contact_bubble != null) { |
| 351 | contact_bubble.attractor.set(x, y); |
| 352 | return contact_bubble; |
| 353 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 354 | |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 355 | contact_bubble = new Bubble(getActivity(), call, x, y, BUBBLE_SIZE); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 356 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 357 | model.addBubble(contact_bubble); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 358 | return contact_bubble; |
| 359 | } |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 360 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 361 | /** |
| 362 | * Should be called when a bubble is removed from the model |
| 363 | */ |
| 364 | void bubbleRemoved(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 365 | if (b.associated_call == null) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 366 | return; |
| 367 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 368 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 369 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 370 | public void changeCallState(String callID, String newState) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 371 | Log.w(TAG, "Call :" + callID + newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 372 | if (newState.contentEquals("FAILURE")) { |
| 373 | try { |
| 374 | mCallbacks.getService().hangUp(callID); |
| 375 | } catch (RemoteException e) { |
| 376 | e.printStackTrace(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 377 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 378 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 379 | if (conf.getParticipants() == null) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 380 | Log.w(TAG, "IT IS NULL"); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 381 | return; |
| 382 | } |
| 383 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 384 | Log.w(TAG, "conf.getParticipants().size():" + conf.getParticipants().size()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 385 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 386 | // conf.getParticipants().get(i).printCallInfo(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 387 | Log.w(TAG, "Call id:" + conf.getParticipants().get(i).getCallId()); |
| 388 | Log.w(TAG, "Searching:" + callID); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 389 | if (callID.equals(conf.getParticipants().get(i).getCallId())) { |
| 390 | if (newState.contentEquals("HUNGUP")) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 391 | Log.w(TAG, "Call hungup:" + conf.getParticipants().get(i).getContact().getmDisplayName()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 392 | model.removeBubble(conf.getParticipants().get(i)); |
| 393 | conf.getParticipants().remove(i); |
| 394 | } else { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 395 | Log.w(TAG, "Call:" + conf.getParticipants().get(i).getContact().getmDisplayName() + " state:" + newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 396 | conf.getParticipants().get(i).setCallState(newState); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | if (conf.isOnGoing()) |
| 402 | initNormalStateDisplay(); |
| 403 | |
| 404 | if (conf.getParticipants().size() == 0) { |
| 405 | mCallbacks.replaceCurrentCallDisplayed(); |
| 406 | } |
| 407 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 408 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 409 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 410 | public boolean draggingBubble() { |
| 411 | return view == null ? false : view.isDraggingBubble(); |
| 412 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 413 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 414 | @Override |
| 415 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 416 | // Log.i(TAG, "Init fragment " + mCall.getCallId()); |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 417 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 418 | // mCall.printCallInfo(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 419 | if (conf.getParticipants().size() == 1) { |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 420 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 421 | if (conf.getParticipants().get(0).isIncoming() && conf.getParticipants().get(0).isRinging()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 422 | initIncomingCallDisplay(); |
| 423 | } else { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 424 | if (conf.getParticipants().get(0).isRinging()) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 425 | initOutGoingCallDisplay(); |
| 426 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 427 | try { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 428 | if (conf.getParticipants().get(0).isOutGoing() |
| 429 | && mCallbacks.getService().getCall(conf.getParticipants().get(0).getCallId()) == null) { |
| 430 | mCallbacks.getService().placeCall(conf.getParticipants().get(0)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 431 | initOutGoingCallDisplay(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 432 | } else if (conf.getParticipants().get(0).isOutGoing() && conf.getParticipants().get(0).isRinging()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 433 | initOutGoingCallDisplay(); |
| 434 | } |
| 435 | } catch (RemoteException e) { |
| 436 | Log.e(TAG, e.toString()); |
| 437 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 438 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 439 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 440 | if (conf.getParticipants().get(0).isOngoing()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 441 | initNormalStateDisplay(); |
| 442 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 443 | } else if (conf.getParticipants().size() > 1) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 444 | initNormalStateDisplay(); |
| 445 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 446 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 447 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 448 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 449 | @Override |
| 450 | public void surfaceCreated(SurfaceHolder holder) { |
| 451 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 452 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 453 | @Override |
| 454 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 455 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 456 | |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 457 | public BubblesView getBubbleView() { |
| 458 | return view; |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 459 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 460 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 461 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 462 | } |