/shell/src/com/google/marvin/shell/TalkContactChooserActivity.java

http://eyes-free.googlecode.com/ · Java · 49 lines · 39 code · 6 blank · 4 comment · 0 complexity · 74370f2f9d1f9b0e44c8c283e6c56bb3 MD5 · raw file

  1. // Copyright 2011 Google Inc. All Rights Reserved.
  2. package com.google.marvin.shell;
  3. import android.app.Activity;
  4. import android.app.ListActivity;
  5. import android.content.Intent;
  6. import android.database.Cursor;
  7. import android.os.Bundle;
  8. import android.provider.ContactsContract;
  9. import android.view.View;
  10. import android.widget.ListAdapter;
  11. import android.widget.ListView;
  12. import android.widget.SimpleCursorAdapter;
  13. /**
  14. * @author credo@google.com (Tim Credo)
  15. */
  16. public class TalkContactChooserActivity extends ListActivity {
  17. private Cursor mCursor;
  18. @Override
  19. public void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. String imWhere = ContactsContract.CommonDataKinds.Im.PROTOCOL + " = "
  22. + ContactsContract.CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK;
  23. mCursor = this.getContentResolver().query(
  24. android.provider.ContactsContract.Data.CONTENT_URI, null, null, null, null);
  25. ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2,
  26. mCursor, new String[] { ContactsContract.CommonDataKinds.Im.DISPLAY_NAME,
  27. ContactsContract.CommonDataKinds.Im.DATA },
  28. new int[] { android.R.id.text1, android.R.id.text2 });
  29. setListAdapter(adapter);
  30. }
  31. @Override
  32. protected void onListItemClick(ListView l, View v, int position, long id) {
  33. super.onListItemClick(l, v, position, id);
  34. mCursor.moveToPosition(position);
  35. int dataIndex = mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA);
  36. int nameIndex = mCursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DISPLAY_NAME);
  37. Intent data = new Intent();
  38. data.putExtra("address", mCursor.getString(dataIndex));
  39. data.putExtra("address", mCursor.getString(nameIndex));
  40. this.setResult(Activity.RESULT_OK, data);
  41. finish();
  42. }
  43. }