alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Adrien Beraud <adrien.beraud@gmail.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 | package com.savoirfairelinux.sflphone.fragments; |
| 32 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 33 | import java.util.ArrayList; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 34 | import java.util.Random; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 35 | |
| 36 | import android.app.Activity; |
| 37 | import android.app.AlertDialog; |
| 38 | import android.app.ListFragment; |
| 39 | import android.app.LoaderManager; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.content.CursorLoader; |
| 42 | import android.content.DialogInterface; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 43 | import android.content.Intent; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 44 | import android.content.Loader; |
| 45 | import android.database.Cursor; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 46 | import android.net.Uri; |
| 47 | import android.os.Bundle; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 48 | import android.os.RemoteException; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 49 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 50 | import android.provider.ContactsContract.CommonDataKinds.SipAddress; |
| 51 | import android.provider.ContactsContract.Contacts; |
| 52 | import android.util.Log; |
| 53 | import android.view.LayoutInflater; |
| 54 | import android.view.View; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 55 | import android.view.View.OnClickListener; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 56 | import android.view.ViewGroup; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 57 | import android.widget.AdapterView; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 58 | import android.widget.AdapterView.OnItemClickListener; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 59 | import android.widget.AdapterView.OnItemLongClickListener; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 60 | import android.widget.Button; |
| 61 | import android.widget.EditText; |
| 62 | import android.widget.ImageButton; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 63 | import android.widget.ListView; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 64 | import android.widget.Toast; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 65 | |
| 66 | import com.savoirfairelinux.sflphone.R; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 67 | import com.savoirfairelinux.sflphone.account.AccountSelectionSpinner; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 68 | import com.savoirfairelinux.sflphone.adapters.CallElementAdapter; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 69 | import com.savoirfairelinux.sflphone.client.CallActivity; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 70 | import com.savoirfairelinux.sflphone.client.SFLPhoneHomeActivity; |
| 71 | import com.savoirfairelinux.sflphone.client.SFLphoneApplication; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 72 | import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 73 | import com.savoirfairelinux.sflphone.client.receiver.CallListReceiver; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 74 | import com.savoirfairelinux.sflphone.model.SipCall; |
| 75 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 76 | |
| 77 | /** |
| 78 | * Main list of Call Elements. We don't manage contacts ourself so they are |
| 79 | */ |
| 80 | public class CallElementListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> { |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 81 | private static final String TAG = CallElementListFragment.class.getSimpleName(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 82 | private CallElementAdapter mAdapter; |
| 83 | private String mCurFilter; |
| 84 | private SFLPhoneHomeActivity sflphoneHome; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 85 | private ISipService service; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 86 | ImageButton buttonCall; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 87 | Button attendedTransfer, conference; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 88 | EditText phoneField; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 89 | private AccountSelectionSpinner mAccountSelectionSpinner; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 90 | private AccountListReceiver mAccountList; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 91 | private boolean isReady = false; |
| 92 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 93 | static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID, Contacts.LOOKUP_KEY }; |
| 94 | static final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE }; |
| 95 | static final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE }; |
| 96 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 97 | private Callbacks mCallbacks = sDummyCallbacks; |
| 98 | /** |
| 99 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 100 | */ |
| 101 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 102 | @Override |
| 103 | public void onCallSelected(SipCall c) { |
| 104 | } |
| 105 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 106 | @Override |
| 107 | public ISipService getService() { |
| 108 | // TODO Auto-generated method stub |
| 109 | return null; |
| 110 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | /** |
| 114 | * The Activity calling this fragment has to implement this interface |
| 115 | * |
| 116 | */ |
| 117 | public interface Callbacks { |
| 118 | public void onCallSelected(SipCall c); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 119 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 120 | public ISipService getService(); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 121 | |
| 122 | } |
| 123 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 124 | @Override |
| 125 | public void onAttach(Activity activity) { |
| 126 | super.onAttach(activity); |
| 127 | sflphoneHome = (SFLPhoneHomeActivity) activity; |
| 128 | service = ((SFLphoneApplication) sflphoneHome.getApplication()).getSipService(); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 129 | if (!(activity instanceof Callbacks)) { |
| 130 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 131 | } |
| 132 | |
| 133 | mCallbacks = (Callbacks) activity; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 134 | Log.w(TAG, "onAttach() service=" + service + ", accountList=" + mAccountList); |
| 135 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 136 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 137 | @Override |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 138 | public void onDetach() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 139 | super.onDetach(); |
| 140 | mCallbacks = sDummyCallbacks; |
| 141 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 142 | |
| 143 | public String getSelectedAccount() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 144 | return mAccountSelectionSpinner.getAccount(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Runnable that fill information in a contact card asynchroniously. |
| 149 | */ |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 150 | /* |
| 151 | * public static class InfosLoader implements Runnable { private View view; private long cid; private ContentResolver cr; |
| 152 | * |
| 153 | * public InfosLoader(Context context, View element, long contact_id) { cid = contact_id; cr = context.getContentResolver(); view = element; } |
| 154 | * |
| 155 | * public static Bitmap loadContactPhoto(ContentResolver cr, long id) { Uri uri = |
| 156 | * ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); InputStream input = |
| 157 | * ContactsContract.Contacts.openContactPhotoInputStream(cr, uri); if (input == null) { return null; } return BitmapFactory.decodeStream(input); } |
| 158 | * |
| 159 | * @Override public void run() { final Bitmap photo_bmp = loadContactPhoto(cr, cid); |
| 160 | * |
| 161 | * Cursor phones = cr.query(CommonDataKinds.Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] |
| 162 | * { Long.toString(cid) }, null); |
| 163 | * |
| 164 | * final List<String> numbers = new ArrayList<String>(); while (phones.moveToNext()) { String number = |
| 165 | * phones.getString(phones.getColumnIndex(CommonDataKinds.Phone.NUMBER)); // int type = |
| 166 | * phones.getInt(phones.getColumnIndex(CommonDataKinds.Phone.TYPE)); numbers.add(number); } phones.close(); // TODO: same for SIP adresses. |
| 167 | * |
| 168 | * final Bitmap bmp = photo_bmp; view.post(new Runnable() { |
| 169 | * |
| 170 | * @Override public void run() { } }); } } |
| 171 | */ |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 172 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 173 | public CallElementListFragment() { |
| 174 | super(); |
| 175 | } |
| 176 | |
| 177 | public void setAccountList(AccountListReceiver accountList) { |
| 178 | mAccountList = accountList; |
| 179 | } |
| 180 | |
| 181 | public void addCall(SipCall c) { |
| 182 | Log.i(TAG, "Adding call " + c.mCallInfo.mDisplayName); |
| 183 | mAdapter.add(c); |
| 184 | } |
| 185 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 186 | // public void removeCall(SipCall c) { |
| 187 | // Log.i(TAG, "Removing call " + c.mCallInfo.mDisplayName); |
| 188 | // mAdapter.remove(c); |
| 189 | // } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 190 | |
| 191 | @Override |
| 192 | public void onActivityCreated(Bundle savedInstanceState) { |
| 193 | super.onActivityCreated(savedInstanceState); |
| 194 | |
| 195 | // Give some text to display if there is no data. In a real |
| 196 | // application this would come from a resource. |
| 197 | // setEmptyText("No phone numbers"); |
| 198 | |
| 199 | // We have a menu item to show in action bar. |
| 200 | setHasOptionsMenu(true); |
| 201 | |
| 202 | // Create an empty adapter we will use to display the loaded data. |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 203 | ArrayList<SipCall> calls = new ArrayList<SipCall>(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 204 | mAdapter = new CallElementAdapter(getActivity(), calls); |
| 205 | setListAdapter(mAdapter); |
| 206 | |
| 207 | // Start out with a progress indicator. |
| 208 | // setListShown(false); |
| 209 | |
| 210 | // Prepare the loader. Either re-connect with an existing one, |
| 211 | // or start a new one. |
| 212 | // getLoaderManager().initLoader(0, null, this) |
| 213 | |
| 214 | final Context context = getActivity(); |
| 215 | ListView lv = getListView(); |
| 216 | lv.setOnItemLongClickListener(new OnItemLongClickListener() { |
| 217 | @Override |
| 218 | public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) { |
| 219 | Log.i(TAG, "On Long Click"); |
| 220 | final CharSequence[] items = { "Hang up Call", "Send Message", "Add to Conference" }; |
| 221 | final SipCall call = (SipCall) mAdapter.getItem(pos); |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 222 | // // FIXME |
| 223 | // service = sflphoneApplication.getSipService(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 224 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 225 | builder.setTitle("Action to perform with " + call.mCallInfo.mDisplayName).setCancelable(true) |
| 226 | .setItems(items, new DialogInterface.OnClickListener() { |
| 227 | public void onClick(DialogInterface dialog, int item) { |
| 228 | Log.i(TAG, "Selected " + items[item]); |
| 229 | switch (item) { |
| 230 | case 0: |
| 231 | call.notifyServiceHangup(service); |
| 232 | break; |
| 233 | case 1: |
| 234 | call.sendTextMessage(); |
| 235 | // Need to hangup this call immediately since no way to do it after this action |
| 236 | call.notifyServiceHangup(service); |
| 237 | break; |
| 238 | case 2: |
| 239 | call.addToConference(); |
| 240 | // Need to hangup this call immediately since no way to do it after this action |
| 241 | call.notifyServiceHangup(service); |
| 242 | break; |
| 243 | default: |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | }); |
| 248 | AlertDialog alert = builder.create(); |
| 249 | alert.show(); |
| 250 | |
| 251 | return true; |
| 252 | } |
| 253 | }); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 254 | |
| 255 | lv.setOnItemClickListener(new OnItemClickListener() { |
| 256 | |
| 257 | @Override |
| 258 | public void onItemClick(AdapterView<?> arg0, View v, int pos, long arg3) { |
| 259 | mCallbacks.onCallSelected((SipCall) mAdapter.getItem(pos)); |
| 260 | |
| 261 | } |
| 262 | |
| 263 | }); |
| 264 | } |
| 265 | |
| 266 | public void launchCallActivity(SipCall call) { |
| 267 | Log.i(TAG, "Launch Call Activity"); |
| 268 | Bundle bundle = new Bundle(); |
| 269 | bundle.putParcelable("CallInfo", call.mCallInfo); |
| 270 | Intent intent = new Intent().setClass(getActivity(), CallActivity.class); |
| 271 | intent.putExtras(bundle); |
| 272 | getActivity().startActivity(intent); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 277 | Log.i(TAG, "onCreateView"); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 278 | View inflatedView = inflater.inflate(R.layout.frag_call_element, container, false); |
| 279 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 280 | mAccountSelectionSpinner = (AccountSelectionSpinner) inflatedView.findViewById(R.id.account_selection_button); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 281 | phoneField = (EditText) inflatedView.findViewById(R.id.phoneNumberTextEntry); |
| 282 | buttonCall = (ImageButton) inflatedView.findViewById(R.id.buttonCall); |
| 283 | |
| 284 | buttonCall.setOnClickListener(new OnClickListener() { |
| 285 | @Override |
| 286 | public void onClick(View v) { |
| 287 | processingNewCallAction(); |
| 288 | } |
| 289 | }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 290 | |
| 291 | attendedTransfer = (Button) inflatedView.findViewById(R.id.button_attended); |
| 292 | attendedTransfer.setOnClickListener(new OnClickListener() { |
| 293 | |
| 294 | @Override |
| 295 | public void onClick(View v) { |
| 296 | if (mAdapter.getCount() == 2) { |
| 297 | try { |
| 298 | service.attendedTransfer(mAdapter.getItem(0).getCallId(), mAdapter.getItem(1).getCallId()); |
| 299 | mAdapter.clear(); |
| 300 | } catch (RemoteException e) { |
| 301 | Log.e(TAG, e.toString()); |
| 302 | } |
| 303 | } else { |
| 304 | Toast.makeText(getActivity(), "You need two calls one on Hold the other current to bind them", Toast.LENGTH_LONG).show(); |
| 305 | } |
| 306 | |
| 307 | } |
| 308 | }); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 309 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 310 | conference = (Button) inflatedView.findViewById(R.id.button_conf); |
| 311 | conference.setOnClickListener(new OnClickListener() { |
| 312 | |
| 313 | @Override |
| 314 | public void onClick(View v) { |
| 315 | if (mAdapter.getCount() == 2) { |
| 316 | try { |
| 317 | service.joinParticipant(mAdapter.getItem(0).getCallId(), mAdapter.getItem(1).getCallId()); |
| 318 | } catch (RemoteException e) { |
| 319 | Log.e(TAG, e.toString()); |
| 320 | } |
| 321 | } else { |
| 322 | Toast.makeText(getActivity(), "You need two calls one on Hold the other current to create a conference", Toast.LENGTH_LONG).show(); |
| 323 | } |
| 324 | } |
| 325 | }); |
| 326 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 327 | isReady = true; |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 328 | if (mCallbacks.getService() != null) { |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 329 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 330 | onServiceSipBinded(mCallbacks.getService()); |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 331 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 332 | return inflatedView; |
| 333 | } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 334 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 335 | public void processingNewCallAction() { |
| 336 | // String accountID = mAccountList.currentAccountID; |
| 337 | String accountID = mAccountSelectionSpinner.getAccount(); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 338 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 339 | String to = phoneField.getText().toString(); |
| 340 | |
| 341 | Random random = new Random(); |
| 342 | String callID = Integer.toString(random.nextInt()); |
| 343 | SipCall.CallInfo info = new SipCall.CallInfo(); |
| 344 | |
| 345 | info.mCallID = callID; |
| 346 | info.mAccountID = accountID; |
| 347 | info.mDisplayName = "Cool Guy!"; |
| 348 | info.mPhone = to; |
| 349 | info.mEmail = "coolGuy@coolGuy.com"; |
| 350 | info.mCallType = SipCall.CALL_TYPE_OUTGOING; |
| 351 | |
| 352 | SipCall call = CallListReceiver.getCallInstance(info); |
| 353 | mCallbacks.onCallSelected(call); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 354 | |
| 355 | try { |
| 356 | service.placeCall(info.mAccountID, info.mCallID, info.mPhone); |
| 357 | } catch (RemoteException e) { |
| 358 | Log.e(TAG, "Cannot call service method", e); |
| 359 | } |
| 360 | addCall(call); |
| 361 | } |
| 362 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 363 | @Override |
| 364 | public Loader<Cursor> onCreateLoader(int id, Bundle args) { |
| 365 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 366 | Log.i(TAG, "onCreateLoader"); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 367 | Uri baseUri; |
| 368 | |
| 369 | if (mCurFilter != null) { |
| 370 | baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(mCurFilter)); |
| 371 | } else { |
| 372 | baseUri = Contacts.CONTENT_URI; |
| 373 | } |
| 374 | |
| 375 | // Now create and return a CursorLoader that will take care of |
| 376 | // creating a Cursor for the data being displayed. |
| 377 | String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.HAS_PHONE_NUMBER + "=1) AND (" + Contacts.DISPLAY_NAME |
| 378 | + " != '' ))"; |
| 379 | // String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ))"; |
| 380 | |
| 381 | return new CursorLoader(getActivity(), baseUri, CONTACTS_SUMMARY_PROJECTION, select, null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"); |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public void onLoadFinished(Loader<Cursor> loader, Cursor data) { |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 386 | Log.i(TAG, "onLoadFinished"); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 387 | // Swap the new cursor in. (The framework will take care of closing the |
| 388 | // old cursor once we return.) |
| 389 | // mAdapter.swapCursor(data); |
| 390 | |
| 391 | // The list should now be shown. |
| 392 | /* |
| 393 | * if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } |
| 394 | */ |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public void onLoaderReset(Loader<Cursor> loader) { |
| 399 | // This is called when the last Cursor provided to onLoadFinished() |
| 400 | // above is about to be closed. We need to make sure we are no |
| 401 | // longer using it. |
| 402 | // mAdapter.swapCursor(null); |
| 403 | } |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 404 | |
| 405 | /** |
| 406 | * Called by activity to pass a reference to sipservice to Fragment. |
| 407 | * |
| 408 | * @param isip |
| 409 | */ |
| 410 | public void onServiceSipBinded(ISipService isip) { |
| 411 | |
| 412 | if (isReady) { |
| 413 | service = isip; |
| 414 | ArrayList<String> accountList; |
| 415 | try { |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 416 | accountList = (ArrayList<String>) mCallbacks.getService().getAccountList(); |
| 417 | mAccountSelectionSpinner.populate(mCallbacks.getService(), accountList); |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 418 | } catch (RemoteException e) { |
| 419 | Log.i(TAG, e.toString()); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | } |
| 424 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 425 | public void updateCall(String iD, String newState) { |
| 426 | mAdapter.update(iD, newState); |
| 427 | |
| 428 | } |
| 429 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 430 | } |