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 | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 38 | import android.content.IntentFilter; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 39 | import org.sflphone.R; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 40 | import org.sflphone.interfaces.CallInterface; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 41 | import org.sflphone.model.CallTimer; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 42 | import org.sflphone.model.Conference; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 43 | import org.sflphone.receivers.CallReceiver; |
| 44 | import org.sflphone.service.CallManagerCallBack; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 45 | import org.sflphone.service.ISipService; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 46 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 47 | import android.app.Activity; |
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; |
| 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; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 54 | import android.os.Handler; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 55 | import android.os.RemoteException; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 56 | import android.os.SystemClock; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 57 | import android.os.Vibrator; |
Alexandre Lision | b4e6061 | 2014-01-14 17:47:23 -0500 | [diff] [blame] | 58 | import android.app.Fragment; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 59 | import android.util.Log; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 60 | import android.view.DragEvent; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 61 | import android.view.LayoutInflater; |
| 62 | import android.view.View; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 63 | import android.view.View.DragShadowBuilder; |
| 64 | import android.view.View.OnDragListener; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 65 | import android.view.ViewGroup; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 66 | import android.widget.AdapterView; |
| 67 | import android.widget.AdapterView.OnItemClickListener; |
| 68 | import android.widget.AdapterView.OnItemLongClickListener; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 69 | import android.widget.BaseAdapter; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 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 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 74 | public class CallListFragment extends Fragment implements CallInterface{ |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 75 | private static final String TAG = CallListFragment.class.getSimpleName(); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 76 | |
| 77 | private Callbacks mCallbacks = sDummyCallbacks; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 78 | private TextView nb_calls, nb_confs; |
| 79 | CallListAdapter confs_adapter, calls_adapter; |
| 80 | CallTimer timer; |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 81 | CallReceiver callReceiver; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 82 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 83 | public static final int REQUEST_TRANSFER = 10; |
| 84 | public static final int REQUEST_CONF = 20; |
| 85 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 86 | /** |
| 87 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 88 | */ |
| 89 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 90 | |
| 91 | @Override |
| 92 | public ISipService getService() { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 93 | Log.i(TAG, "I'm a dummy"); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 94 | return null; |
| 95 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 96 | |
| 97 | @Override |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 98 | public void selectedCall(Conference c) { |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 99 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 100 | }; |
| 101 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 102 | @Override |
| 103 | public void incomingCall(Intent call) { |
| 104 | |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public void callStateChanged(Intent callState) { |
| 109 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 110 | String cID = b.getString("CallID"); |
| 111 | String state = b.getString("State"); |
| 112 | Log.i(TAG, "callStateChanged" + cID + " " + state); |
| 113 | try { |
| 114 | updateLists(); |
| 115 | } catch (RemoteException e) { |
| 116 | e.printStackTrace(); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public void incomingText(Intent msg) { |
| 122 | Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); |
| 123 | b.getString("CallID"); |
| 124 | String from = b.getString("From"); |
| 125 | String mess = b.getString("Msg"); |
| 126 | Toast.makeText(getActivity(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show(); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void confCreated(Intent intent) { |
| 131 | try { |
| 132 | updateLists(); |
| 133 | } catch (RemoteException e) { |
| 134 | e.printStackTrace(); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void confRemoved(Intent intent) { |
| 140 | |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public void confChanged(Intent intent) { |
| 145 | |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void recordingChanged(Intent intent) { |
| 150 | |
| 151 | } |
| 152 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 153 | /** |
| 154 | * The Activity calling this fragment has to implement this interface |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 155 | */ |
| 156 | public interface Callbacks { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 157 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 158 | public ISipService getService(); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 159 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 160 | public void selectedCall(Conference c); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 161 | |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public void onAttach(Activity activity) { |
| 166 | super.onAttach(activity); |
| 167 | |
| 168 | if (!(activity instanceof Callbacks)) { |
| 169 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 170 | } |
| 171 | |
| 172 | mCallbacks = (Callbacks) activity; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 173 | |
| 174 | } |
| 175 | |
| 176 | private Runnable mUpdateTimeTask = new Runnable() { |
| 177 | public void run() { |
| 178 | final long start = SystemClock.uptimeMillis(); |
| 179 | long millis = SystemClock.uptimeMillis() - start; |
| 180 | int seconds = (int) (millis / 1000); |
| 181 | int minutes = seconds / 60; |
| 182 | seconds = seconds % 60; |
| 183 | |
| 184 | calls_adapter.notifyDataSetChanged(); |
| 185 | confs_adapter.notifyDataSetChanged(); |
| 186 | mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000)); |
| 187 | } |
| 188 | }; |
| 189 | |
| 190 | private Handler mHandler = new Handler(); |
| 191 | |
| 192 | @Override |
| 193 | public void onResume() { |
| 194 | super.onResume(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 195 | IntentFilter intentFilter = new IntentFilter(); |
| 196 | intentFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 197 | intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
| 198 | intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); |
| 199 | getActivity().registerReceiver(callReceiver, intentFilter); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 200 | if (mCallbacks.getService() != null) { |
| 201 | try { |
| 202 | updateLists(); |
| 203 | if (!calls_adapter.isEmpty() || !confs_adapter.isEmpty()) { |
| 204 | mHandler.postDelayed(mUpdateTimeTask, 0); |
| 205 | } |
| 206 | |
| 207 | } catch (RemoteException e) { |
| 208 | Log.e(TAG, e.toString()); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | } |
| 213 | |
| 214 | @SuppressWarnings("unchecked") |
| 215 | // No proper solution with HashMap runtime cast |
| 216 | public void updateLists() throws RemoteException { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 217 | HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList(); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 218 | Log.i(TAG, "There are " + confs.size()); |
| 219 | sortConferences(confs); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 222 | private void sortConferences(HashMap<String, Conference> conferences) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 223 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 224 | ArrayList<Conference> multiConfs = new ArrayList<Conference>(); |
| 225 | ArrayList<Conference> oneToOneConfs = new ArrayList<Conference>(); |
| 226 | for (Conference conf : conferences.values()) { |
| 227 | if (conf.hasMultipleParticipants()) |
| 228 | multiConfs.add(conf); |
| 229 | else |
| 230 | oneToOneConfs.add(conf); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 231 | } |
| 232 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 233 | nb_confs.setText("" + multiConfs.size()); |
| 234 | nb_calls.setText("" + oneToOneConfs.size()); |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame^] | 235 | confs_adapter.updateDataset(multiConfs); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 236 | calls_adapter.updateDataset(oneToOneConfs); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void onDetach() { |
| 241 | super.onDetach(); |
| 242 | mCallbacks = sDummyCallbacks; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 243 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 246 | @Override |
| 247 | public void onCreate(Bundle savedInstanceState) { |
| 248 | super.onCreate(savedInstanceState); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 249 | callReceiver = new CallReceiver(this); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | @Override |
| 253 | public void onPause() { |
| 254 | super.onPause(); |
| 255 | mHandler.removeCallbacks(mUpdateTimeTask); |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 256 | getActivity().unregisterReceiver(callReceiver); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public void onActivityCreated(Bundle savedInstanceState) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 261 | super.onActivityCreated(savedInstanceState); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 262 | } |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 263 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 264 | @Override |
| 265 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 266 | Log.i(TAG, "onCreateView"); |
| 267 | View inflatedView = inflater.inflate(R.layout.frag_call_list, container, false); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 268 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 269 | nb_calls = (TextView) inflatedView.findViewById(R.id.calls_counter); |
| 270 | nb_confs = (TextView) inflatedView.findViewById(R.id.confs_counter); |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 271 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 272 | confs_adapter = new CallListAdapter(getActivity()); |
| 273 | ((ListView) inflatedView.findViewById(R.id.confs_list)).setAdapter(confs_adapter); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 274 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 275 | calls_adapter = new CallListAdapter(getActivity()); |
| 276 | ((ListView) inflatedView.findViewById(R.id.calls_list)).setAdapter(calls_adapter); |
| 277 | ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemClickListener(callClickListener); |
| 278 | ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemClickListener(callClickListener); |
| 279 | |
| 280 | ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemLongClickListener(mItemLongClickListener); |
| 281 | ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemLongClickListener(mItemLongClickListener); |
| 282 | |
| 283 | return inflatedView; |
| 284 | } |
| 285 | |
| 286 | OnItemClickListener callClickListener = new OnItemClickListener() { |
| 287 | |
| 288 | @Override |
| 289 | public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) { |
| 290 | mCallbacks.selectedCall((Conference) v.getTag()); |
| 291 | } |
| 292 | }; |
| 293 | |
| 294 | private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() { |
| 295 | |
| 296 | @Override |
| 297 | public boolean onItemLongClick(AdapterView<?> adptv, View view, int pos, long arg3) { |
| 298 | final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE); |
| 299 | vibe.vibrate(80); |
| 300 | Intent i = new Intent(); |
| 301 | Bundle b = new Bundle(); |
| 302 | b.putParcelable("conference", (Conference) adptv.getAdapter().getItem(pos)); |
| 303 | i.putExtra("bconference", b); |
| 304 | |
| 305 | DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view); |
| 306 | ClipData data = ClipData.newIntent("conference", i); |
| 307 | view.startDrag(data, shadowBuilder, view, 0); |
| 308 | return false; |
| 309 | } |
| 310 | |
| 311 | }; |
| 312 | |
| 313 | public class CallListAdapter extends BaseAdapter implements Observer { |
| 314 | |
| 315 | private ArrayList<Conference> calls; |
| 316 | |
| 317 | private Context mContext; |
| 318 | |
| 319 | public CallListAdapter(Context act) { |
| 320 | super(); |
| 321 | mContext = act; |
| 322 | calls = new ArrayList<Conference>(); |
| 323 | |
| 324 | } |
| 325 | |
| 326 | public ArrayList<Conference> getDataset() { |
| 327 | return calls; |
| 328 | } |
| 329 | |
| 330 | public void remove(Conference transfer) { |
| 331 | |
| 332 | } |
| 333 | |
| 334 | public void updateDataset(ArrayList<Conference> list) { |
| 335 | calls.clear(); |
| 336 | calls.addAll(list); |
| 337 | notifyDataSetChanged(); |
| 338 | } |
| 339 | |
| 340 | @Override |
| 341 | public int getCount() { |
| 342 | return calls.size(); |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public Conference getItem(int position) { |
| 347 | return calls.get(position); |
| 348 | } |
| 349 | |
| 350 | @Override |
| 351 | public long getItemId(int position) { |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public View getView(int position, View convertView, ViewGroup parent) { |
| 357 | if (convertView == null) |
| 358 | convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null); |
| 359 | |
| 360 | Conference call = calls.get(position); |
| 361 | if (call.getParticipants().size() == 1) { |
| 362 | ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName()); |
| 363 | |
Alexandre Lision | 945e461 | 2014-01-15 17:40:31 -0500 | [diff] [blame^] | 364 | long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestampStart_()); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 365 | |
| 366 | ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration / 3600, (duration % 3600) / 60, |
| 367 | (duration % 60))); |
| 368 | } else { |
| 369 | // String tmp = "Conference with " + call.getParticipants().size() + " participants"; |
| 370 | ((TextView) convertView.findViewById(R.id.call_title)).setText(getString(R.string.home_conf_item, call.getParticipants().size())); |
| 371 | } |
| 372 | // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size()); |
| 373 | ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState()); |
| 374 | |
| 375 | convertView.setOnDragListener(dragListener); |
| 376 | convertView.setTag(call); |
| 377 | |
| 378 | return convertView; |
| 379 | } |
| 380 | |
| 381 | @Override |
| 382 | public void update(Observable observable, Object data) { |
| 383 | Log.i(TAG, "Updating views..."); |
| 384 | notifyDataSetChanged(); |
| 385 | } |
| 386 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 387 | } |
| 388 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 389 | OnDragListener dragListener = new OnDragListener() { |
| 390 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 391 | @SuppressWarnings("deprecation") |
| 392 | // deprecated in API 16.... |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 393 | @Override |
| 394 | public boolean onDrag(View v, DragEvent event) { |
| 395 | switch (event.getAction()) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 396 | case DragEvent.ACTION_DRAG_STARTED: |
| 397 | // Do nothing |
| 398 | // Log.w(TAG, "ACTION_DRAG_STARTED"); |
| 399 | break; |
| 400 | case DragEvent.ACTION_DRAG_ENTERED: |
| 401 | // Log.w(TAG, "ACTION_DRAG_ENTERED"); |
| 402 | v.setBackgroundColor(Color.GREEN); |
| 403 | break; |
| 404 | case DragEvent.ACTION_DRAG_EXITED: |
| 405 | // Log.w(TAG, "ACTION_DRAG_EXITED"); |
| 406 | v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector)); |
| 407 | break; |
| 408 | case DragEvent.ACTION_DROP: |
| 409 | // Log.w(TAG, "ACTION_DROP"); |
| 410 | View view = (View) event.getLocalState(); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 411 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 412 | Item i = event.getClipData().getItemAt(0); |
| 413 | Intent intent = i.getIntent(); |
| 414 | intent.setExtrasClassLoader(Conference.class.getClassLoader()); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 415 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 416 | Conference initial = (Conference) view.getTag(); |
| 417 | Conference target = (Conference) v.getTag(); |
alision | f2ae436 | 2013-07-05 16:16:12 -0400 | [diff] [blame] | 418 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 419 | if (initial == target) { |
| 420 | return true; |
| 421 | } |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 422 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 423 | DropActionsChoice dialog = DropActionsChoice.newInstance(); |
| 424 | Bundle b = new Bundle(); |
| 425 | b.putParcelable("call_initial", initial); |
| 426 | b.putParcelable("call_targeted", target); |
| 427 | dialog.setArguments(b); |
| 428 | dialog.setTargetFragment(CallListFragment.this, 0); |
| 429 | dialog.show(getChildFragmentManager(), "dialog"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 430 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 431 | // view.setBackgroundColor(Color.WHITE); |
| 432 | // v.setBackgroundColor(Color.BLACK); |
| 433 | break; |
| 434 | case DragEvent.ACTION_DRAG_ENDED: |
| 435 | // Log.w(TAG, "ACTION_DRAG_ENDED"); |
| 436 | View view1 = (View) event.getLocalState(); |
| 437 | view1.setVisibility(View.VISIBLE); |
| 438 | v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector)); |
| 439 | default: |
| 440 | break; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 441 | } |
| 442 | return true; |
| 443 | } |
| 444 | |
| 445 | }; |
| 446 | |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 447 | @Override |
| 448 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 449 | super.onActivityResult(requestCode, resultCode, data); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 450 | Conference transfer = null; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 451 | if (requestCode == REQUEST_TRANSFER) { |
| 452 | switch (resultCode) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 453 | case 0: |
| 454 | Conference c = data.getParcelableExtra("target"); |
| 455 | transfer = data.getParcelableExtra("transfer"); |
| 456 | try { |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 457 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 458 | mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId()); |
| 459 | calls_adapter.remove(transfer); |
| 460 | calls_adapter.remove(c); |
| 461 | calls_adapter.notifyDataSetChanged(); |
| 462 | } catch (RemoteException e) { |
| 463 | // TODO Auto-generated catch block |
| 464 | e.printStackTrace(); |
| 465 | } |
| 466 | Toast.makeText(getActivity(), getString(R.string.home_transfer_complet), Toast.LENGTH_LONG).show(); |
| 467 | break; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 468 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 469 | case 1: |
| 470 | String to = data.getStringExtra("to_number"); |
| 471 | transfer = data.getParcelableExtra("transfer"); |
| 472 | try { |
| 473 | Toast.makeText(getActivity(), getString(R.string.home_transfering, transfer.getParticipants().get(0).getContact().getmDisplayName(), to), |
| 474 | Toast.LENGTH_SHORT).show(); |
| 475 | mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to); |
| 476 | mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId()); |
| 477 | } catch (RemoteException e) { |
| 478 | // TODO Auto-generated catch block |
| 479 | e.printStackTrace(); |
| 480 | } |
| 481 | break; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 482 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 483 | default: |
| 484 | break; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 485 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 486 | } else if (requestCode == REQUEST_CONF) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 487 | switch (resultCode) { |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 488 | case 0: |
| 489 | Conference call_to_add = data.getParcelableExtra("transfer"); |
| 490 | Conference call_target = data.getParcelableExtra("target"); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 491 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 492 | bindCalls(call_to_add, call_target); |
| 493 | break; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 494 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 495 | default: |
| 496 | break; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 497 | } |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 501 | private void bindCalls(Conference call_to_add, Conference call_target) { |
| 502 | try { |
| 503 | |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 504 | Log.i(TAG, "joining calls:"+ call_to_add.getId() + " and " + call_target.getId()); |
| 505 | |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 506 | if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) { |
| 507 | |
| 508 | mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId()); |
| 509 | |
| 510 | } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) { |
| 511 | |
| 512 | // We join two conferences |
| 513 | mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId()); |
| 514 | |
| 515 | } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) { |
| 516 | |
| 517 | mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId()); |
| 518 | |
| 519 | } else { |
| 520 | // We join two single calls to create a conf |
| 521 | mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(), |
| 522 | call_target.getParticipants().get(0).getCallId()); |
| 523 | } |
| 524 | |
| 525 | } catch (RemoteException e) { |
| 526 | // TODO Auto-generated catch block |
| 527 | e.printStackTrace(); |
| 528 | } |
| 529 | } |
| 530 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 531 | } |