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