alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 31 | package org.sflphone.fragments; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 32 | |
| 33 | import java.util.ArrayList; |
| 34 | import java.util.HashMap; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 35 | import java.util.Observable; |
| 36 | import java.util.Observer; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 37 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 38 | import org.sflphone.R; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 39 | import org.sflphone.model.CallTimer; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 40 | import org.sflphone.model.Conference; |
| 41 | import org.sflphone.model.SipCall; |
| 42 | import org.sflphone.service.ISipService; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 43 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 44 | import android.app.Activity; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 45 | import android.content.ClipData; |
| 46 | import android.content.ClipData.Item; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 47 | import android.content.Context; |
| 48 | import android.content.Intent; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 49 | import android.graphics.Color; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 50 | import android.os.Bundle; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 51 | import android.os.Handler; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 52 | import android.os.RemoteException; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 53 | import android.os.SystemClock; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 54 | import android.os.Vibrator; |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 55 | import android.support.v4.app.Fragment; |
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; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 66 | import android.widget.BaseAdapter; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 67 | import android.widget.ListView; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 68 | import android.widget.TextView; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 69 | import android.widget.Toast; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 70 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 71 | public class CallListFragment extends Fragment { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 72 | private static final String TAG = CallListFragment.class.getSimpleName(); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 73 | |
| 74 | private Callbacks mCallbacks = sDummyCallbacks; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 75 | private TextView nb_calls, nb_confs; |
| 76 | CallListAdapter confs_adapter, calls_adapter; |
| 77 | CallTimer timer; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 78 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 79 | public static final int REQUEST_TRANSFER = 10; |
| 80 | public static final int REQUEST_CONF = 20; |
| 81 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 82 | /** |
| 83 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 84 | */ |
| 85 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 86 | |
| 87 | @Override |
| 88 | public ISipService getService() { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 89 | Log.i(TAG, "I'm a dummy"); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 90 | return null; |
| 91 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 92 | |
| 93 | @Override |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 94 | public void selectedCall(Conference c) { |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 95 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | /** |
| 99 | * The Activity calling this fragment has to implement this interface |
| 100 | * |
| 101 | */ |
| 102 | public interface Callbacks { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 103 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 104 | public ISipService getService(); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 105 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 106 | public void selectedCall(Conference c); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 107 | |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public void onAttach(Activity activity) { |
| 112 | super.onAttach(activity); |
| 113 | |
| 114 | if (!(activity instanceof Callbacks)) { |
| 115 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 116 | } |
| 117 | |
| 118 | mCallbacks = (Callbacks) activity; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 119 | |
| 120 | } |
| 121 | |
| 122 | private Runnable mUpdateTimeTask = new Runnable() { |
| 123 | public void run() { |
| 124 | final long start = SystemClock.uptimeMillis(); |
| 125 | long millis = SystemClock.uptimeMillis() - start; |
| 126 | int seconds = (int) (millis / 1000); |
| 127 | int minutes = seconds / 60; |
| 128 | seconds = seconds % 60; |
| 129 | |
| 130 | calls_adapter.notifyDataSetChanged(); |
| 131 | confs_adapter.notifyDataSetChanged(); |
| 132 | mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000)); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | private Handler mHandler = new Handler(); |
| 137 | |
| 138 | @Override |
| 139 | public void onResume() { |
| 140 | super.onResume(); |
| 141 | if (mCallbacks.getService() != null) { |
| 142 | try { |
| 143 | updateLists(); |
| 144 | if (!calls_adapter.isEmpty() || !confs_adapter.isEmpty()) { |
| 145 | mHandler.postDelayed(mUpdateTimeTask, 0); |
| 146 | } |
| 147 | |
| 148 | } catch (RemoteException e) { |
| 149 | Log.e(TAG, e.toString()); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | } |
| 154 | |
| 155 | @SuppressWarnings("unchecked") |
| 156 | // No proper solution with HashMap runtime cast |
| 157 | public void updateLists() throws RemoteException { |
| 158 | HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList(); |
| 159 | HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList(); |
| 160 | |
| 161 | updateCallList(calls); |
| 162 | updateConferenceList(confs); |
| 163 | } |
| 164 | |
| 165 | private void updateConferenceList(HashMap<String, Conference> confs) { |
| 166 | nb_confs.setText("" + confs.size()); |
| 167 | confs_adapter.updateDataset(new ArrayList<Conference>(confs.values())); |
| 168 | } |
| 169 | |
| 170 | private void updateCallList(HashMap<String, SipCall> calls) { |
| 171 | nb_calls.setText("" + calls.size()); |
| 172 | ArrayList<Conference> conferences = new ArrayList<Conference>(); |
| 173 | for (SipCall call : calls.values()) { |
| 174 | Conference confOne = new Conference("-1"); |
| 175 | confOne.getParticipants().add(call); |
| 176 | conferences.add(confOne); |
| 177 | } |
| 178 | |
| 179 | calls_adapter.updateDataset(conferences); |
| 180 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public void onDetach() { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 185 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 186 | super.onDetach(); |
| 187 | mCallbacks = sDummyCallbacks; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 188 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 189 | } |
| 190 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 191 | @Override |
| 192 | public void onCreate(Bundle savedInstanceState) { |
| 193 | super.onCreate(savedInstanceState); |
| 194 | } |
| 195 | |
| 196 | @Override |
| 197 | public void onPause() { |
| 198 | super.onPause(); |
| 199 | mHandler.removeCallbacks(mUpdateTimeTask); |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | public void onActivityCreated(Bundle savedInstanceState) { |
| 204 | |
| 205 | super.onActivityCreated(savedInstanceState); |
| 206 | |
| 207 | // Give some text to display if there is no data. In a real |
| 208 | // application this would come from a resource. |
| 209 | // setEmptyText("No phone numbers"); |
| 210 | |
| 211 | // We have a menu item to show in action bar. |
| 212 | setHasOptionsMenu(true); |
| 213 | |
| 214 | } |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 215 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 216 | @Override |
| 217 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 218 | Log.i(TAG, "onCreateView"); |
| 219 | View inflatedView = inflater.inflate(R.layout.frag_call_list, container, false); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 220 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 221 | nb_calls = (TextView) inflatedView.findViewById(R.id.calls_counter); |
| 222 | nb_confs = (TextView) inflatedView.findViewById(R.id.confs_counter); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 223 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 224 | confs_adapter = new CallListAdapter(getActivity()); |
| 225 | ((ListView) inflatedView.findViewById(R.id.confs_list)).setAdapter(confs_adapter); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 226 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 227 | calls_adapter = new CallListAdapter(getActivity()); |
| 228 | ((ListView) inflatedView.findViewById(R.id.calls_list)).setAdapter(calls_adapter); |
| 229 | ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemClickListener(callClickListener); |
| 230 | ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemClickListener(callClickListener); |
| 231 | |
| 232 | ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemLongClickListener(mItemLongClickListener); |
| 233 | ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemLongClickListener(mItemLongClickListener); |
| 234 | |
| 235 | return inflatedView; |
| 236 | } |
| 237 | |
| 238 | OnItemClickListener callClickListener = new OnItemClickListener() { |
| 239 | |
| 240 | @Override |
| 241 | public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) { |
| 242 | mCallbacks.selectedCall((Conference) v.getTag()); |
| 243 | } |
| 244 | }; |
| 245 | |
| 246 | private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() { |
| 247 | |
| 248 | @Override |
| 249 | public boolean onItemLongClick(AdapterView<?> adptv, View view, int pos, long arg3) { |
| 250 | final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE); |
| 251 | vibe.vibrate(80); |
| 252 | Intent i = new Intent(); |
| 253 | Bundle b = new Bundle(); |
| 254 | b.putParcelable("conference", (Conference) adptv.getAdapter().getItem(pos)); |
| 255 | i.putExtra("bconference", b); |
| 256 | |
| 257 | DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view); |
| 258 | ClipData data = ClipData.newIntent("conference", i); |
| 259 | view.startDrag(data, shadowBuilder, view, 0); |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | }; |
| 264 | |
| 265 | public class CallListAdapter extends BaseAdapter implements Observer { |
| 266 | |
| 267 | private ArrayList<Conference> calls; |
| 268 | |
| 269 | private Context mContext; |
| 270 | |
| 271 | public CallListAdapter(Context act) { |
| 272 | super(); |
| 273 | mContext = act; |
| 274 | calls = new ArrayList<Conference>(); |
| 275 | |
| 276 | } |
| 277 | |
| 278 | public ArrayList<Conference> getDataset() { |
| 279 | return calls; |
| 280 | } |
| 281 | |
| 282 | public void remove(Conference transfer) { |
| 283 | |
| 284 | } |
| 285 | |
| 286 | public void updateDataset(ArrayList<Conference> list) { |
| 287 | calls.clear(); |
| 288 | calls.addAll(list); |
| 289 | notifyDataSetChanged(); |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public int getCount() { |
| 294 | return calls.size(); |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public Conference getItem(int position) { |
| 299 | return calls.get(position); |
| 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public long getItemId(int position) { |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public View getView(int position, View convertView, ViewGroup parent) { |
| 309 | if (convertView == null) |
| 310 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null); |
| 311 | |
| 312 | Conference call = calls.get(position); |
| 313 | if (call.getParticipants().size() == 1) { |
| 314 | ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName()); |
| 315 | |
| 316 | long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start()); |
| 317 | |
| 318 | ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration / 3600, (duration % 3600) / 60, |
| 319 | (duration % 60))); |
| 320 | } else { |
| 321 | // String tmp = "Conference with " + call.getParticipants().size() + " participants"; |
| 322 | ((TextView) convertView.findViewById(R.id.call_title)).setText(getString(R.string.home_conf_item, call.getParticipants().size())); |
| 323 | } |
| 324 | // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size()); |
| 325 | ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState()); |
| 326 | |
| 327 | convertView.setOnDragListener(dragListener); |
| 328 | convertView.setTag(call); |
| 329 | |
| 330 | return convertView; |
| 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public void update(Observable observable, Object data) { |
| 335 | Log.i(TAG, "Updating views..."); |
| 336 | notifyDataSetChanged(); |
| 337 | } |
| 338 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 339 | } |
| 340 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 341 | OnDragListener dragListener = new OnDragListener() { |
| 342 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 343 | @SuppressWarnings("deprecation") |
| 344 | // deprecated in API 16.... |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 345 | @Override |
| 346 | public boolean onDrag(View v, DragEvent event) { |
| 347 | switch (event.getAction()) { |
| 348 | case DragEvent.ACTION_DRAG_STARTED: |
| 349 | // Do nothing |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 350 | // Log.w(TAG, "ACTION_DRAG_STARTED"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 351 | break; |
| 352 | case DragEvent.ACTION_DRAG_ENTERED: |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 353 | // Log.w(TAG, "ACTION_DRAG_ENTERED"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 354 | v.setBackgroundColor(Color.GREEN); |
| 355 | break; |
| 356 | case DragEvent.ACTION_DRAG_EXITED: |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 357 | // Log.w(TAG, "ACTION_DRAG_EXITED"); |
| 358 | v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector)); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 359 | break; |
| 360 | case DragEvent.ACTION_DROP: |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 361 | // Log.w(TAG, "ACTION_DROP"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 362 | View view = (View) event.getLocalState(); |
| 363 | |
| 364 | Item i = event.getClipData().getItemAt(0); |
| 365 | Intent intent = i.getIntent(); |
| 366 | intent.setExtrasClassLoader(Conference.class.getClassLoader()); |
| 367 | |
| 368 | Conference initial = (Conference) view.getTag(); |
| 369 | Conference target = (Conference) v.getTag(); |
alision | f2ae436 | 2013-07-05 16:16:12 -0400 | [diff] [blame] | 370 | |
| 371 | if (initial == target) { |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 372 | return true; |
| 373 | } |
| 374 | |
| 375 | DropActionsChoice dialog = DropActionsChoice.newInstance(); |
| 376 | Bundle b = new Bundle(); |
| 377 | b.putParcelable("call_initial", initial); |
| 378 | b.putParcelable("call_targeted", target); |
| 379 | dialog.setArguments(b); |
| 380 | dialog.setTargetFragment(CallListFragment.this, 0); |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 381 | dialog.show(getChildFragmentManager(), "dialog"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 382 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 383 | // view.setBackgroundColor(Color.WHITE); |
| 384 | // v.setBackgroundColor(Color.BLACK); |
| 385 | break; |
| 386 | case DragEvent.ACTION_DRAG_ENDED: |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 387 | // Log.w(TAG, "ACTION_DRAG_ENDED"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 388 | View view1 = (View) event.getLocalState(); |
| 389 | view1.setVisibility(View.VISIBLE); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 390 | v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector)); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 391 | default: |
| 392 | break; |
| 393 | } |
| 394 | return true; |
| 395 | } |
| 396 | |
| 397 | }; |
| 398 | |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 399 | @Override |
| 400 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 401 | super.onActivityResult(requestCode, resultCode, data); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 402 | Conference transfer = null; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 403 | if (requestCode == REQUEST_TRANSFER) { |
| 404 | switch (resultCode) { |
| 405 | case 0: |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 406 | Conference c = data.getParcelableExtra("target"); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 407 | transfer = data.getParcelableExtra("transfer"); |
| 408 | try { |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 409 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 410 | mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId()); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 411 | calls_adapter.remove(transfer); |
| 412 | calls_adapter.remove(c); |
| 413 | calls_adapter.notifyDataSetChanged(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 414 | } catch (RemoteException e) { |
| 415 | // TODO Auto-generated catch block |
| 416 | e.printStackTrace(); |
| 417 | } |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 418 | Toast.makeText(getActivity(), getString(R.string.home_transfer_complet), Toast.LENGTH_LONG).show(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 419 | break; |
| 420 | |
| 421 | case 1: |
| 422 | String to = data.getStringExtra("to_number"); |
| 423 | transfer = data.getParcelableExtra("transfer"); |
| 424 | try { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 425 | Toast.makeText(getActivity(), getString(R.string.home_transfering,transfer.getParticipants().get(0).getContact().getmDisplayName(),to), |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 426 | Toast.LENGTH_SHORT).show(); |
| 427 | mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to); |
| 428 | mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId()); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 429 | } catch (RemoteException e) { |
| 430 | // TODO Auto-generated catch block |
| 431 | e.printStackTrace(); |
| 432 | } |
| 433 | break; |
| 434 | |
| 435 | default: |
| 436 | break; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 437 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 438 | } else if (requestCode == REQUEST_CONF) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 439 | switch (resultCode) { |
| 440 | case 0: |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 441 | Conference call_to_add = data.getParcelableExtra("transfer"); |
| 442 | Conference call_target = data.getParcelableExtra("target"); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 443 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 444 | bindCalls(call_to_add, call_target); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 445 | break; |
| 446 | |
| 447 | default: |
| 448 | break; |
| 449 | } |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 453 | private void bindCalls(Conference call_to_add, Conference call_target) { |
| 454 | try { |
| 455 | |
| 456 | if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) { |
| 457 | |
| 458 | mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId()); |
| 459 | |
| 460 | } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) { |
| 461 | |
| 462 | // We join two conferences |
| 463 | mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId()); |
| 464 | |
| 465 | } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) { |
| 466 | |
| 467 | mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId()); |
| 468 | |
| 469 | } else { |
| 470 | // We join two single calls to create a conf |
| 471 | mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(), |
| 472 | call_target.getParticipants().get(0).getCallId()); |
| 473 | } |
| 474 | |
| 475 | } catch (RemoteException e) { |
| 476 | // TODO Auto-generated catch block |
| 477 | e.printStackTrace(); |
| 478 | } |
| 479 | } |
| 480 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 481 | } |