Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1 | /* |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 2 | * Copyright (C) 2004-2015 Savoir-faire Linux Inc. |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 5 | * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | package cx.ring.fragments; |
| 23 | |
| 24 | import android.app.Activity; |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 25 | import android.graphics.Color; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 26 | import android.net.Uri; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 27 | import android.support.v4.app.NotificationCompat; |
| 28 | import android.support.v4.app.NotificationManagerCompat; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 31 | import android.content.res.Resources; |
| 32 | import android.graphics.Bitmap; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 33 | import android.os.Bundle; |
| 34 | import android.os.PowerManager; |
| 35 | import android.os.PowerManager.WakeLock; |
| 36 | import android.os.RemoteException; |
Adrien Béraud | dde513c | 2015-10-22 11:21:52 -0400 | [diff] [blame] | 37 | import android.support.v7.app.ActionBar; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 38 | import android.util.Log; |
| 39 | import android.view.*; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 40 | import android.view.View.OnClickListener; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 41 | import android.widget.*; |
| 42 | import android.widget.CompoundButton.OnCheckedChangeListener; |
| 43 | import cx.ring.R; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 44 | import cx.ring.adapters.ContactPictureTask; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 45 | import cx.ring.client.ConversationActivity; |
| 46 | import cx.ring.client.HomeActivity; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 47 | import cx.ring.interfaces.CallInterface; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 48 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 49 | import java.util.Locale; |
| 50 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 51 | import cx.ring.model.CallContact; |
| 52 | import cx.ring.model.Conference; |
| 53 | import cx.ring.model.SecureSipCall; |
| 54 | import cx.ring.model.SipCall; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 55 | import cx.ring.model.account.Account; |
Adrien Béraud | 4c6d29b | 2015-11-19 18:10:35 -0500 | [diff] [blame] | 56 | import cx.ring.service.DRingService; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 57 | import cx.ring.service.LocalService; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 58 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 59 | public class CallFragment extends CallableWrapperFragment implements CallInterface { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 60 | |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 61 | static private final String TAG = CallFragment.class.getSimpleName(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 62 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 63 | public static final int REQUEST_TRANSFER = 10; |
| 64 | |
| 65 | // Screen wake lock for incoming call |
| 66 | private WakeLock mScreenWakeLock; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 67 | private ImageView contactBubbleView; |
| 68 | private TextView contactBubbleTxt; |
| 69 | private View acceptButton; |
| 70 | private View refuseButton; |
| 71 | private View hangupButton; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 72 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 73 | private View securityIndicator; |
| 74 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 75 | ViewSwitcher mSecuritySwitch; |
| 76 | private TextView mCallStatusTxt; |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 77 | private boolean mSpeakerPhone = false; |
| 78 | //private ToggleButton mToggleSpeakers; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 79 | |
| 80 | public Callbacks mCallbacks = sDummyCallbacks; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 81 | |
| 82 | TransferDFragment editName; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 83 | |
| 84 | @Override |
| 85 | public void onCreate(Bundle savedBundle) { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 86 | Log.i(TAG, "onCreate"); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 87 | super.onCreate(savedBundle); |
| 88 | |
| 89 | Resources r = getResources(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 90 | |
| 91 | setHasOptionsMenu(true); |
| 92 | PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); |
| 93 | mScreenWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 94 | "cx.ring.onIncomingCall"); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 95 | mScreenWakeLock.setReferenceCounted(false); |
| 96 | |
| 97 | Log.d(TAG, "Acquire wake up lock"); |
| 98 | if (mScreenWakeLock != null && !mScreenWakeLock.isHeld()) { |
| 99 | mScreenWakeLock.acquire(); |
| 100 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 104 | * The Activity calling this fragment has to implement this interface |
| 105 | */ |
| 106 | public interface Callbacks extends LocalService.Callbacks { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 107 | void startTimer(); |
| 108 | void terminateCall(); |
| 109 | Conference getDisplayedConference(); |
| 110 | void updateDisplayedConference(Conference c); |
Adrien Béraud | dde513c | 2015-10-22 11:21:52 -0400 | [diff] [blame] | 111 | ActionBar getSupportActionBar(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 115 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 116 | */ |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 117 | private static class DummyCallbacks extends LocalService.DummyCallbacks implements Callbacks { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 118 | @Override |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 119 | public void terminateCall() {} |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 120 | @Override |
| 121 | public Conference getDisplayedConference() { |
| 122 | return null; |
| 123 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 124 | @Override |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 125 | public void updateDisplayedConference(Conference c) { } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 126 | @Override |
Adrien Béraud | dde513c | 2015-10-22 11:21:52 -0400 | [diff] [blame] | 127 | public ActionBar getSupportActionBar() { return null; } |
| 128 | @Override |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 129 | public void startTimer() { } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 130 | } |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 131 | private static final Callbacks sDummyCallbacks = new DummyCallbacks(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 132 | |
| 133 | @Override |
| 134 | public void onAttach(Activity activity) { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 135 | Log.i(TAG, "onAttach"); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 136 | super.onAttach(activity); |
| 137 | |
| 138 | if (!(activity instanceof Callbacks)) { |
| 139 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 140 | } |
| 141 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 142 | mCallbacks = (Callbacks) activity; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 143 | } |
| 144 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 145 | public void refreshState() { |
| 146 | Conference conf = getConference(); |
| 147 | if (conf == null) { |
| 148 | contactBubbleView.setImageBitmap(null); |
| 149 | contactBubbleTxt.setText(""); |
| 150 | acceptButton.setVisibility(View.GONE); |
| 151 | refuseButton.setVisibility(View.GONE); |
| 152 | hangupButton.setVisibility(View.GONE); |
| 153 | } else if (conf.getParticipants().size() == 1) { |
| 154 | SipCall call = conf.getParticipants().get(0); |
| 155 | if (call.isIncoming() && call.isRinging()) { |
| 156 | Log.w(TAG, "CallFragment refreshState INCOMING " + call.getCallId()); |
| 157 | initIncomingCallDisplay(); |
| 158 | } else if (conf.getParticipants().get(0).isRinging()) { |
| 159 | Log.w(TAG, "CallFragment refreshState RINGING " + call.getCallId()); |
| 160 | initOutGoingCallDisplay(); |
| 161 | } else if (call.isOngoing()) { |
| 162 | initNormalStateDisplay(); |
| 163 | } |
| 164 | } else if (conf.getParticipants().size() > 1) { |
| 165 | initNormalStateDisplay(); |
| 166 | } |
| 167 | } |
| 168 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 169 | @Override |
| 170 | public void onCreateOptionsMenu(Menu m, MenuInflater inf) { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 171 | inf.inflate(R.menu.ac_call, m); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 172 | super.onCreateOptionsMenu(m, inf); |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public void onPrepareOptionsMenu(Menu menu) { |
| 177 | super.onPrepareOptionsMenu(menu); |
| 178 | MenuItem it = menu.findItem(R.id.menuitem_speaker); |
| 179 | if (it != null) { |
| 180 | if (it.getIcon() != null) |
| 181 | it.getIcon().setAlpha(mSpeakerPhone ? 255 : 128); |
| 182 | it.setChecked(mSpeakerPhone); |
| 183 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public boolean onOptionsItemSelected(MenuItem item) { |
| 188 | super.onOptionsItemSelected(item); |
| 189 | switch (item.getItemId()) { |
| 190 | case R.id.menuitem_chat: |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 191 | Intent intent = new Intent() |
| 192 | .setClass(getActivity(), ConversationActivity.class) |
| 193 | .setAction(Intent.ACTION_VIEW) |
| 194 | .setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, getConference().getParticipants().get(0).getContact().getIds().get(0))); |
| 195 | intent.putExtra("resuming", true); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 196 | startActivityForResult(intent, HomeActivity.REQUEST_CODE_CONVERSATION); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 197 | break; |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 198 | case R.id.menuitem_addcontact: |
| 199 | break; |
| 200 | case R.id.menuitem_speaker: |
| 201 | mSpeakerPhone = !mSpeakerPhone; |
| 202 | //setActionBarCheckboxChecked(item, !item.isChecked()); |
| 203 | try { |
| 204 | mCallbacks.getRemoteService().toggleSpeakerPhone(mSpeakerPhone); |
| 205 | } catch (RemoteException e) { |
| 206 | e.printStackTrace(); |
| 207 | } |
| 208 | getActivity().invalidateOptionsMenu(); |
| 209 | break; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | return true; |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public void onDetach() { |
| 217 | super.onDetach(); |
| 218 | mCallbacks = sDummyCallbacks; |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public void onStop() { |
| 223 | super.onStop(); |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public void onResume() { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 228 | Log.w(TAG, "onResume()"); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 229 | super.onResume(); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 230 | //initializeWiFiListener(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 231 | refreshState(); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 232 | |
| 233 | Conference c = getConference(); |
| 234 | if (c != null) { |
| 235 | c.mVisible = true; |
| 236 | NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity()); |
| 237 | notificationManager.cancel(c.notificationId); |
| 238 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public void onPause() { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 243 | Log.w(TAG, "onPause()"); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 244 | super.onPause(); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 245 | //getActivity().unregisterReceiver(wifiReceiver); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 246 | if (mScreenWakeLock != null && mScreenWakeLock.isHeld()) { |
| 247 | mScreenWakeLock.release(); |
| 248 | } |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 249 | Conference c = getConference(); |
| 250 | if (c != null) { |
| 251 | c.mVisible = false; |
| 252 | c.showCallNotification(getActivity()); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | public void confUpdate() { |
| 257 | LocalService service = mCallbacks.getService(); |
| 258 | if (service == null) |
| 259 | return; |
| 260 | |
| 261 | Conference c = service.getConference(getConference().getId()); |
| 262 | mCallbacks.updateDisplayedConference(c); |
| 263 | if (c == null || c.getParticipants().isEmpty()) { |
| 264 | mCallbacks.terminateCall(); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | String newState = c.getState(); |
| 269 | if (c.isOnGoing()) { |
| 270 | initNormalStateDisplay(); |
| 271 | } else if (c.isRinging()) { |
| 272 | mCallStatusTxt.setText(newState); |
| 273 | |
| 274 | if (c.isIncoming()) { |
| 275 | initIncomingCallDisplay(); |
| 276 | } else |
| 277 | initOutGoingCallDisplay(); |
| 278 | } else { |
| 279 | NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity()); |
| 280 | notificationManager.cancel(c.notificationId); |
| 281 | mCallStatusTxt.setText(newState); |
| 282 | mCallbacks.terminateCall(); |
| 283 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void callStateChanged(Conference updated, String callID, String newState) { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 288 | Conference cur = getConference(); |
| 289 | if (cur.getId().equals(callID) || cur.getCallById(callID) != null) { |
| 290 | mCallbacks.updateDisplayedConference(updated); |
| 291 | } else { |
| 292 | return; |
| 293 | } |
| 294 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 295 | Log.i(TAG, "Call :" + callID + " " + newState); |
| 296 | |
| 297 | if (getConference().isOnGoing()) { |
| 298 | initNormalStateDisplay(); |
| 299 | } else if (getConference().isRinging()) { |
| 300 | mCallStatusTxt.setText(newState); |
| 301 | |
| 302 | if (getConference().isIncoming()) { |
| 303 | initIncomingCallDisplay(); |
| 304 | } else |
| 305 | initOutGoingCallDisplay(); |
| 306 | } else { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 307 | NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity()); |
| 308 | notificationManager.cancel(getConference().notificationId); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 309 | mCallStatusTxt.setText(newState); |
| 310 | mCallbacks.terminateCall(); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public void secureZrtpOn(Conference updated, String id) { |
| 316 | Log.i(TAG, "secureZrtpOn"); |
| 317 | mCallbacks.updateDisplayedConference(updated); |
| 318 | updateSecurityDisplay(); |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public void secureZrtpOff(Conference updated, String id) { |
| 323 | Log.i(TAG, "secureZrtpOff"); |
| 324 | mCallbacks.updateDisplayedConference(updated); |
| 325 | updateSecurityDisplay(); |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public void displaySAS(Conference updated, final String securedCallID) { |
| 330 | Log.i(TAG, "displaySAS"); |
| 331 | mCallbacks.updateDisplayedConference(updated); |
| 332 | updateSecurityDisplay(); |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void zrtpNegotiationFailed(Conference c, String securedCallID) { |
| 337 | mCallbacks.updateDisplayedConference(c); |
| 338 | updateSecurityDisplay(); |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public void zrtpNotSupported(Conference c, String securedCallID) { |
| 343 | mCallbacks.updateDisplayedConference(c); |
| 344 | updateSecurityDisplay(); |
| 345 | } |
| 346 | |
| 347 | @Override |
| 348 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 349 | super.onActivityResult(requestCode, resultCode, data); |
| 350 | SipCall transfer; |
| 351 | if (requestCode == REQUEST_TRANSFER) { |
| 352 | switch (resultCode) { |
| 353 | case TransferDFragment.RESULT_TRANSFER_CONF: |
| 354 | Conference c = data.getParcelableExtra("target"); |
| 355 | transfer = data.getParcelableExtra("transfer"); |
| 356 | try { |
| 357 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 358 | mCallbacks.getRemoteService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 359 | |
| 360 | } catch (RemoteException e) { |
| 361 | e.printStackTrace(); |
| 362 | } |
| 363 | break; |
| 364 | |
| 365 | case TransferDFragment.RESULT_TRANSFER_NUMBER: |
| 366 | String to = data.getStringExtra("to_number"); |
| 367 | transfer = data.getParcelableExtra("transfer"); |
| 368 | try { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 369 | mCallbacks.getRemoteService().transfer(transfer.getCallId(), to); |
| 370 | mCallbacks.getRemoteService().hangUp(transfer.getCallId()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 371 | } catch (RemoteException e) { |
| 372 | e.printStackTrace(); |
| 373 | } |
| 374 | break; |
| 375 | case Activity.RESULT_CANCELED: |
| 376 | default: |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 377 | /*synchronized (mBubbleModel) { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 378 | mBubbleModel.clear(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 379 | }*/ |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 380 | initNormalStateDisplay(); |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | @Override |
| 387 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 388 | Log.i(TAG, "onCreateView"); |
| 389 | final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false); |
| 390 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 391 | contactBubbleView = (ImageView) rootView.findViewById(R.id.contact_bubble); |
| 392 | contactBubbleTxt = (TextView) rootView.findViewById(R.id.contact_bubble_txt); |
| 393 | acceptButton = rootView.findViewById(R.id.call_accept_btn); |
| 394 | refuseButton = rootView.findViewById(R.id.call_refuse_btn); |
| 395 | hangupButton = rootView.findViewById(R.id.call_hangup_btn); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 396 | |
| 397 | mCallStatusTxt = (TextView) rootView.findViewById(R.id.call_status_txt); |
| 398 | |
| 399 | mSecuritySwitch = (ViewSwitcher) rootView.findViewById(R.id.security_switcher); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 400 | /*mToggleSpeakers = (ToggleButton) rootView.findViewById(R.id.speaker_toggle); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 401 | |
| 402 | mToggleSpeakers.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 403 | |
| 404 | @Override |
| 405 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 406 | try { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 407 | mCallbacks.getRemoteService().toggleSpeakerPhone(isChecked); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 408 | } catch (RemoteException e) { |
| 409 | e.printStackTrace(); |
| 410 | } |
| 411 | |
| 412 | } |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 413 | });*/ |
| 414 | |
| 415 | securityIndicator = rootView.findViewById(R.id.security_indicator); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 416 | return rootView; |
| 417 | } |
| 418 | |
| 419 | public Conference getConference() { |
| 420 | return mCallbacks.getDisplayedConference(); |
| 421 | } |
| 422 | |
| 423 | private void initNormalStateDisplay() { |
| 424 | Log.i(TAG, "Start normal display"); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 425 | mCallbacks.startTimer(); |
| 426 | acceptButton.setVisibility(View.GONE); |
| 427 | refuseButton.setVisibility(View.GONE); |
| 428 | |
| 429 | final SipCall call = getConference().getParticipants().get(0); |
| 430 | CallContact contact = call.getContact(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 431 | new ContactPictureTask(getActivity(), contactBubbleView, contact).run(); |
| 432 | contactBubbleTxt.setText(contact.getDisplayName()); |
| 433 | |
| 434 | hangupButton.setVisibility(View.VISIBLE); |
| 435 | hangupButton.setOnClickListener(new OnClickListener() { |
| 436 | @Override |
| 437 | public void onClick(View v) { |
| 438 | try { |
| 439 | mCallbacks.getRemoteService().hangUp(call.getCallId()); |
| 440 | mCallbacks.terminateCall(); |
| 441 | } catch (RemoteException e) { |
| 442 | e.printStackTrace(); |
| 443 | } |
| 444 | } |
| 445 | }); |
| 446 | |
Adrien Béraud | dde513c | 2015-10-22 11:21:52 -0400 | [diff] [blame] | 447 | mCallbacks.getSupportActionBar().setTitle(contact.getDisplayName()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 448 | updateSecurityDisplay(); |
| 449 | } |
| 450 | |
| 451 | private void updateSecurityDisplay() { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 452 | //First we check if all participants use a security layer. |
| 453 | boolean secure_call = !getConference().getParticipants().isEmpty(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 454 | for (SipCall c : getConference().getParticipants()) { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 455 | //Account acc = mCallbacks.getService().getAccount(c.getAccount()); |
| 456 | secure_call &= c instanceof SecureSipCall && ((SecureSipCall)c).isSecure(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | securityIndicator.setVisibility(secure_call ? View.VISIBLE : View.GONE); |
| 460 | if (!secure_call) |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 461 | return; |
| 462 | |
| 463 | Log.i(TAG, "Enable security display"); |
| 464 | if (getConference().hasMultipleParticipants()) { |
| 465 | //TODO What layout should we put? |
| 466 | } else { |
| 467 | final SecureSipCall secured = (SecureSipCall) getConference().getParticipants().get(0); |
| 468 | switch (secured.displayModule()) { |
| 469 | case SecureSipCall.DISPLAY_GREEN_LOCK: |
| 470 | Log.i(TAG, "DISPLAY_GREEN_LOCK"); |
| 471 | showLock(R.drawable.green_lock); |
| 472 | break; |
| 473 | case SecureSipCall.DISPLAY_RED_LOCK: |
| 474 | Log.i(TAG, "DISPLAY_RED_LOCK"); |
| 475 | showLock(R.drawable.red_lock); |
| 476 | break; |
| 477 | case SecureSipCall.DISPLAY_CONFIRM_SAS: |
| 478 | final Button sas = (Button) mSecuritySwitch.findViewById(R.id.confirm_sas); |
| 479 | Log.i(TAG, "Confirm SAS: " + secured.getSAS()); |
| 480 | sas.setText("Confirm SAS: " + secured.getSAS()); |
| 481 | sas.setOnClickListener(new View.OnClickListener() { |
| 482 | @Override |
| 483 | public void onClick(View v) { |
| 484 | try { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 485 | mCallbacks.getRemoteService().confirmSAS(secured.getCallId()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 486 | showLock(R.drawable.green_lock); |
| 487 | } catch (RemoteException e) { |
| 488 | e.printStackTrace(); |
| 489 | } |
| 490 | } |
| 491 | }); |
| 492 | mSecuritySwitch.setDisplayedChild(0); |
| 493 | mSecuritySwitch.setVisibility(View.VISIBLE); |
| 494 | break; |
| 495 | case SecureSipCall.DISPLAY_NONE: |
| 496 | break; |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | private void showLock(int resId) { |
| 502 | ImageView lock = (ImageView) mSecuritySwitch.findViewById(R.id.lock_image); |
| 503 | lock.setImageDrawable(getResources().getDrawable(resId)); |
| 504 | mSecuritySwitch.setDisplayedChild(1); |
| 505 | mSecuritySwitch.setVisibility(View.VISIBLE); |
| 506 | } |
| 507 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 508 | protected Bitmap getContactPhoto(CallContact contact, int size) { |
| 509 | if (contact.getPhotoId() > 0) { |
| 510 | return ContactPictureTask.loadContactPhoto(getActivity().getContentResolver(), contact.getId()); |
| 511 | } else { |
| 512 | return ContactPictureTask.decodeSampledBitmapFromResource(getResources(), R.drawable.ic_contact_picture, size, size); |
| 513 | } |
| 514 | } |
| 515 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 516 | private void initIncomingCallDisplay() { |
| 517 | Log.i(TAG, "Start incoming display"); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 518 | if (mCallbacks.getService().getAccount(getConference().getParticipants().get(0).getAccount()).isAutoanswerEnabled()) { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 519 | try { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 520 | mCallbacks.getRemoteService().accept(getConference().getParticipants().get(0).getCallId()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 521 | } catch (RemoteException e) { |
| 522 | e.printStackTrace(); |
| 523 | } catch (NullPointerException e) { |
| 524 | e.printStackTrace(); |
| 525 | } |
| 526 | } else { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 527 | final SipCall call = getConference().getParticipants().get(0); |
| 528 | CallContact contact = call.getContact(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 529 | new ContactPictureTask(getActivity(), contactBubbleView, contact).run(); |
| 530 | contactBubbleTxt.setText(contact.getDisplayName()); |
| 531 | acceptButton.setVisibility(View.VISIBLE); |
| 532 | acceptButton.setOnClickListener(new OnClickListener() { |
| 533 | @Override |
| 534 | public void onClick(View v) { |
| 535 | acceptButton.setOnClickListener(null); |
| 536 | refuseButton.setOnClickListener(null); |
| 537 | try { |
| 538 | mCallbacks.getRemoteService().accept(call.getCallId()); |
| 539 | } catch (RemoteException e) { |
| 540 | e.printStackTrace(); |
| 541 | } |
| 542 | } |
| 543 | }); |
| 544 | refuseButton.setVisibility(View.VISIBLE); |
| 545 | refuseButton.setOnClickListener(new OnClickListener() { |
| 546 | @Override |
| 547 | public void onClick(View v) { |
| 548 | acceptButton.setOnClickListener(null); |
| 549 | refuseButton.setOnClickListener(null); |
| 550 | try { |
| 551 | mCallbacks.getRemoteService().refuse(call.getCallId()); |
| 552 | mCallbacks.terminateCall(); |
| 553 | } catch (RemoteException e) { |
| 554 | e.printStackTrace(); |
| 555 | } |
| 556 | } |
| 557 | }); |
| 558 | hangupButton.setVisibility(View.GONE); |
Adrien Béraud | dde513c | 2015-10-22 11:21:52 -0400 | [diff] [blame] | 559 | mCallbacks.getSupportActionBar().setTitle(contact.getDisplayName()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 560 | } |
| 561 | } |
| 562 | |
| 563 | private void initOutGoingCallDisplay() { |
| 564 | Log.i(TAG, "Start outgoing display"); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 565 | |
| 566 | final SipCall call = getConference().getParticipants().get(0); |
| 567 | CallContact contact = call.getContact(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 568 | new ContactPictureTask(getActivity(), contactBubbleView, contact).run(); |
| 569 | contactBubbleTxt.setText(contact.getDisplayName()); |
| 570 | |
| 571 | acceptButton.setVisibility(View.GONE); |
| 572 | refuseButton.setVisibility(View.GONE); |
| 573 | |
| 574 | hangupButton.setVisibility(View.VISIBLE); |
| 575 | hangupButton.setOnClickListener(new OnClickListener() { |
| 576 | @Override |
| 577 | public void onClick(View v) { |
| 578 | try { |
| 579 | mCallbacks.getRemoteService().hangUp(call.getCallId()); |
| 580 | mCallbacks.terminateCall(); |
| 581 | } catch (RemoteException e) { |
| 582 | e.printStackTrace(); |
| 583 | } |
| 584 | } |
| 585 | }); |
| 586 | |
Adrien Béraud | dde513c | 2015-10-22 11:21:52 -0400 | [diff] [blame] | 587 | mCallbacks.getSupportActionBar().setTitle(contact.getDisplayName()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 588 | } |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 589 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 590 | /* |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 591 | public void makeTransfer(BubbleContact contact) { |
| 592 | FragmentManager fm = getFragmentManager(); |
| 593 | editName = TransferDFragment.newInstance(); |
| 594 | Bundle b = new Bundle(); |
| 595 | try { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 596 | b.putParcelableArrayList("calls", (ArrayList<Conference>) mCallbacks.getRemoteService().getConcurrentCalls()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 597 | b.putParcelable("call_selected", contact.associated_call); |
| 598 | editName.setArguments(b); |
| 599 | editName.setTargetFragment(this, REQUEST_TRANSFER); |
| 600 | editName.show(fm, ""); |
| 601 | } catch (RemoteException e) { |
| 602 | Log.e(TAG, e.toString()); |
| 603 | } |
| 604 | |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 605 | }*/ |
Adrien Béraud | 4c6d29b | 2015-11-19 18:10:35 -0500 | [diff] [blame] | 606 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 607 | public void updateTime() { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame^] | 608 | if (getConference() != null && !getConference().getParticipants().isEmpty()) { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 609 | long duration = System.currentTimeMillis() - getConference().getParticipants().get(0).getTimestampStart(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 610 | duration = duration / 1000; |
| 611 | if (getConference().isOnGoing()) |
| 612 | mCallStatusTxt.setText(String.format("%d:%02d:%02d", duration / 3600, duration % 3600 / 60, duration % 60)); |
| 613 | } |
| 614 | |
| 615 | } |
| 616 | |
| 617 | public void onKeyUp(int keyCode, KeyEvent event) { |
| 618 | try { |
| 619 | |
| 620 | switch (keyCode) { |
| 621 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 622 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 623 | break; |
| 624 | default: |
| 625 | String toSend = Character.toString(event.getDisplayLabel()); |
| 626 | toSend = toSend.toUpperCase(Locale.getDefault()); |
| 627 | Log.d(TAG, "toSend " + toSend); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 628 | mCallbacks.getRemoteService().playDtmf(toSend); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 629 | break; |
| 630 | } |
| 631 | } catch (RemoteException e) { |
| 632 | e.printStackTrace(); |
| 633 | } catch (NullPointerException e) { |
| 634 | e.printStackTrace(); |
| 635 | } |
| 636 | } |
| 637 | } |