Search in sources :

Example 1 with DialerDatabaseHelper

use of com.android.dialer.database.DialerDatabaseHelper in project android_packages_apps_Dialer by MoKee.

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) {
        Log.v(TAG, "Load in background " + mQuery);
    }
    if (!PermissionsUtil.hasContactsPermissions(mContext)) {
        return new MatrixCursor(PhoneQuery.PROJECTION_PRIMARY);
    }
    /**
     * Loads results from the database helper.
     */
    final DialerDatabaseHelper dialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(mContext);
    final ArrayList<ContactNumber> allMatches = dialerDatabaseHelper.getLooseMatches(mQuery, mNameMatcher);
    if (DEBUG) {
        Log.v(TAG, "Loaded matches " + String.valueOf(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;
}
Also used : ContactNumber(com.android.dialer.database.DialerDatabaseHelper.ContactNumber) DialerDatabaseHelper(com.android.dialer.database.DialerDatabaseHelper) MatrixCursor(android.database.MatrixCursor)

Example 2 with DialerDatabaseHelper

use of com.android.dialer.database.DialerDatabaseHelper 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 " + mQuery);
    }
    if (!PermissionsUtil.hasContactsReadPermissions(mContext)) {
        return new MatrixCursor(PhoneQuery.PROJECTION_PRIMARY);
    }
    /**
     * Loads results from the database helper.
     */
    final DialerDatabaseHelper dialerDatabaseHelper = Database.get(mContext).getDatabaseHelper(mContext);
    final ArrayList<ContactNumber> allMatches = dialerDatabaseHelper.getLooseMatches(mQuery, mNameMatcher);
    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;
}
Also used : ContactNumber(com.android.dialer.database.DialerDatabaseHelper.ContactNumber) DialerDatabaseHelper(com.android.dialer.database.DialerDatabaseHelper) MatrixCursor(android.database.MatrixCursor)

Aggregations

MatrixCursor (android.database.MatrixCursor)2 DialerDatabaseHelper (com.android.dialer.database.DialerDatabaseHelper)2 ContactNumber (com.android.dialer.database.DialerDatabaseHelper.ContactNumber)2