alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 1 | /* |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 2 | * Copyright (C) 2004-2013 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 | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 33 | |
| 34 | import java.util.ArrayList; |
| 35 | import java.util.HashMap; |
| 36 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 37 | import org.sflphone.R; |
| 38 | import org.sflphone.model.Conference; |
| 39 | import org.sflphone.model.SipCall; |
| 40 | import org.sflphone.service.ISipService; |
| 41 | import org.sflphone.views.SwipeListViewTouchListener; |
| 42 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 43 | import android.app.Activity; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 44 | import android.app.AlertDialog; |
| 45 | import android.app.Dialog; |
| 46 | import android.app.DialogFragment; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 47 | import android.app.Fragment; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 48 | import android.content.ClipData; |
| 49 | import android.content.ClipData.Item; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 50 | import android.content.Context; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 51 | import android.content.DialogInterface; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 52 | import android.content.Intent; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 53 | import android.graphics.Color; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 54 | import android.os.Bundle; |
| 55 | import android.os.RemoteException; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 56 | import android.os.Vibrator; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 57 | import android.util.Log; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 58 | import android.view.DragEvent; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 59 | import android.view.LayoutInflater; |
| 60 | import android.view.View; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 61 | import android.view.View.DragShadowBuilder; |
| 62 | import android.view.View.OnDragListener; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 63 | import android.view.ViewGroup; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 64 | import android.widget.AdapterView; |
| 65 | import android.widget.AdapterView.OnItemClickListener; |
| 66 | import android.widget.AdapterView.OnItemLongClickListener; |
| 67 | import android.widget.ArrayAdapter; |
| 68 | import android.widget.BaseAdapter; |
| 69 | import android.widget.ListAdapter; |
| 70 | import android.widget.ListView; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 71 | import android.widget.TextView; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 72 | import android.widget.Toast; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 73 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 74 | public class CallListFragment extends Fragment { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 75 | static final String TAG = CallListFragment.class.getSimpleName(); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 76 | |
| 77 | private Callbacks mCallbacks = sDummyCallbacks; |
| 78 | |
| 79 | CallListAdapter mAdapter; |
| 80 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 81 | public static final int REQUEST_TRANSFER = 10; |
| 82 | public static final int REQUEST_CONF = 20; |
| 83 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 84 | @Override |
| 85 | public void onCreate(Bundle savedBundle) { |
| 86 | super.onCreate(savedBundle); |
| 87 | |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 88 | mAdapter = new CallListAdapter(getActivity()); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 89 | |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 94 | */ |
| 95 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 96 | |
| 97 | @Override |
| 98 | public ISipService getService() { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 99 | return null; |
| 100 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 101 | |
| 102 | @Override |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 103 | public void onCallSelected(Conference conf) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public void onCallsTerminated() { |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 108 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | /** |
| 112 | * The Activity calling this fragment has to implement this interface |
| 113 | * |
| 114 | */ |
| 115 | public interface Callbacks { |
| 116 | public ISipService getService(); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 117 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 118 | public void onCallSelected(Conference conf); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 119 | |
| 120 | public void onCallsTerminated(); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 121 | |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public void onAttach(Activity activity) { |
| 126 | super.onAttach(activity); |
| 127 | |
| 128 | if (!(activity instanceof Callbacks)) { |
| 129 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 130 | } |
| 131 | |
| 132 | mCallbacks = (Callbacks) activity; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public void onDetach() { |
| 137 | super.onDetach(); |
| 138 | mCallbacks = sDummyCallbacks; |
| 139 | } |
| 140 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 141 | ListView list; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 142 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 143 | @Override |
| 144 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 145 | ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call_list, container, false); |
| 146 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 147 | list = (ListView) rootView.findViewById(R.id.call_list); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 148 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 149 | list.setDivider(getResources().getDrawable(android.R.drawable.divider_horizontal_dark)); |
| 150 | list.setDividerHeight(10); |
| 151 | list.setAdapter(mAdapter); |
| 152 | list.setOnItemClickListener(mItemClickListener); |
| 153 | list.setOnTouchListener(new SwipeListViewTouchListener(list, new SwipeListViewTouchListener.OnSwipeCallback() { |
| 154 | @Override |
| 155 | public void onSwipeLeft(ListView listView, int[] reverseSortedPositions) { |
| 156 | // Log.i(this.getClass().getName(), "swipe left : pos="+reverseSortedPositions[0]); |
| 157 | // TODO : YOUR CODE HERE FOR LEFT ACTION |
alision | f2ae436 | 2013-07-05 16:16:12 -0400 | [diff] [blame] | 158 | Conference tmp = mAdapter.getItem(reverseSortedPositions[0]); |
| 159 | try { |
| 160 | if (tmp.hasMultipleParticipants()) { |
| 161 | mCallbacks.getService().hangUpConference(tmp.getId()); |
| 162 | } else { |
| 163 | mCallbacks.getService().hangUp(tmp.getParticipants().get(0).getCallId()); |
| 164 | } |
| 165 | } catch (RemoteException e) { |
| 166 | // TODO Auto-generated catch block |
| 167 | e.printStackTrace(); |
| 168 | } |
| 169 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void onSwipeRight(ListView listView, int[] reverseSortedPositions) { |
| 174 | // Log.i(ProfileMenuActivity.class.getClass().getName(), "swipe right : pos="+reverseSortedPositions[0]); |
| 175 | // TODO : YOUR CODE HERE FOR RIGHT ACTION |
alision | f2ae436 | 2013-07-05 16:16:12 -0400 | [diff] [blame] | 176 | |
| 177 | Conference tmp = mAdapter.getItem(reverseSortedPositions[0]); |
| 178 | try { |
| 179 | if (tmp.hasMultipleParticipants()) { |
| 180 | if (tmp.isOnHold()) { |
| 181 | mCallbacks.getService().unholdConference(tmp.getId()); |
| 182 | } else { |
| 183 | mCallbacks.getService().holdConference(tmp.getId()); |
| 184 | } |
| 185 | } else { |
| 186 | if (tmp.isOnHold()) { |
| 187 | Toast.makeText(getActivity(), "call is on hold, unholding", Toast.LENGTH_SHORT).show(); |
| 188 | mCallbacks.getService().unhold(tmp.getParticipants().get(0).getCallId()); |
| 189 | } else { |
| 190 | Toast.makeText(getActivity(), "call is current, holding", Toast.LENGTH_SHORT).show(); |
| 191 | mCallbacks.getService().hold(tmp.getParticipants().get(0).getCallId()); |
| 192 | } |
| 193 | } |
| 194 | } catch (RemoteException e) { |
| 195 | // TODO Auto-generated catch block |
| 196 | e.printStackTrace(); |
| 197 | } |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 198 | } |
| 199 | }, true, // example : left action = dismiss |
| 200 | false)); // example : right action without dismiss animation); |
| 201 | list.setOnItemLongClickListener(mItemLongClickListener); |
| 202 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 203 | return rootView; |
| 204 | } |
| 205 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 206 | OnDragListener dragListener = new OnDragListener() { |
| 207 | |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 208 | @SuppressWarnings("deprecation") // deprecated in API 16.... |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 209 | @Override |
| 210 | public boolean onDrag(View v, DragEvent event) { |
| 211 | switch (event.getAction()) { |
| 212 | case DragEvent.ACTION_DRAG_STARTED: |
| 213 | // Do nothing |
| 214 | Log.w(TAG, "ACTION_DRAG_STARTED"); |
| 215 | break; |
| 216 | case DragEvent.ACTION_DRAG_ENTERED: |
| 217 | Log.w(TAG, "ACTION_DRAG_ENTERED"); |
| 218 | v.setBackgroundColor(Color.GREEN); |
| 219 | break; |
| 220 | case DragEvent.ACTION_DRAG_EXITED: |
| 221 | Log.w(TAG, "ACTION_DRAG_EXITED"); |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 222 | v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_contact_selector)); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 223 | break; |
| 224 | case DragEvent.ACTION_DROP: |
| 225 | Log.w(TAG, "ACTION_DROP"); |
| 226 | View view = (View) event.getLocalState(); |
| 227 | |
| 228 | Item i = event.getClipData().getItemAt(0); |
| 229 | Intent intent = i.getIntent(); |
| 230 | intent.setExtrasClassLoader(Conference.class.getClassLoader()); |
| 231 | |
| 232 | Conference initial = (Conference) view.getTag(); |
| 233 | Conference target = (Conference) v.getTag(); |
alision | f2ae436 | 2013-07-05 16:16:12 -0400 | [diff] [blame] | 234 | |
| 235 | if (initial == target) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 236 | return true; |
| 237 | } |
| 238 | |
| 239 | DropActionsChoice dialog = DropActionsChoice.newInstance(); |
| 240 | Bundle b = new Bundle(); |
| 241 | b.putParcelable("call_initial", initial); |
| 242 | b.putParcelable("call_targeted", target); |
| 243 | dialog.setArguments(b); |
| 244 | dialog.setTargetFragment(CallListFragment.this, 0); |
| 245 | dialog.show(getFragmentManager(), "dialog"); |
| 246 | |
| 247 | Toast.makeText( |
| 248 | getActivity(), |
| 249 | "Dropped " + initial.getParticipants().get(0).getContact().getmDisplayName() + " on " |
| 250 | + target.getParticipants().get(0).getContact().getmDisplayName(), Toast.LENGTH_SHORT).show(); |
| 251 | // view.setBackgroundColor(Color.WHITE); |
| 252 | // v.setBackgroundColor(Color.BLACK); |
| 253 | break; |
| 254 | case DragEvent.ACTION_DRAG_ENDED: |
| 255 | Log.w(TAG, "ACTION_DRAG_ENDED"); |
| 256 | View view1 = (View) event.getLocalState(); |
| 257 | view1.setVisibility(View.VISIBLE); |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 258 | v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_contact_selector)); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 259 | default: |
| 260 | break; |
| 261 | } |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | }; |
| 266 | |
| 267 | private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() { |
| 268 | |
| 269 | @Override |
| 270 | public boolean onItemLongClick(AdapterView<?> arg0, View view, int pos, long arg3) { |
| 271 | final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE); |
| 272 | vibe.vibrate(80); |
| 273 | Intent i = new Intent(); |
| 274 | Bundle b = new Bundle(); |
| 275 | b.putParcelable("conference", mAdapter.getItem(pos)); |
| 276 | i.putExtra("bconference", b); |
alision | f2ae436 | 2013-07-05 16:16:12 -0400 | [diff] [blame] | 277 | |
| 278 | DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 279 | ClipData data = ClipData.newIntent("conference", i); |
| 280 | view.startDrag(data, shadowBuilder, view, 0); |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | }; |
| 285 | |
| 286 | private OnItemClickListener mItemClickListener = new OnItemClickListener() { |
| 287 | |
| 288 | @Override |
| 289 | public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) { |
| 290 | mCallbacks.onCallSelected(mAdapter.getItem(pos)); |
| 291 | |
| 292 | } |
| 293 | }; |
| 294 | |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 295 | @SuppressWarnings("unchecked") // No proper solution with HashMap runtime cast |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 296 | public void update() { |
| 297 | try { |
| 298 | HashMap<String, SipCall> list = (HashMap<String, SipCall>) mCallbacks.getService().getCallList(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 299 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 300 | // Toast.makeText(getActivity(), "Calls: " + list.size(), Toast.LENGTH_SHORT).show(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 301 | ArrayList<Conference> conferences = new ArrayList<Conference>(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 302 | HashMap<String, Conference> tmp = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList(); |
| 303 | conferences.addAll(tmp.values()); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 304 | |
| 305 | ArrayList<SipCall> simple_calls = new ArrayList<SipCall>(list.values()); |
| 306 | for (SipCall call : simple_calls) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 307 | Conference confOne = new Conference("-1"); |
| 308 | confOne.getParticipants().add(call); |
| 309 | conferences.add(confOne); |
| 310 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 311 | |
| 312 | if (conferences.isEmpty()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 313 | mCallbacks.onCallsTerminated(); |
| 314 | } |
| 315 | |
| 316 | mAdapter.update(conferences); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 317 | } catch (RemoteException e) { |
| 318 | Log.e(TAG, e.toString()); |
| 319 | } |
| 320 | |
| 321 | } |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 322 | |
Alexandre Lision | 80a9916 | 2013-09-13 14:19:23 -0400 | [diff] [blame] | 323 | // private void makeTransferDialog(int groupPosition) { |
| 324 | // FragmentManager fm = getFragmentManager(); |
| 325 | // TransferDFragment editNameDialog = new TransferDFragment(); |
| 326 | // |
| 327 | // if (!mAdapter.getItem(groupPosition).hasMultipleParticipants()) { |
| 328 | // Bundle b = new Bundle(); |
| 329 | // b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition)); |
| 330 | // b.putParcelable("call_selected", mAdapter.getItem(groupPosition)); |
| 331 | // editNameDialog.setArguments(b); |
| 332 | // editNameDialog.setTargetFragment(this, REQUEST_TRANSFER); |
| 333 | // editNameDialog.show(fm, "dialog"); |
| 334 | // } else { |
| 335 | // Toast.makeText(getActivity(), "Transfer a Conference ?", Toast.LENGTH_SHORT).show(); |
| 336 | // } |
| 337 | // |
| 338 | // } |
| 339 | // |
| 340 | // private void makeConferenceDialog(int groupPosition) { |
| 341 | // FragmentManager fm = getFragmentManager(); |
| 342 | // ConferenceDFragment confDialog = ConferenceDFragment.newInstance(); |
| 343 | // |
| 344 | // Bundle b = new Bundle(); |
| 345 | // b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition)); |
| 346 | // b.putParcelable("call_selected", mAdapter.getItem(groupPosition)); |
| 347 | // confDialog.setArguments(b); |
| 348 | // confDialog.setTargetFragment(this, REQUEST_CONF); |
| 349 | // confDialog.show(fm, "dialog"); |
| 350 | // |
| 351 | // } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 352 | |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 353 | @Override |
| 354 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 355 | super.onActivityResult(requestCode, resultCode, data); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 356 | Conference transfer = null; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 357 | if (requestCode == REQUEST_TRANSFER) { |
| 358 | switch (resultCode) { |
| 359 | case 0: |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 360 | Conference c = data.getParcelableExtra("target"); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 361 | transfer = data.getParcelableExtra("transfer"); |
| 362 | try { |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 363 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 364 | mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId()); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 365 | mAdapter.remove(transfer); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 366 | mAdapter.remove(c); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 367 | mAdapter.notifyDataSetChanged(); |
| 368 | } catch (RemoteException e) { |
| 369 | // TODO Auto-generated catch block |
| 370 | e.printStackTrace(); |
| 371 | } |
| 372 | Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show(); |
| 373 | break; |
| 374 | |
| 375 | case 1: |
| 376 | String to = data.getStringExtra("to_number"); |
| 377 | transfer = data.getParcelableExtra("transfer"); |
| 378 | try { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 379 | Toast.makeText(getActivity(), "Transferring " + transfer.getParticipants().get(0).getContact().getmDisplayName() + " to " + to, |
| 380 | Toast.LENGTH_SHORT).show(); |
| 381 | mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to); |
| 382 | mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId()); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 383 | } catch (RemoteException e) { |
| 384 | // TODO Auto-generated catch block |
| 385 | e.printStackTrace(); |
| 386 | } |
| 387 | break; |
| 388 | |
| 389 | default: |
| 390 | break; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 391 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 392 | } else if (requestCode == REQUEST_CONF) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 393 | switch (resultCode) { |
| 394 | case 0: |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 395 | Conference call_to_add = data.getParcelableExtra("transfer"); |
| 396 | Conference call_target = data.getParcelableExtra("target"); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 397 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 398 | bindCalls(call_to_add, call_target); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 399 | break; |
| 400 | |
| 401 | default: |
| 402 | break; |
| 403 | } |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 407 | private void bindCalls(Conference call_to_add, Conference call_target) { |
| 408 | try { |
| 409 | |
| 410 | if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) { |
| 411 | |
| 412 | mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId()); |
| 413 | |
| 414 | } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) { |
| 415 | |
| 416 | // We join two conferences |
| 417 | mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId()); |
| 418 | |
| 419 | } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) { |
| 420 | |
| 421 | mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId()); |
| 422 | |
| 423 | } else { |
| 424 | // We join two single calls to create a conf |
| 425 | mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(), |
| 426 | call_target.getParticipants().get(0).getCallId()); |
| 427 | } |
| 428 | |
| 429 | } catch (RemoteException e) { |
| 430 | // TODO Auto-generated catch block |
| 431 | e.printStackTrace(); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | public class CallListAdapter extends BaseAdapter { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 436 | |
| 437 | private ArrayList<Conference> calls; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 438 | |
| 439 | private Context mContext; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 440 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 441 | public CallListAdapter(Context act) { |
| 442 | super(); |
| 443 | mContext = act; |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 444 | calls = new ArrayList<Conference>(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 445 | |
| 446 | } |
| 447 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 448 | public ArrayList<Conference> getConcurrentCalls(int position) { |
| 449 | ArrayList<Conference> toReturn = new ArrayList<Conference>(); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 450 | for (int i = 0; i < calls.size(); ++i) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 451 | if (position != i) |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 452 | toReturn.add(calls.get(i)); |
| 453 | } |
| 454 | return toReturn; |
| 455 | } |
| 456 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 457 | public void remove(Conference transfer) { |
Alexandre Lision | 6d75d06 | 2013-09-13 14:18:34 -0400 | [diff] [blame] | 458 | calls.remove(transfer); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 459 | } |
| 460 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 461 | public void update(ArrayList<Conference> list) { |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 462 | calls.clear(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 463 | calls.addAll(list); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 464 | notifyDataSetChanged(); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 465 | } |
| 466 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 467 | @Override |
| 468 | public int getCount() { |
| 469 | return calls.size(); |
| 470 | } |
| 471 | |
| 472 | @Override |
| 473 | public Conference getItem(int position) { |
| 474 | return calls.get(position); |
| 475 | } |
| 476 | |
| 477 | @Override |
| 478 | public long getItemId(int position) { |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | @Override |
| 483 | public View getView(int position, View convertView, ViewGroup parent) { |
| 484 | if (convertView == null) |
| 485 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null); |
| 486 | |
| 487 | Conference call = calls.get(position); |
| 488 | if (call.getParticipants().size() == 1) { |
| 489 | ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName()); |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 490 | |
| 491 | long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start()); |
| 492 | |
| 493 | ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration/3600, (duration%3600)/60, (duration%60))); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 494 | } else { |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 495 | String tmp = "Conference with " + call.getParticipants().size() + " participants"; |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 496 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 497 | ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp); |
| 498 | } |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 499 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 500 | ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState()); |
| 501 | convertView.setOnDragListener(dragListener); |
| 502 | |
| 503 | convertView.setTag(call); |
| 504 | return convertView; |
| 505 | } |
| 506 | |
| 507 | } |
| 508 | |
| 509 | public static class DropActionsChoice extends DialogFragment { |
| 510 | |
| 511 | ListAdapter mAdapter; |
| 512 | private Bundle args; |
| 513 | |
| 514 | /** |
| 515 | * Create a new instance of CallActionsDFragment |
| 516 | */ |
| 517 | public static DropActionsChoice newInstance() { |
| 518 | DropActionsChoice f = new DropActionsChoice(); |
| 519 | return f; |
| 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public void onCreate(Bundle savedInstanceState) { |
| 524 | super.onCreate(savedInstanceState); |
| 525 | |
| 526 | // Pick a style based on the num. |
| 527 | int style = DialogFragment.STYLE_NORMAL, theme = 0; |
| 528 | setStyle(style, theme); |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 533 | ListView rootView = new ListView(getActivity()); |
| 534 | |
| 535 | args = getArguments(); |
| 536 | mAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, getResources().getStringArray( |
| 537 | R.array.drop_actions)); |
| 538 | |
| 539 | // ListView list = (ListView) rootView.findViewById(R.id.concurrent_calls); |
| 540 | rootView.setAdapter(mAdapter); |
| 541 | rootView.setOnItemClickListener(new OnItemClickListener() { |
| 542 | |
| 543 | @Override |
| 544 | public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) { |
| 545 | Intent in = new Intent(); |
| 546 | |
| 547 | in.putExtra("transfer", args.getParcelable("call_initial")); |
| 548 | in.putExtra("target", args.getParcelable("call_targeted")); |
| 549 | |
| 550 | switch (pos) { |
| 551 | case 0: // Transfer |
| 552 | getTargetFragment().onActivityResult(REQUEST_TRANSFER, 0, in); |
| 553 | break; |
| 554 | case 1: // Conference |
| 555 | getTargetFragment().onActivityResult(REQUEST_CONF, 0, in); |
| 556 | break; |
| 557 | } |
| 558 | dismiss(); |
| 559 | |
| 560 | } |
| 561 | }); |
| 562 | |
| 563 | final AlertDialog a = new AlertDialog.Builder(getActivity()).setView(rootView).setTitle("Choose Action") |
| 564 | .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { |
| 565 | public void onClick(DialogInterface dialog, int whichButton) { |
| 566 | dismiss(); |
| 567 | } |
| 568 | }).create(); |
| 569 | |
| 570 | return a; |
| 571 | } |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 572 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 573 | |
| 574 | } |