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