use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by LineageOS.
the class SmartDialCursorLoader method loadInBackground.
/**
* Queries the SmartDial database and loads results in background.
*
* @return Cursor of contacts that matches the SmartDial query.
*/
@Override
public Cursor loadInBackground() {
if (DEBUG) {
LogUtil.v(TAG, "Load in background " + query);
}
if (!PermissionsUtil.hasContactsReadPermissions(context)) {
return new MatrixCursor(PhoneQuery.PROJECTION_PRIMARY);
}
/**
* Loads results from the database helper.
*/
final DialerDatabaseHelper dialerDatabaseHelper = Database.get(context).getDatabaseHelper(context);
final ArrayList<ContactNumber> allMatches = dialerDatabaseHelper.getLooseMatches(query, nameMatcher);
if (DEBUG) {
LogUtil.v(TAG, "Loaded matches " + allMatches.size());
}
/**
* Constructs a cursor for the returned array of results.
*/
final MatrixCursor cursor = new MatrixCursor(PhoneQuery.PROJECTION_PRIMARY);
Object[] row = new Object[PhoneQuery.PROJECTION_PRIMARY.length];
for (ContactNumber contact : allMatches) {
row[PhoneQuery.PHONE_ID] = contact.dataId;
row[PhoneQuery.PHONE_NUMBER] = contact.phoneNumber;
row[PhoneQuery.CONTACT_ID] = contact.id;
row[PhoneQuery.LOOKUP_KEY] = contact.lookupKey;
row[PhoneQuery.PHOTO_ID] = contact.photoId;
row[PhoneQuery.DISPLAY_NAME] = contact.displayName;
row[PhoneQuery.CARRIER_PRESENCE] = contact.carrierPresence;
cursor.addRow(row);
}
return cursor;
}
Aggregations