alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 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 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 32 | package org.sflphone.fragments; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 33 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 34 | import android.app.Activity; |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 35 | import android.content.BroadcastReceiver; |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 36 | import android.content.Context; |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 37 | import android.content.Intent; |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 38 | import android.content.IntentFilter; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 39 | import android.graphics.Bitmap; |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 40 | import android.graphics.BitmapFactory; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 41 | import android.graphics.PointF; |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 42 | import android.net.wifi.WifiInfo; |
| 43 | import android.net.wifi.WifiManager; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 44 | import android.os.Bundle; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 45 | import android.os.PowerManager; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 46 | import android.os.PowerManager.WakeLock; |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 47 | import android.os.RemoteException; |
| 48 | import android.support.v4.app.FragmentManager; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 49 | import android.util.Log; |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 50 | import android.view.*; |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 51 | import android.view.SurfaceHolder.Callback; |
Alexandre Lision | 84208a3 | 2013-09-25 13:18:37 -0400 | [diff] [blame] | 52 | import android.view.View.OnClickListener; |
Alexandre Lision | 84208a3 | 2013-09-25 13:18:37 -0400 | [diff] [blame] | 53 | import android.view.inputmethod.InputMethodManager; |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 54 | import android.widget.Button; |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 55 | import android.widget.CompoundButton; |
| 56 | import android.widget.CompoundButton.OnCheckedChangeListener; |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 57 | import android.widget.TextView; |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 58 | import android.widget.ToggleButton; |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 59 | import org.sflphone.R; |
| 60 | import org.sflphone.interfaces.CallInterface; |
| 61 | import org.sflphone.model.*; |
| 62 | import org.sflphone.service.ISipService; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 63 | |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 64 | import java.util.ArrayList; |
| 65 | import java.util.Locale; |
| 66 | |
| 67 | public class CallFragment extends CallableWrapperFragment implements CallInterface, Callback { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 68 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 69 | static final String TAG = "CallFragment"; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 70 | |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 71 | float BUBBLE_SIZE = 75; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 72 | static final float ATTRACTOR_SIZE = 40; |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 73 | public static final int REQUEST_TRANSFER = 10; |
| 74 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 75 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 76 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 77 | private TextView callStatusTxt; |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 78 | private ToggleButton speakers; |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 79 | |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 80 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 81 | private PowerManager powerManager; |
| 82 | // Screen wake lock for incoming call |
| 83 | private WakeLock wakeLock; |
| 84 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 85 | private BubblesView view; |
| 86 | private BubbleModel model; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 87 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 88 | public Callbacks mCallbacks = sDummyCallbacks; |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 89 | boolean accepted = false; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 90 | private Bitmap call_icon; |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 91 | |
Alexandre Lision | 0eb0203 | 2013-09-27 16:32:40 -0400 | [diff] [blame] | 92 | TransferDFragment editName; |
Alexandre Lision | a3c4f5f | 2014-01-07 17:22:22 -0500 | [diff] [blame] | 93 | private WifiManager wifiManager; |
| 94 | private BroadcastReceiver wifiReceiver = new BroadcastReceiver() { |
| 95 | |
| 96 | @Override |
| 97 | public void onReceive(Context context, Intent intent) { |
| 98 | WifiInfo info = wifiManager.getConnectionInfo(); |
| 99 | Log.i(TAG, "Level of wifi " +info.getRssi()); |
| 100 | } |
| 101 | |
| 102 | }; |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 103 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 104 | @Override |
| 105 | public void onCreate(Bundle savedBundle) { |
| 106 | super.onCreate(savedBundle); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 107 | model = new BubbleModel(getResources().getDisplayMetrics().density); |
alision | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 108 | BUBBLE_SIZE = getResources().getDimension(R.dimen.bubble_size); |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 109 | Log.e(TAG, "BUBBLE_SIZE " + BUBBLE_SIZE); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 110 | this.setHasOptionsMenu(true); |
alision | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 111 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 112 | powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); |
| 113 | wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, |
| 114 | "org.sflphone.onIncomingCall"); |
| 115 | wakeLock.setReferenceCounted(false); |
| 116 | |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 117 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 118 | Log.d(TAG, "Acquire wake up lock"); |
| 119 | if (wakeLock != null && !wakeLock.isHeld()) { |
| 120 | wakeLock.acquire(); |
| 121 | } |
Alexandre Lision | a3c4f5f | 2014-01-07 17:22:22 -0500 | [diff] [blame] | 122 | } |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 123 | |
Alexandre Lision | a3c4f5f | 2014-01-07 17:22:22 -0500 | [diff] [blame] | 124 | private void initializeWiFiListener(){ |
| 125 | Log.i(TAG, "executing initializeWiFiListener"); |
| 126 | |
| 127 | String connectivity_context = Context.WIFI_SERVICE; |
| 128 | wifiManager = (WifiManager) getActivity().getSystemService(connectivity_context); |
| 129 | |
| 130 | if(!wifiManager.isWifiEnabled()){ |
| 131 | if(wifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLING){ |
| 132 | wifiManager.setWifiEnabled(true); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | getActivity().registerReceiver(wifiReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 137 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 138 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 139 | /** |
| 140 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 141 | */ |
| 142 | private static Callbacks sDummyCallbacks = new Callbacks() { |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 143 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 144 | @Override |
| 145 | public ISipService getService() { |
| 146 | return null; |
| 147 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 148 | |
Alexandre Lision | ccf0c93 | 2013-10-10 16:24:41 -0400 | [diff] [blame] | 149 | @Override |
Alexandre Lision | dafe951 | 2013-10-28 16:31:41 -0400 | [diff] [blame] | 150 | public void terminateCall() { |
Alexandre Lision | ccf0c93 | 2013-10-10 16:24:41 -0400 | [diff] [blame] | 151 | } |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 152 | |
| 153 | @Override |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 154 | public Conference getDisplayedConference() { |
| 155 | return null; |
| 156 | } |
| 157 | |
| 158 | @Override |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 159 | public void startTimer() { |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 160 | } |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 161 | |
| 162 | @Override |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 163 | public void slideChatScreen() { |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 164 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 165 | }; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 166 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 167 | /** |
| 168 | * The Activity calling this fragment has to implement this interface |
| 169 | * |
| 170 | */ |
| 171 | public interface Callbacks { |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 172 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 173 | public ISipService getService(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 174 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 175 | public void startTimer(); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 176 | |
| 177 | public void slideChatScreen(); |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 178 | |
Alexandre Lision | dafe951 | 2013-10-28 16:31:41 -0400 | [diff] [blame] | 179 | public void terminateCall(); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 180 | |
| 181 | public Conference getDisplayedConference(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 182 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 183 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 184 | @Override |
| 185 | public void onAttach(Activity activity) { |
| 186 | super.onAttach(activity); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 187 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 188 | if (!(activity instanceof Callbacks)) { |
| 189 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 190 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 191 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 192 | // rootView.requestDisallowInterceptTouchEvent(true); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 193 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 194 | mCallbacks = (Callbacks) activity; |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 195 | // myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me"); |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 196 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 197 | } |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 198 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 199 | @Override |
| 200 | public void onCreateOptionsMenu(Menu m, MenuInflater inf) { |
| 201 | super.onCreateOptionsMenu(m, inf); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 202 | inf.inflate(R.menu.ac_call, m); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public boolean onOptionsItemSelected(MenuItem item) { |
| 207 | super.onOptionsItemSelected(item); |
Alexandre Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame] | 208 | switch (item.getItemId()) { |
| 209 | case R.id.menuitem_chat: |
| 210 | mCallbacks.slideChatScreen(); |
| 211 | break; |
| 212 | } |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 213 | |
| 214 | return true; |
| 215 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 216 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 217 | @Override |
| 218 | public void onDetach() { |
| 219 | super.onDetach(); |
| 220 | mCallbacks = sDummyCallbacks; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 221 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 222 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 223 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 224 | public void onStop() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 225 | super.onStop(); |
| 226 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 227 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 228 | @Override |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 229 | public void onResume() { |
| 230 | super.onResume(); |
Alexandre Lision | a3c4f5f | 2014-01-07 17:22:22 -0500 | [diff] [blame] | 231 | initializeWiFiListener(); |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public void onPause() { |
| 236 | super.onPause(); |
Alexandre Lision | a3c4f5f | 2014-01-07 17:22:22 -0500 | [diff] [blame] | 237 | getActivity().unregisterReceiver(wifiReceiver); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 238 | if (wakeLock != null && wakeLock.isHeld()) { |
| 239 | wakeLock.release(); |
| 240 | } |
| 241 | |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | @Override |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 245 | public void callStateChanged(String callID, String state) { |
| 246 | changeCallState(callID, state); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | @Override |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 250 | public void recordingChanged(String callID, String filename) { |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 251 | |
| 252 | } |
| 253 | |
| 254 | @Override |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 255 | public void secureZrtpOn(String id) { |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 256 | Log.i(TAG, "secureZrtpOn"); |
| 257 | //enableSASButton(); |
| 258 | } |
| 259 | |
| 260 | @Override |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 261 | public void secureZrtpOff(String id) { |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 262 | Log.i(TAG, "secureZrtpOff"); |
| 263 | } |
| 264 | |
| 265 | @Override |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 266 | public void displaySAS(final String callID, String SAS, boolean verified) { |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 267 | Log.i(TAG, "displaySAS"); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 268 | final Button sas = (Button) getView().findViewById(R.id.confirm_sas); |
| 269 | sas.setText("Confirm SAS: " + SAS); |
| 270 | sas.setVisibility(View.VISIBLE); |
| 271 | sas.setOnClickListener(new OnClickListener() { |
| 272 | @Override |
| 273 | public void onClick(View v) { |
| 274 | try { |
| 275 | mCallbacks.getService().confirmSAS(callID); |
| 276 | sas.setVisibility(View.INVISIBLE); |
| 277 | } catch (RemoteException e) { |
| 278 | e.printStackTrace(); |
| 279 | } |
| 280 | } |
| 281 | }); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | @Override |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 285 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 286 | super.onActivityResult(requestCode, resultCode, data); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 287 | SipCall transfer; |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 288 | if (requestCode == REQUEST_TRANSFER) { |
| 289 | switch (resultCode) { |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 290 | case TransferDFragment.RESULT_TRANSFER_CONF: |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 291 | Conference c = data.getParcelableExtra("target"); |
| 292 | transfer = data.getParcelableExtra("transfer"); |
| 293 | try { |
| 294 | |
| 295 | mCallbacks.getService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId()); |
| 296 | |
| 297 | } catch (RemoteException e) { |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 298 | e.printStackTrace(); |
| 299 | } |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 300 | break; |
| 301 | |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 302 | case TransferDFragment.RESULT_TRANSFER_NUMBER: |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 303 | String to = data.getStringExtra("to_number"); |
| 304 | transfer = data.getParcelableExtra("transfer"); |
| 305 | try { |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 306 | mCallbacks.getService().transfer(transfer.getCallId(), to); |
| 307 | mCallbacks.getService().hangUp(transfer.getCallId()); |
| 308 | } catch (RemoteException e) { |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 309 | e.printStackTrace(); |
| 310 | } |
| 311 | break; |
Adrien Béraud | 9751284 | 2013-09-19 13:37:19 +1000 | [diff] [blame] | 312 | case Activity.RESULT_CANCELED: |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 313 | default: |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 314 | model.clear(); |
| 315 | initNormalStateDisplay(); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 316 | break; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | @Override |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 322 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
Alexandre Lision | 84208a3 | 2013-09-25 13:18:37 -0400 | [diff] [blame] | 323 | final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 324 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 325 | view = (BubblesView) rootView.findViewById(R.id.main_view); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 326 | view.setFragment(this); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 327 | view.setModel(model); |
| 328 | view.getHolder().addCallback(this); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 329 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 330 | callStatusTxt = (TextView) rootView.findViewById(R.id.call_status_txt); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 331 | call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_call); |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 332 | |
Alexandre Lision | baeeb21 | 2013-12-09 12:54:47 -0500 | [diff] [blame] | 333 | speakers = (ToggleButton) rootView.findViewById(R.id.speaker_toggle); |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 334 | |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 335 | speakers.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 336 | |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 337 | @Override |
| 338 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 339 | try { |
| 340 | mCallbacks.getService().toggleSpeakerPhone(isChecked); |
| 341 | } catch (RemoteException e) { |
| 342 | e.printStackTrace(); |
| 343 | } |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 344 | |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 345 | } |
| 346 | }); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 347 | |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 348 | rootView.findViewById(R.id.dialpad_btn).setOnClickListener(new OnClickListener() { |
Alexandre Lision | 84208a3 | 2013-09-25 13:18:37 -0400 | [diff] [blame] | 349 | |
| 350 | @Override |
| 351 | public void onClick(View v) { |
| 352 | InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); |
| 353 | lManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY); |
| 354 | } |
| 355 | }); |
| 356 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 357 | return rootView; |
| 358 | } |
Alexandre Lision | c30e841 | 2013-09-26 15:12:59 -0400 | [diff] [blame] | 359 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 360 | public Conference getConference(){ |
| 361 | return mCallbacks.getDisplayedConference(); |
| 362 | } |
| 363 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 364 | private void initNormalStateDisplay() { |
| 365 | Log.i(TAG, "Start normal display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 366 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 367 | mCallbacks.startTimer(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 368 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 369 | getBubbleForUser(getConference(), model.width / 2, model.height / 2); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 370 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 371 | int angle_part = 360 / getConference().getParticipants().size(); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 372 | double dX, dY; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 373 | int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 374 | for (int i = 0; i < getConference().getParticipants().size(); ++i) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 375 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 376 | if (getConference().getParticipants().get(i) == null) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 377 | continue; |
| 378 | } |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 379 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 380 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 381 | getBubbleFor(getConference().getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 382 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 383 | |
| 384 | model.clearAttractors(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 385 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 386 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 387 | private void initIncomingCallDisplay() { |
| 388 | Log.i(TAG, "Start incoming display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 389 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 390 | mCallbacks.startTimer(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 391 | |
Alexandre Lision | 23628c1 | 2013-09-24 11:17:05 -0400 | [diff] [blame] | 392 | int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 393 | getBubbleForUser(getConference(), model.width / 2, model.height / 2 + radiusCalls); |
| 394 | getBubbleFor(getConference().getParticipants().get(0), model.width / 2, model.height / 2 - radiusCalls); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 395 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 396 | model.clearAttractors(); |
Alexandre Lision | 23628c1 | 2013-09-24 11:17:05 -0400 | [diff] [blame] | 397 | model.addAttractor(new Attractor(new PointF(model.width / 2, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 398 | @Override |
| 399 | public boolean onBubbleSucked(Bubble b) { |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 400 | |
| 401 | if (!accepted) { |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 402 | try { |
| 403 | mCallbacks.getService().accept(b.getCallID()); |
| 404 | } catch (RemoteException e) { |
| 405 | e.printStackTrace(); |
| 406 | } |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 407 | accepted = true; |
| 408 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 409 | return false; |
| 410 | } |
| 411 | }, call_icon)); |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 412 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 413 | if (getConference().getParticipants().get(0).getAccount().isAutoanswerEnabled()) { |
Alexandre Lision | 332f491 | 2013-11-12 13:04:32 -0500 | [diff] [blame] | 414 | try { |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 415 | mCallbacks.getService().accept(getConference().getParticipants().get(0).getCallId()); |
Alexandre Lision | 332f491 | 2013-11-12 13:04:32 -0500 | [diff] [blame] | 416 | } catch (RemoteException e) { |
| 417 | e.printStackTrace(); |
| 418 | } |
| 419 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 420 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 421 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 422 | private void initOutGoingCallDisplay() { |
| 423 | Log.i(TAG, "Start outgoing display"); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 424 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 425 | mCallbacks.startTimer(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 426 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 427 | getBubbleForUser(getConference(), model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 428 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 429 | // TODO off-thread image loading |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 430 | int angle_part = 360 / getConference().getParticipants().size(); |
Alexandre Lision | 5f144b8 | 2014-02-11 09:59:36 -0500 | [diff] [blame] | 431 | double dX, dY; |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 432 | int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 433 | for (int i = 0; i < getConference().getParticipants().size(); ++i) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 434 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 435 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 436 | getBubbleFor(getConference().getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 437 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 438 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 439 | model.clearAttractors(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 440 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 441 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 442 | /** |
| 443 | * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location. |
| 444 | * |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 445 | * @param call |
| 446 | * The call associated to a contact |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 447 | * @param x |
| 448 | * Initial or new x position. |
| 449 | * @param y |
| 450 | * Initial or new y position. |
| 451 | * @return Bubble corresponding to the contact. |
| 452 | */ |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 453 | private Bubble getBubbleFor(SipCall call, float x, float y) { |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 454 | Bubble contact_bubble = model.getBubble(call.getCallId()); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 455 | if (contact_bubble != null) { |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 456 | ((BubbleContact) contact_bubble).setCall(call); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 457 | contact_bubble.attractor.set(x, y); |
| 458 | return contact_bubble; |
| 459 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 460 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 461 | contact_bubble = new BubbleContact(getActivity(), call, x, y, BUBBLE_SIZE); |
| 462 | |
| 463 | model.addBubble(contact_bubble); |
| 464 | return contact_bubble; |
| 465 | } |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 466 | |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 467 | private Bubble getBubbleForUser(Conference conf, float x, float y) { |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 468 | Bubble contact_bubble = model.getUser(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 469 | if (contact_bubble != null) { |
| 470 | contact_bubble.attractor.set(x, y); |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 471 | ((BubbleUser) contact_bubble).setConference(conf); |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 472 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 473 | return contact_bubble; |
| 474 | } |
| 475 | |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 476 | contact_bubble = new BubbleUser(getActivity(), CallContact.ContactBuilder.buildUserContact(getActivity().getContentResolver()), conf, x, y, |
| 477 | BUBBLE_SIZE * 1.3f); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 478 | |
Alexandre Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 479 | try { |
| 480 | ((BubbleUser) contact_bubble).setMute(mCallbacks.getService().isCaptureMuted()); |
| 481 | } catch (RemoteException e) { |
| 482 | e.printStackTrace(); |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 483 | } catch (NullPointerException e1) { |
Alexandre Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 484 | e1.printStackTrace(); |
| 485 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 486 | model.addBubble(contact_bubble); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 487 | return contact_bubble; |
| 488 | } |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 489 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 490 | public void changeCallState(String callID, String newState) { |
Alexandre Lision | e4b9584 | 2013-11-12 10:36:51 -0500 | [diff] [blame] | 491 | Log.i(TAG, "Call :" + callID + " " + newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 492 | if (newState.contentEquals("FAILURE")) { |
| 493 | try { |
| 494 | mCallbacks.getService().hangUp(callID); |
| 495 | } catch (RemoteException e) { |
| 496 | e.printStackTrace(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 497 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 498 | } |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 499 | if (getConference() == null) { |
Alexandre Lision | e4b9584 | 2013-11-12 10:36:51 -0500 | [diff] [blame] | 500 | return; |
| 501 | } |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 502 | for (int i = 0; i < getConference().getParticipants().size(); ++i) { |
| 503 | if (callID.equals(getConference().getParticipants().get(i).getCallId())) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 504 | if (newState.contentEquals("HUNGUP")) { |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 505 | model.removeBubble(getConference().getParticipants().get(i)); |
| 506 | getConference().getParticipants().remove(i); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 507 | } else { |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 508 | getConference().getParticipants().get(i).setCallState(newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 513 | if (getConference().isOnGoing()) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 514 | initNormalStateDisplay(); |
Alexandre Lision | 4fb2262 | 2013-10-21 16:26:33 -0400 | [diff] [blame] | 515 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 516 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 517 | if (getConference().getParticipants().size() == 0) { |
Alexandre Lision | e4b9584 | 2013-11-12 10:36:51 -0500 | [diff] [blame] | 518 | callStatusTxt.setText(newState); |
Alexandre Lision | dafe951 | 2013-10-28 16:31:41 -0400 | [diff] [blame] | 519 | mCallbacks.terminateCall(); |
Alexandre Lision | ccf0c93 | 2013-10-10 16:24:41 -0400 | [diff] [blame] | 520 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 521 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 522 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 523 | public boolean draggingBubble() { |
| 524 | return view == null ? false : view.isDraggingBubble(); |
| 525 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 526 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 527 | @Override |
| 528 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 529 | |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 530 | if (getConference().getParticipants().size() == 1) { |
| 531 | if (getConference().getParticipants().get(0).isIncoming() && getConference().getParticipants().get(0).isRinging()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 532 | initIncomingCallDisplay(); |
| 533 | } else { |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 534 | if (getConference().getParticipants().get(0).isRinging()) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 535 | initOutGoingCallDisplay(); |
| 536 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 537 | try { |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 538 | if (getConference().getParticipants().get(0).isOutGoing() |
| 539 | && mCallbacks.getService().getConference(getConference().getId()) == null) { |
| 540 | mCallbacks.getService().placeCall(getConference().getParticipants().get(0)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 541 | initOutGoingCallDisplay(); |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 542 | } else if (getConference().getParticipants().get(0).isOutGoing() && getConference().getParticipants().get(0).isRinging()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 543 | initOutGoingCallDisplay(); |
| 544 | } |
| 545 | } catch (RemoteException e) { |
| 546 | Log.e(TAG, e.toString()); |
| 547 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 548 | } |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 549 | if (getConference().getParticipants().get(0).isOngoing()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 550 | initNormalStateDisplay(); |
| 551 | } |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 552 | } else if (getConference().getParticipants().size() > 1) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 553 | initNormalStateDisplay(); |
| 554 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 555 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 556 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 557 | public void makeTransfer(BubbleContact contact) { |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 558 | FragmentManager fm = getFragmentManager(); |
Alexandre Lision | 0eb0203 | 2013-09-27 16:32:40 -0400 | [diff] [blame] | 559 | editName = TransferDFragment.newInstance(); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 560 | Bundle b = new Bundle(); |
Alexandre Lision | 6ae652d | 2013-09-26 16:39:20 -0400 | [diff] [blame] | 561 | try { |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 562 | b.putParcelableArrayList("calls", (ArrayList<Conference>) mCallbacks.getService().getConcurrentCalls()); |
Alexandre Lision | 6ae652d | 2013-09-26 16:39:20 -0400 | [diff] [blame] | 563 | b.putParcelable("call_selected", contact.associated_call); |
| 564 | editName.setArguments(b); |
| 565 | editName.setTargetFragment(this, REQUEST_TRANSFER); |
| 566 | editName.show(fm, ""); |
| 567 | } catch (RemoteException e) { |
| 568 | Log.e(TAG, e.toString()); |
| 569 | } |
| 570 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 571 | } |
| 572 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 573 | @Override |
| 574 | public void surfaceCreated(SurfaceHolder holder) { |
Alexandre Lision | c30e841 | 2013-09-26 15:12:59 -0400 | [diff] [blame] | 575 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 576 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 577 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 578 | @Override |
| 579 | public void surfaceDestroyed(SurfaceHolder holder) { |
Alexandre Lision | 84208a3 | 2013-09-25 13:18:37 -0400 | [diff] [blame] | 580 | // check that soft input is hidden |
| 581 | InputMethodManager lManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); |
| 582 | lManager.hideSoftInputFromWindow(view.getWindowToken(), 0); |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 583 | if (editName != null && editName.isVisible()) { |
Alexandre Lision | 0eb0203 | 2013-09-27 16:32:40 -0400 | [diff] [blame] | 584 | editName.dismiss(); |
| 585 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 586 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 587 | |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 588 | public BubblesView getBubbleView() { |
| 589 | return view; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 590 | } |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 591 | |
| 592 | public void updateTime() { |
Alexandre Lision | 48b49eb | 2014-02-11 13:37:33 -0500 | [diff] [blame] | 593 | long duration = System.currentTimeMillis() / 1000 - this.getConference().getParticipants().get(0).getTimestampStart_(); |
| 594 | if (getConference().isOnGoing()) |
Alexandre Lision | e4b9584 | 2013-11-12 10:36:51 -0500 | [diff] [blame] | 595 | callStatusTxt.setText(String.format("%d:%02d:%02d", duration / 3600, duration % 3600 / 60, duration % 60)); |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 596 | } |
| 597 | |
Alexandre Lision | 64dc8c0 | 2013-09-25 15:32:25 -0400 | [diff] [blame] | 598 | public void onKeyUp(int keyCode, KeyEvent event) { |
| 599 | try { |
Alexandre Lision | b8add81 | 2013-10-24 11:42:42 -0400 | [diff] [blame] | 600 | |
Alexandre Lision | fda4d1d | 2013-10-25 15:29:53 -0400 | [diff] [blame] | 601 | switch (keyCode) { |
| 602 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 603 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 604 | break; |
| 605 | default: |
| 606 | String toSend = Character.toString(event.getDisplayLabel()); |
| 607 | toSend.toUpperCase(Locale.getDefault()); |
| 608 | Log.d(TAG, "toSend " + toSend); |
| 609 | mCallbacks.getService().playDtmf(toSend); |
| 610 | break; |
| 611 | } |
Alexandre Lision | 64dc8c0 | 2013-09-25 15:32:25 -0400 | [diff] [blame] | 612 | } catch (RemoteException e) { |
| 613 | e.printStackTrace(); |
Alexandre Lision | 3e1e06f | 2014-02-10 12:13:25 -0500 | [diff] [blame] | 614 | } catch (NullPointerException e) { |
| 615 | e.printStackTrace(); |
Alexandre Lision | 64dc8c0 | 2013-09-25 15:32:25 -0400 | [diff] [blame] | 616 | } |
| 617 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 618 | } |