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