7 package com.google.appinventor.components.runtime;
9 import android.content.ContentResolver;
10 import android.content.Context;
11 import android.database.Cursor;
12 import android.database.DatabaseUtils;
13 import android.provider.Contacts.ContactMethods;
14 import android.provider.Contacts.People;
15 import android.text.TextUtils;
16 import android.text.util.Rfc822Token;
17 import android.view.View;
18 import android.widget.ResourceCursorAdapter;
19 import android.widget.TextView;
20 import android.util.Log;
38 private static final boolean DEBUG =
false;
39 private static final String TAG =
"EmailAddressAdapter";
44 private static String SORT_ORDER;
46 private ContentResolver contentResolver;
48 private Context context;
50 private static final String[] PRE_HONEYCOMB_PROJECTION = {
59 super(context, android.R.layout.simple_dropdown_item_1line,
null);
60 contentResolver = context.getContentResolver();
61 this.context = context;
65 SORT_ORDER = People.TIMES_CONTACTED +
" DESC, " + People.NAME;
78 name = cursor.getString(POST_HONEYCOMB_NAME_INDEX);
79 address = cursor.getString(POST_HONEYCOMB_EMAIL_INDEX);
85 return new Rfc822Token(name, address,
null).toString();
88 private final String makeDisplayString(Cursor cursor) {
92 StringBuilder s =
new StringBuilder();
98 name = cursor.getString(POST_HONEYCOMB_NAME_INDEX);
99 address = cursor.getString(POST_HONEYCOMB_EMAIL_INDEX);
105 if (!TextUtils.isEmpty(name)) {
124 public final void bindView(View view, Context context, Cursor cursor) {
125 ((TextView) view).setText(makeDisplayString(cursor));
132 android.net.Uri db =
null;
133 StringBuilder s =
new StringBuilder();
135 if (constraint !=
null) {
136 String filter = DatabaseUtils.sqlEscapeString(constraint.toString() +
'%');
142 s.append(
"(display_name LIKE ");
146 db = ContactMethods.CONTENT_EMAIL_URI;
147 s.append(
"(name LIKE ");
149 s.append(
") OR (display_name LIKE ");
154 where = s.toString();
159 Cursor c = context.getContentResolver().query(db,
null,
null,
null,
null,
null);
160 Log.d(TAG,
"listing columns");
161 for (
int i = 0; i<c.getColumnCount(); i++) {
162 Log.d(TAG,
"column " + i +
"=" + c.getColumnName(i));
167 return contentResolver.query(db, POST_HONEYCOMB_PROJECTION,
168 where,
null, SORT_ORDER);
170 return contentResolver.query(db, PRE_HONEYCOMB_PROJECTION,
171 where,
null, SORT_ORDER);