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