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 | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 84 | BUBBLE_SIZE = getResources().getDimension(R.dimen.bubble_size); |
| 85 | Log.e(TAG,"BUBBLE_SIZE "+BUBBLE_SIZE); |
| 86 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 87 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 88 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 89 | /** |
| 90 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 91 | */ |
| 92 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 93 | @Override |
| 94 | public void onSendMessage(SipCall call, String msg) { |
| 95 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 96 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 97 | @Override |
| 98 | public void callContact(SipCall call) { |
| 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 onCallAccepted(SipCall call) { |
| 103 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 104 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 105 | @Override |
| 106 | public void onCallRejected(SipCall call) { |
| 107 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 108 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 109 | @Override |
| 110 | public void onCallEnded(SipCall call) { |
| 111 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 112 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 113 | @Override |
| 114 | public void onCallSuspended(SipCall call) { |
| 115 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 116 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 117 | @Override |
| 118 | public void onCallResumed(SipCall call) { |
| 119 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 120 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 121 | @Override |
| 122 | public void onCalltransfered(SipCall call, String to) { |
| 123 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 124 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 125 | @Override |
| 126 | public void onRecordCall(SipCall call) { |
| 127 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 128 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 129 | @Override |
| 130 | public ISipService getService() { |
| 131 | return null; |
| 132 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 133 | |
| 134 | @Override |
| 135 | public void replaceCurrentCallDisplayed() { |
| 136 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 137 | }; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 138 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 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); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 164 | |
| 165 | public void replaceCurrentCallDisplayed(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 166 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 167 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 168 | @Override |
| 169 | public void onAttach(Activity activity) { |
| 170 | super.onAttach(activity); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 171 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 172 | if (!(activity instanceof Callbacks)) { |
| 173 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 174 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 175 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 176 | // rootView.requestDisallowInterceptTouchEvent(true); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 177 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 178 | mCallbacks = (Callbacks) activity; |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 179 | myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me"); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 180 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 181 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 182 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 183 | @Override |
| 184 | public void onDetach() { |
| 185 | super.onDetach(); |
| 186 | mCallbacks = sDummyCallbacks; |
| 187 | // rootView.requestDisallowInterceptTouchEvent(false); |
| 188 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 189 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 190 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 191 | public void onStop() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 192 | super.onStop(); |
| 193 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 194 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 195 | @Override |
| 196 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 197 | ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 198 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 199 | view = (BubblesView) rootView.findViewById(R.id.main_view); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 200 | view.setFragment(this); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 201 | view.setModel(model); |
| 202 | view.getHolder().addCallback(this); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 203 | |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 204 | callStatusTxt = (CounterTextView) rootView.findViewById(R.id.call_status_txt); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 205 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 206 | hangup_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_hangup); |
| 207 | call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 208 | separate_icon = BitmapFactory.decodeResource(getResources(), R.drawable.icon_separate); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 209 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 210 | // Do nothing here, the view is not initialized yet. |
| 211 | return rootView; |
| 212 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 213 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 214 | private void initNormalStateDisplay() { |
| 215 | Log.i(TAG, "Start normal display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 216 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 217 | callStatusTxt.setText("0 min"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 218 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 219 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 220 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 221 | int angle_part = 360 / conf.getParticipants().size(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 222 | double dX = 0; |
| 223 | double dY = 0; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 224 | int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 225 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 226 | |
| 227 | if (conf.getParticipants().get(i) == null) { |
| 228 | Log.i(TAG, i + " null "); |
| 229 | continue; |
| 230 | } |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 231 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 232 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 233 | 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] | 234 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 235 | |
| 236 | model.clearAttractors(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 237 | model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .1f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 238 | @Override |
| 239 | public boolean onBubbleSucked(Bubble b) { |
| 240 | Log.w(TAG, "Bubble sucked ! "); |
| 241 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 242 | if (b.associated_call.getContact().isUser()) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 243 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 244 | try { |
| 245 | if (conf.hasMultipleParticipants()) |
| 246 | mCallbacks.getService().hangUpConference(conf.getId()); |
| 247 | else |
| 248 | mCallbacks.onCallEnded(conf.getParticipants().get(0)); |
| 249 | } catch (RemoteException e) { |
| 250 | e.printStackTrace(); |
| 251 | } |
| 252 | |
| 253 | } else { |
| 254 | mCallbacks.onCallEnded(b.associated_call); |
| 255 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 256 | bubbleRemoved(b); |
| 257 | return true; |
| 258 | } |
| 259 | }, hangup_icon)); |
| 260 | |
| 261 | // if (conf.hasMultipleParticipants()) { |
| 262 | // model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .9f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 263 | // @Override |
| 264 | // public boolean onBubbleSucked(Bubble b) { |
| 265 | // |
| 266 | // try { |
| 267 | // mCallbacks.getService().detachParticipant(b.associated_call.getCallId()); |
| 268 | // } catch (RemoteException e) { |
| 269 | // e.printStackTrace(); |
| 270 | // } |
| 271 | // |
| 272 | // bubbleRemoved(b); |
| 273 | // return true; |
| 274 | // } |
| 275 | // }, separate_icon)); |
| 276 | // } |
| 277 | |
| 278 | // if(mCalls.size() == 1 && mCalls.get(0).isOnHold()){ |
| 279 | // mCallbacks.onCallResumed(mCalls.get(0)); |
| 280 | // } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 281 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 282 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 283 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 284 | private void initIncomingCallDisplay() { |
| 285 | Log.i(TAG, "Start incoming display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 286 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 287 | callStatusTxt.setText("Incoming call"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 288 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 289 | getBubbleFor(conf.getParticipants().get(0), model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 290 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 291 | model.clearAttractors(); |
| 292 | model.addAttractor(new Attractor(new PointF(4 * model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 293 | @Override |
| 294 | public boolean onBubbleSucked(Bubble b) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 295 | mCallbacks.onCallAccepted(conf.getParticipants().get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 296 | return false; |
| 297 | } |
| 298 | }, call_icon)); |
| 299 | model.addAttractor(new Attractor(new PointF(model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 300 | @Override |
| 301 | public boolean onBubbleSucked(Bubble b) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 302 | mCallbacks.onCallRejected(conf.getParticipants().get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 303 | bubbleRemoved(b); |
| 304 | return true; |
| 305 | } |
| 306 | }, hangup_icon)); |
| 307 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 308 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 309 | private void initOutGoingCallDisplay() { |
| 310 | Log.i(TAG, "Start outgoing display"); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 311 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 312 | callStatusTxt.setText("Calling..."); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 313 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 314 | getBubbleFor(myself, model.width / 2, (float) (model.height / 1.2)); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 315 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 316 | // TODO off-thread image loading |
| 317 | int angle_part = 360 / conf.getParticipants().size(); |
| 318 | double dX = 0; |
| 319 | double dY = 0; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 320 | int radiusCalls = (int) ((model.width / 2 - BUBBLE_SIZE)); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 321 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 322 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 323 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 324 | getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
| 325 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 326 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 327 | model.clearAttractors(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 328 | 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] | 329 | @Override |
| 330 | public boolean onBubbleSucked(Bubble b) { |
| 331 | Log.w(TAG, "Bubble sucked ! "); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 332 | mCallbacks.onCallEnded(conf.getParticipants().get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 333 | bubbleRemoved(b); |
| 334 | return true; |
| 335 | } |
| 336 | }, hangup_icon)); |
| 337 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 338 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 339 | /** |
| 340 | * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location. |
| 341 | * |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 342 | * @param call |
| 343 | * The call associated to a contact |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 344 | * @param x |
| 345 | * Initial or new x position. |
| 346 | * @param y |
| 347 | * Initial or new y position. |
| 348 | * @return Bubble corresponding to the contact. |
| 349 | */ |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 350 | private Bubble getBubbleFor(SipCall call, float x, float y) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 351 | Bubble contact_bubble = model.getBubble(call); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 352 | if (contact_bubble != null) { |
| 353 | contact_bubble.attractor.set(x, y); |
| 354 | return contact_bubble; |
| 355 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 356 | |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 357 | contact_bubble = new Bubble(getActivity(), call, x, y, BUBBLE_SIZE); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 358 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 359 | model.addBubble(contact_bubble); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 360 | return contact_bubble; |
| 361 | } |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 362 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 363 | /** |
| 364 | * Should be called when a bubble is removed from the model |
| 365 | */ |
| 366 | void bubbleRemoved(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 367 | if (b.associated_call == null) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 368 | return; |
| 369 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 370 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 371 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 372 | public void changeCallState(String callID, String newState) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 373 | Log.w(TAG, "Call :" + callID + newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 374 | if (newState.contentEquals("FAILURE")) { |
| 375 | try { |
| 376 | mCallbacks.getService().hangUp(callID); |
| 377 | } catch (RemoteException e) { |
| 378 | e.printStackTrace(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 379 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 380 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 381 | if (conf.getParticipants() == null) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 382 | Log.w(TAG, "IT IS NULL"); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 383 | return; |
| 384 | } |
| 385 | |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 386 | Log.w(TAG, "conf.getParticipants().size():" + conf.getParticipants().size()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 387 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 388 | // conf.getParticipants().get(i).printCallInfo(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 389 | Log.w(TAG, "Call id:" + conf.getParticipants().get(i).getCallId()); |
| 390 | Log.w(TAG, "Searching:" + callID); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 391 | if (callID.equals(conf.getParticipants().get(i).getCallId())) { |
| 392 | if (newState.contentEquals("HUNGUP")) { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 393 | Log.w(TAG, "Call hungup:" + conf.getParticipants().get(i).getContact().getmDisplayName()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 394 | model.removeBubble(conf.getParticipants().get(i)); |
| 395 | conf.getParticipants().remove(i); |
| 396 | } else { |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 397 | Log.w(TAG, "Call:" + conf.getParticipants().get(i).getContact().getmDisplayName() + " state:" + newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 398 | conf.getParticipants().get(i).setCallState(newState); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if (conf.isOnGoing()) |
| 404 | initNormalStateDisplay(); |
| 405 | |
| 406 | if (conf.getParticipants().size() == 0) { |
| 407 | mCallbacks.replaceCurrentCallDisplayed(); |
| 408 | } |
| 409 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 410 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 411 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 412 | public boolean draggingBubble() { |
| 413 | return view == null ? false : view.isDraggingBubble(); |
| 414 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 415 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 416 | @Override |
| 417 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 418 | |
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 | } |