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