Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -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.client; |
| 32 | |
| 33 | import java.io.InputStream; |
| 34 | import java.util.ArrayList; |
| 35 | import java.util.List; |
| 36 | import java.util.concurrent.ExecutorService; |
| 37 | import java.util.concurrent.Executors; |
| 38 | |
Emeric Vigier | 1f1ced3 | 2012-11-02 16:56:32 -0400 | [diff] [blame] | 39 | import android.app.Activity; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 40 | import android.app.ListFragment; |
| 41 | import android.app.LoaderManager; |
Alexandre Savard | f1e32cf | 2012-09-20 17:45:16 -0400 | [diff] [blame] | 42 | import android.app.AlertDialog; |
| 43 | import android.app.AlertDialog.Builder; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 44 | import android.content.ContentResolver; |
| 45 | import android.content.ContentUris; |
| 46 | import android.content.Context; |
| 47 | import android.content.CursorLoader; |
Alexandre Savard | f1e32cf | 2012-09-20 17:45:16 -0400 | [diff] [blame] | 48 | import android.content.DialogInterface; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 49 | import android.content.Loader; |
| 50 | import android.database.Cursor; |
| 51 | import android.graphics.Bitmap; |
| 52 | import android.graphics.BitmapFactory; |
| 53 | import android.net.Uri; |
| 54 | import android.os.Bundle; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 55 | import android.os.RemoteException; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 56 | import android.provider.*; |
| 57 | import android.provider.ContactsContract.CommonDataKinds; |
| 58 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 59 | import android.provider.ContactsContract.CommonDataKinds.SipAddress; |
| 60 | import android.provider.ContactsContract.Contacts; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 61 | import android.util.Log; |
| 62 | import android.view.*; |
Alexandre Savard | f1e32cf | 2012-09-20 17:45:16 -0400 | [diff] [blame] | 63 | import android.widget.AdapterView.OnItemLongClickListener; |
| 64 | import android.widget.AdapterView.OnItemSelectedListener; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 65 | import android.widget.*; |
Alexandre Savard | 38d6a15 | 2012-09-18 13:33:02 -0400 | [diff] [blame] | 66 | import java.util.List; |
| 67 | import java.util.ArrayList; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 68 | |
| 69 | import com.savoirfairelinux.sflphone.R; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 70 | import com.savoirfairelinux.sflphone.service.ISipService; |
Alexandre Savard | 35d208a | 2012-10-31 15:15:06 -0400 | [diff] [blame] | 71 | import com.savoirfairelinux.sflphone.utils.AccountSelectionButton; |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 72 | import com.savoirfairelinux.sflphone.utils.AccountList; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Main list of Call Elements. |
| 76 | * We don't manage contacts ourself so they are |
| 77 | */ |
Alexandre Savard | 9b742d5 | 2012-09-20 13:57:44 -0400 | [diff] [blame] | 78 | public class CallElementList extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 79 | { |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 80 | private static final String TAG = "CallElementList"; |
| 81 | private static final String CURRENT_STATE_LABEL = " CURRENT STATE: "; |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 82 | private ContactManager mContactManager; |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 83 | private CallElementAdapter mAdapter; |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 84 | private String mCurFilter; |
| 85 | private SFLPhoneHome sflphoneHome; |
Emeric Vigier | 0038a61 | 2012-11-06 18:51:19 -0500 | [diff] [blame^] | 86 | private SFLphoneApplication sflphoneApplication; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 87 | private ISipService service; |
Alexandre Savard | 35d208a | 2012-10-31 15:15:06 -0400 | [diff] [blame] | 88 | private AccountSelectionButton mAccountSelectionButton; |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 89 | private AccountList mAccountList; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 90 | |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 91 | static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, |
| 92 | Contacts.PHOTO_ID, Contacts.LOOKUP_KEY }; |
| 93 | static final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE }; |
| 94 | static final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE }; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 95 | |
Emeric Vigier | 1f1ced3 | 2012-11-02 16:56:32 -0400 | [diff] [blame] | 96 | @Override |
| 97 | public void onAttach(Activity activity) { |
| 98 | super.onAttach(activity); |
| 99 | sflphoneHome = (SFLPhoneHome) activity; |
| 100 | service = ((SFLphoneApplication) sflphoneHome.getApplication()).getSipService(); |
Emeric Vigier | cc0785a | 2012-11-06 19:07:48 -0500 | [diff] [blame] | 101 | mAccountList = ((SFLphoneApplication) sflphoneHome.getApplication()).getAccountList(); |
Emeric Vigier | 1f1ced3 | 2012-11-02 16:56:32 -0400 | [diff] [blame] | 102 | Log.i(TAG, "onAttach() service " + service); |
| 103 | } |
| 104 | |
Alexandre Savard | 60f0f1c | 2012-11-01 09:40:34 -0400 | [diff] [blame] | 105 | public String getSelectedAccount() { |
| 106 | return mAccountSelectionButton.getText().toString(); |
| 107 | } |
| 108 | |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 109 | /** |
| 110 | * Runnable that fill information in a contact card asynchroniously. |
| 111 | */ |
| 112 | public static class InfosLoader implements Runnable |
| 113 | { |
| 114 | private View view; |
| 115 | private long cid; |
| 116 | private ContentResolver cr; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 117 | |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 118 | public InfosLoader(Context context, View element, long contact_id) |
Alexandre Savard | 38d6a15 | 2012-09-18 13:33:02 -0400 | [diff] [blame] | 119 | { |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 120 | cid = contact_id; |
| 121 | cr = context.getContentResolver(); |
| 122 | view = element; |
Alexandre Savard | 38d6a15 | 2012-09-18 13:33:02 -0400 | [diff] [blame] | 123 | } |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 124 | |
| 125 | public static Bitmap loadContactPhoto(ContentResolver cr, long id) { |
| 126 | Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); |
| 127 | InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri); |
| 128 | if (input == null) { |
| 129 | return null; |
| 130 | } |
| 131 | return BitmapFactory.decodeStream(input); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public void run() |
| 136 | { |
| 137 | final Bitmap photo_bmp = loadContactPhoto(cr, cid); |
| 138 | |
| 139 | Cursor phones = cr.query(CommonDataKinds.Phone.CONTENT_URI, |
| 140 | CONTACTS_PHONES_PROJECTION, |
| 141 | CommonDataKinds.Phone.CONTACT_ID + " = ?", |
| 142 | new String[] { Long.toString(cid) }, null); |
| 143 | |
| 144 | final List<String> numbers = new ArrayList<String>(); |
| 145 | while (phones.moveToNext()) { |
| 146 | String number = phones.getString(phones.getColumnIndex(CommonDataKinds.Phone.NUMBER)); |
| 147 | //int type = phones.getInt(phones.getColumnIndex(CommonDataKinds.Phone.TYPE)); |
| 148 | numbers.add(number); |
| 149 | } |
| 150 | phones.close(); |
| 151 | // TODO: same for SIP adresses. |
| 152 | |
| 153 | final Bitmap bmp = photo_bmp; |
| 154 | view.post(new Runnable() |
| 155 | { |
| 156 | @Override |
| 157 | public void run() |
| 158 | { |
| 159 | /* |
| 160 | ImageView photo_view = (ImageView) view.findViewById(R.id.photo); |
| 161 | TextView phones_txt = (TextView) view.findViewById(R.id.phones); |
| 162 | |
| 163 | if (photo_bmp != null) { |
| 164 | photo_view.setImageBitmap(bmp); |
| 165 | photo_view.setVisibility(View.VISIBLE); |
| 166 | } else { |
| 167 | photo_view.setVisibility(View.GONE); |
| 168 | } |
| 169 | |
| 170 | if (numbers.size() > 0) { |
| 171 | String phonestxt = numbers.get(0); |
| 172 | for (int i = 1, n = numbers.size(); i < n; i++) |
| 173 | phonestxt += "\n" + numbers.get(i); |
| 174 | phones_txt.setText(phonestxt); |
| 175 | phones_txt.setVisibility(View.VISIBLE); |
| 176 | } else |
| 177 | phones_txt.setVisibility(View.GONE); |
| 178 | */ |
| 179 | } |
| 180 | }); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * A CursorAdapter that creates and update call elements using corresponding contact infos. |
| 186 | * TODO: handle contact list separatly to allow showing synchronized contacts on Call cards with multiple contacts etc. |
| 187 | */ |
| 188 | public static class CallElementAdapter extends ArrayAdapter |
| 189 | { |
| 190 | private ExecutorService infos_fetcher = Executors.newCachedThreadPool(); |
| 191 | private Context mContext; |
| 192 | private final List mCallList; |
| 193 | |
| 194 | public CallElementAdapter(Context context, List callList) |
| 195 | { |
| 196 | super(context, R.layout.call_element, callList); |
| 197 | mContext = context; |
| 198 | mCallList = callList; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public View getView(int position, View convertView, ViewGroup parent) |
| 203 | { |
| 204 | View rowView = convertView; |
| 205 | CallElementView entryView = null; |
| 206 | |
| 207 | if(rowView == null) |
| 208 | { |
| 209 | // Get a new instance of the row layout view |
| 210 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 211 | rowView = inflater.inflate(R.layout.call_element, null); |
| 212 | |
| 213 | // Hold the view objects in an object |
| 214 | // so they don't need to be re-fetched |
| 215 | entryView = new CallElementView(); |
| 216 | entryView.toggleButton = (ImageButton) rowView.findViewById(R.id.toggleButton1); |
| 217 | entryView.button = (Button) rowView.findViewById(R.id.button2); |
| 218 | entryView.photo = (ImageView) rowView.findViewById(R.id.photo); |
| 219 | entryView.displayName = (TextView) rowView.findViewById(R.id.display_name); |
| 220 | entryView.phones = (TextView) rowView.findViewById(R.id.phones); |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 221 | entryView.state = (TextView) rowView.findViewById(R.id.callstate); |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 222 | |
| 223 | // Cache the view obects in the tag |
| 224 | // so they can be re-accessed later |
| 225 | rowView.setTag(entryView); |
| 226 | } else { |
| 227 | entryView = (CallElementView) rowView.getTag(); |
| 228 | } |
| 229 | |
| 230 | // Transfer the stock data from the data object |
| 231 | // to the view objects |
| 232 | SipCall call = (SipCall) mCallList.get(position); |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 233 | call.setAssociatedRowView(rowView); |
| 234 | entryView.displayName.setText(call.getDisplayName()); |
| 235 | entryView.phones.setText(call.getPhone()); |
| 236 | entryView.state.setText(CURRENT_STATE_LABEL + call.getCallStateString()); |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 237 | |
| 238 | return rowView; |
| 239 | } |
| 240 | }; |
| 241 | |
| 242 | public static class CallElementView |
| 243 | { |
| 244 | protected ImageButton toggleButton; |
| 245 | protected Button button; |
| 246 | protected ImageView photo; |
| 247 | protected TextView displayName; |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 248 | protected TextView phones; |
| 249 | protected TextView state; |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 250 | } |
| 251 | |
Emeric Vigier | 1f1ced3 | 2012-11-02 16:56:32 -0400 | [diff] [blame] | 252 | public CallElementList() |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 253 | { |
| 254 | super(); |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | public void setAccountList(AccountList accountList) { |
| 258 | mAccountList = accountList; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 259 | } |
| 260 | |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 261 | public void addCall(SipCall c) |
| 262 | { |
| 263 | Log.i(TAG, "Adding call " + c.mCallInfo.mDisplayName); |
| 264 | mAdapter.add(c); |
| 265 | } |
| 266 | |
Alexandre Savard | 9b742d5 | 2012-09-20 13:57:44 -0400 | [diff] [blame] | 267 | public void removeCall(SipCall c) |
| 268 | { |
| 269 | Log.i(TAG, "Removing call " + c.mCallInfo.mDisplayName); |
| 270 | mAdapter.remove(c); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | @Override |
| 275 | public void onActivityCreated(Bundle savedInstanceState) |
| 276 | { |
| 277 | super.onActivityCreated(savedInstanceState); |
| 278 | |
| 279 | // Give some text to display if there is no data. In a real |
| 280 | // application this would come from a resource. |
| 281 | //setEmptyText("No phone numbers"); |
| 282 | |
| 283 | // We have a menu item to show in action bar. |
| 284 | setHasOptionsMenu(true); |
| 285 | |
| 286 | |
| 287 | // Create an empty adapter we will use to display the loaded data. |
Alexandre Savard | d197653 | 2012-10-26 15:32:45 -0400 | [diff] [blame] | 288 | ArrayList calls = new ArrayList(); |
Alexandre Savard | 9b742d5 | 2012-09-20 13:57:44 -0400 | [diff] [blame] | 289 | mAdapter = new CallElementAdapter(getActivity(), calls); |
| 290 | setListAdapter(mAdapter); |
| 291 | |
| 292 | // Start out with a progress indicator. |
| 293 | //setListShown(false); |
| 294 | |
| 295 | // Prepare the loader. Either re-connect with an existing one, |
| 296 | // or start a new one. |
| 297 | // getLoaderManager().initLoader(0, null, this) |
Alexandre Savard | f1e32cf | 2012-09-20 17:45:16 -0400 | [diff] [blame] | 298 | |
| 299 | final Context context = getActivity(); |
| 300 | ListView lv = getListView(); |
| 301 | lv.setOnItemLongClickListener(new OnItemLongClickListener() { |
| 302 | @Override |
| 303 | public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) { |
| 304 | Log.i(TAG, "On Long Click"); |
| 305 | final CharSequence[] items = {"Hang up Call", "Send Message", "Add to Conference"}; |
| 306 | final SipCall call = (SipCall) mAdapter.getItem(pos); |
Emeric Vigier | 0038a61 | 2012-11-06 18:51:19 -0500 | [diff] [blame^] | 307 | // FIXME |
| 308 | service = sflphoneApplication.getSipService(); |
Alexandre Savard | f1e32cf | 2012-09-20 17:45:16 -0400 | [diff] [blame] | 309 | AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 310 | builder.setTitle("Action to perform with " + call.mCallInfo.mDisplayName) |
| 311 | .setCancelable(true) |
| 312 | .setItems(items, new DialogInterface.OnClickListener() { |
| 313 | public void onClick(DialogInterface dialog, int item) { |
| 314 | Log.i(TAG, "Selected " + items[item]); |
| 315 | switch (item) { |
| 316 | case 0: |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 317 | call.notifyServiceHangup(service); |
Alexandre Savard | f1e32cf | 2012-09-20 17:45:16 -0400 | [diff] [blame] | 318 | break; |
| 319 | case 1: |
| 320 | call.sendTextMessage(); |
| 321 | // Need to hangup this call immediately since no way to do it after this action |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 322 | call.notifyServiceHangup(service); |
Alexandre Savard | f1e32cf | 2012-09-20 17:45:16 -0400 | [diff] [blame] | 323 | break; |
| 324 | case 2: |
| 325 | call.addToConference(); |
| 326 | // Need to hangup this call immediately since no way to do it after this action |
Alexandre Savard | 4f42ade | 2012-10-24 18:03:31 -0400 | [diff] [blame] | 327 | call.notifyServiceHangup(service); |
Alexandre Savard | f1e32cf | 2012-09-20 17:45:16 -0400 | [diff] [blame] | 328 | break; |
| 329 | default: |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | }); |
| 334 | AlertDialog alert = builder.create(); |
| 335 | alert.show(); |
| 336 | |
| 337 | return true; |
| 338 | } |
| 339 | }); |
Alexandre Savard | 9b742d5 | 2012-09-20 13:57:44 -0400 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | @Override |
| 343 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
Alexandre Savard | 9b742d5 | 2012-09-20 13:57:44 -0400 | [diff] [blame] | 344 | View inflatedView = inflater.inflate(R.layout.call_element_list, container, false); |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 345 | |
Alexandre Savard | 35d208a | 2012-10-31 15:15:06 -0400 | [diff] [blame] | 346 | mAccountSelectionButton = (AccountSelectionButton) inflatedView.findViewById(R.id.account_selection_button); |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 347 | mAccountList.addManagementUI(mAccountSelectionButton); |
Alexandre Savard | af0f3c6 | 2012-11-01 18:35:56 -0400 | [diff] [blame] | 348 | mAccountSelectionButton.setAccountList(mAccountList); |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 349 | |
Alexandre Savard | 9b742d5 | 2012-09-20 13:57:44 -0400 | [diff] [blame] | 350 | return inflatedView; |
| 351 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 352 | |
Alexandre Savard | 9b742d5 | 2012-09-20 13:57:44 -0400 | [diff] [blame] | 353 | public void onListItemClick(ListView l, View v, int position, long id) |
| 354 | { |
| 355 | // Insert desired behavior here. |
Alexandre Savard | 6b7f418 | 2012-09-20 14:10:42 -0400 | [diff] [blame] | 356 | SipCall call = (SipCall) mAdapter.getItem(position); |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 357 | Log.i(TAG, "Call Clicked: " + call.getCallId()); |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 358 | |
Alexandre Savard | df54426 | 2012-10-25 14:24:08 -0400 | [diff] [blame] | 359 | call.launchCallActivity(getActivity()); |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 360 | |
| 361 | sflphoneHome.onSelectedCallAction(call); |
Alexandre Savard | 9b742d5 | 2012-09-20 13:57:44 -0400 | [diff] [blame] | 362 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 363 | |
| 364 | @Override |
| 365 | public Loader<Cursor> onCreateLoader(int id, Bundle args) |
| 366 | { |
| 367 | |
| 368 | //return new CursorLoader(getActivity(), CommonDataKinds.Phone.CONTENT_URI, null,null,null, null); |
| 369 | |
| 370 | // This is called when a new Loader needs to be created. This |
| 371 | // sample only has one Loader, so we don't care about the ID. |
| 372 | // First, pick the base URI to use depending on whether we are |
| 373 | // currently filtering. |
| 374 | Uri baseUri; |
| 375 | |
| 376 | if (mCurFilter != null) { |
| 377 | baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(mCurFilter)); |
| 378 | } else { |
| 379 | baseUri = Contacts.CONTENT_URI; |
| 380 | } |
| 381 | |
| 382 | // Now create and return a CursorLoader that will take care of |
| 383 | // creating a Cursor for the data being displayed. |
| 384 | String select = "((" + Contacts.DISPLAY_NAME |
| 385 | + " NOTNULL) AND (" |
| 386 | + Contacts.HAS_PHONE_NUMBER |
| 387 | + "=1) AND (" |
| 388 | + Contacts.DISPLAY_NAME |
| 389 | + " != '' ))"; |
| 390 | //String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ))"; |
| 391 | |
| 392 | return new CursorLoader(getActivity(), |
| 393 | baseUri, |
| 394 | CONTACTS_SUMMARY_PROJECTION, |
| 395 | select, |
| 396 | null, |
| 397 | Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"); |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public void onLoadFinished(Loader<Cursor> loader, Cursor data) |
| 402 | { |
| 403 | // Swap the new cursor in. (The framework will take care of closing the |
| 404 | // old cursor once we return.) |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 405 | // mAdapter.swapCursor(data); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 406 | |
| 407 | // The list should now be shown. |
| 408 | /* |
| 409 | if (isResumed()) { |
| 410 | setListShown(true); |
| 411 | } else { |
| 412 | setListShownNoAnimation(true); |
| 413 | }*/ |
| 414 | } |
| 415 | |
| 416 | @Override |
| 417 | public void onLoaderReset(Loader<Cursor> loader) |
| 418 | { |
| 419 | // This is called when the last Cursor provided to onLoadFinished() |
| 420 | // above is about to be closed. We need to make sure we are no |
| 421 | // longer using it. |
Alexandre Savard | a140465 | 2012-09-20 13:34:08 -0400 | [diff] [blame] | 422 | // mAdapter.swapCursor(null); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 423 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 424 | } |