2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.calendar;
19 import android.content.ContentResolver;
20 import android.content.Context;
21 import android.database.Cursor;
22 import android.net.Uri;
23 import android.provider.ContactsContract.Contacts;
24 import android.provider.ContactsContract.Data;
25 import android.provider.ContactsContract.CommonDataKinds.Email;
26 import android.text.util.Rfc822Token;
27 import android.view.View;
28 import android.widget.ResourceCursorAdapter;
29 import android.widget.TextView;
31 // Customized from com.android.email.EmailAddressAdapter
33 public class EmailAddressAdapter extends ResourceCursorAdapter {
34 public static final int NAME_INDEX = 1;
35 public static final int DATA_INDEX = 2;
37 private static final String SORT_ORDER =
38 Contacts.TIMES_CONTACTED + " DESC, " + Contacts.DISPLAY_NAME;
40 private ContentResolver mContentResolver;
42 private static final String[] PROJECTION = {
44 Contacts.DISPLAY_NAME, // 1
48 public EmailAddressAdapter(Context context) {
49 super(context, android.R.layout.simple_dropdown_item_1line, null);
50 mContentResolver = context.getContentResolver();
54 public final String convertToString(Cursor cursor) {
55 return makeDisplayString(cursor);
58 private final String makeDisplayString(Cursor cursor) {
59 String name = cursor.getString(NAME_INDEX);
60 String address = cursor.getString(DATA_INDEX);
62 return new Rfc822Token(name, address, null).toString();
66 public final void bindView(View view, Context context, Cursor cursor) {
67 ((TextView) view).setText(makeDisplayString(cursor));
71 public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
72 String filter = constraint == null ? "" : constraint.toString();
73 Uri uri = Uri.withAppendedPath(Email.CONTENT_FILTER_URI, Uri.encode(filter));
74 return mContentResolver.query(uri, PROJECTION, null, null, SORT_ORDER);