2008-11-01 17:32:06 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2008-12-16 18:34:01 -05:00
|
|
|
package com.android.email;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
import static android.provider.Contacts.ContactMethods.CONTENT_EMAIL_URI;
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.DatabaseUtils;
|
|
|
|
import android.provider.Contacts.ContactMethods;
|
|
|
|
import android.provider.Contacts.People;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ResourceCursorAdapter;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2008-12-16 18:34:01 -05:00
|
|
|
import com.android.email.mail.Address;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public class EmailAddressAdapter extends ResourceCursorAdapter
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
public static final int NAME_INDEX = 1;
|
|
|
|
|
|
|
|
public static final int DATA_INDEX = 2;
|
|
|
|
|
|
|
|
private static final String SORT_ORDER = People.TIMES_CONTACTED + " DESC, " + People.NAME;
|
|
|
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
private static final String[] PROJECTION =
|
|
|
|
{
|
|
|
|
ContactMethods._ID, // 0
|
|
|
|
ContactMethods.NAME, // 1
|
|
|
|
ContactMethods.DATA
|
|
|
|
// 2
|
2008-11-01 17:32:06 -04:00
|
|
|
};
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public EmailAddressAdapter(Context context)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
super(context, R.layout.recipient_dropdown_item, null);
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public final String convertToString(Cursor cursor)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
String name = cursor.getString(NAME_INDEX);
|
|
|
|
String address = cursor.getString(DATA_INDEX);
|
|
|
|
|
|
|
|
return new Address(address, name).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public final void bindView(View view, Context context, Cursor cursor)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
TextView text1 = (TextView)view.findViewById(R.id.text1);
|
|
|
|
TextView text2 = (TextView)view.findViewById(R.id.text2);
|
|
|
|
text1.setText(cursor.getString(NAME_INDEX));
|
|
|
|
text2.setText(cursor.getString(DATA_INDEX));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public Cursor runQueryOnBackgroundThread(CharSequence constraint)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
String where = null;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
if (constraint != null)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
String filter = DatabaseUtils.sqlEscapeString(constraint.toString() + '%');
|
|
|
|
|
|
|
|
StringBuilder s = new StringBuilder();
|
2009-11-15 00:59:16 -05:00
|
|
|
s.append("("+People.NAME+" LIKE ");
|
2008-11-01 17:32:06 -04:00
|
|
|
s.append(filter);
|
2009-11-15 00:59:16 -05:00
|
|
|
s.append(") OR ("+ContactMethods.DATA+" LIKE ");
|
2008-11-01 17:32:06 -04:00
|
|
|
s.append(filter);
|
|
|
|
s.append(")");
|
|
|
|
|
|
|
|
where = s.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mContentResolver.query(CONTENT_EMAIL_URI, PROJECTION, where, null, SORT_ORDER);
|
|
|
|
}
|
|
|
|
}
|