PageRenderTime 36ms CodeModel.GetById 26ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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