FileDocCategorySizeDatePackage
ContactsPickerActivity.javaAPI DocAndroid 1.5 API5675Wed May 06 22:42:46 BST 2009com.android.im.app

ContactsPickerActivity

public class ContactsPickerActivity extends android.app.ListActivity
Activity used to pick a contact.

Fields Summary
public static final String
EXTRA_EXCLUDED_CONTACTS
public static final String
EXTRA_RESULT_USERNAME
private ContactsAdapter
mAdapter
private String
mExcludeClause
android.net.Uri
mData
android.widget.Filter
mFilter
Constructors Summary
Methods Summary
private static java.lang.StringbuildExcludeClause(java.lang.String[] excluded)

        if (excluded == null || excluded.length == 0) {
            return null;
        }

        StringBuilder clause = new StringBuilder();
        clause.append(Im.Contacts.USERNAME);
        clause.append(" NOT IN (");
        int len = excluded.length;
        for (int i = 0; i < len - 1; i++) {
            DatabaseUtils.appendValueToSql(clause, excluded[i]);
            clause.append(',");
        }
        DatabaseUtils.appendValueToSql(clause, excluded[len - 1]);
        clause.append(')");
        return clause.toString();
    
private static final voidlog(java.lang.String msg)


          
        Log.d(ImApp.LOG_TAG, "<ContactsPickerActivity> " + msg);
    
protected voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        setContentView(R.layout.contacts_picker_activity);
        if(!resolveIntent()){
            if(Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
                log("no data, finish");
            }
            finish();
            return;
        }

        EditText filter = (EditText)findViewById(R.id.filter);
        filter.addTextChangedListener(new TextWatcher() {
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mFilter.filter(s);
            }

            public void afterTextChanged(Editable s) {
            }
        });
    
protected voidonListItemClick(android.widget.ListView l, android.view.View v, int position, long id)

        Cursor cursor = (Cursor)mAdapter.getItem(position);
        Intent data = new Intent();
        data.putExtra(EXTRA_RESULT_USERNAME,
                cursor.getString(ContactView.COLUMN_CONTACT_USERNAME));
        setResult(RESULT_OK, data);
        finish();
    
private booleanresolveIntent()

        Intent i = getIntent();
        mData = i.getData();

        if(mData == null) {
            return false;
        }
        mExcludeClause = buildExcludeClause(i.getStringArrayExtra(EXTRA_EXCLUDED_CONTACTS));
        Cursor cursor = managedQuery(mData, ContactView.CONTACT_PROJECTION,
                mExcludeClause, Im.Contacts.DEFAULT_SORT_ORDER);
        if (cursor == null) {
            return false;
        }

        mAdapter = new ContactsAdapter(this, cursor);
        mFilter = mAdapter.getFilter();
        setListAdapter(mAdapter);
        return true;
    
android.database.CursorrunQuery(java.lang.CharSequence constraint)

        String where;
        if (constraint == null) {
            where = mExcludeClause;
        } else {
            StringBuilder buf = new StringBuilder();
            if (mExcludeClause != null) {
                buf.append(mExcludeClause).append(" AND ");
            }

            buf.append(Im.Contacts.NICKNAME);
            buf.append(" LIKE ");
            DatabaseUtils.appendValueToSql(buf, "%" + constraint + "%");

            where = buf.toString();
        }
        return managedQuery(mData, ContactView.CONTACT_PROJECTION, where,
                Im.Contacts.DEFAULT_SORT_ORDER);