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.
|
|
|
|
*/
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-08-14 09:59:33 -04:00
|
|
|
import com.fsck.k9.helper.Contacts;
|
|
|
|
import com.fsck.k9.mail.Address;
|
2008-11-01 17:32:06 -04:00
|
|
|
import android.content.Context;
|
2010-08-14 09:59:33 -04:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.view.View;
|
2008-11-01 17:32:06 -04:00
|
|
|
import android.widget.ResourceCursorAdapter;
|
2010-08-14 09:59:33 -04:00
|
|
|
import android.widget.TextView;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public class EmailAddressAdapter extends ResourceCursorAdapter {
|
2010-03-22 23:19:12 -04:00
|
|
|
private static EmailAddressAdapter sInstance;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public static EmailAddressAdapter getInstance(Context context) {
|
|
|
|
if (sInstance == null) {
|
2010-08-14 09:59:33 -04:00
|
|
|
sInstance = new EmailAddressAdapter(context);
|
|
|
|
}
|
2010-03-22 23:19:12 -04:00
|
|
|
|
2010-08-14 09:59:33 -04:00
|
|
|
return sInstance;
|
|
|
|
}
|
2010-03-22 23:19:12 -04:00
|
|
|
|
|
|
|
|
2010-11-30 22:03:22 -05:00
|
|
|
private final Contacts mContacts;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private EmailAddressAdapter(Context context) {
|
2010-08-14 09:59:33 -04:00
|
|
|
super(context, R.layout.recipient_dropdown_item, null);
|
|
|
|
mContacts = Contacts.getInstance(context);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2010-08-14 09:59:33 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public final String convertToString(final Cursor cursor) {
|
2010-08-14 09:59:33 -04:00
|
|
|
final String name = mContacts.getName(cursor);
|
2010-11-30 22:07:28 -05:00
|
|
|
final String address = mContacts.getEmail(cursor);
|
2010-08-14 09:59:33 -04:00
|
|
|
|
|
|
|
return new Address(address, name).toString();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2010-08-14 09:59:33 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public final void bindView(final View view, final Context context, final Cursor cursor) {
|
2010-08-14 09:59:33 -04:00
|
|
|
final TextView text1 = (TextView) view.findViewById(R.id.text1);
|
|
|
|
final TextView text2 = (TextView) view.findViewById(R.id.text2);
|
|
|
|
text1.setText(mContacts.getName(cursor));
|
|
|
|
text2.setText(mContacts.getEmail(cursor));
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-08-14 09:59:33 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
|
2010-08-14 09:59:33 -04:00
|
|
|
return mContacts.searchContacts(constraint);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|