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