Search in sources :

Example 6 with ContactNumber

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

the class SmartDialPrefixTest method testPutForFullName.

public void testPutForFullName() {
    final SQLiteDatabase db = mTestHelper.getWritableDatabase();
    final MatrixCursor nameCursor = constructNewNameCursor();
    final MatrixCursor contactCursor = constructNewContactCursor();
    final ContactNumber jasonsmith = constructNewContactWithDummyIds(contactCursor, nameCursor, "", 0, "Jason Smith");
    final ContactNumber jasonsmitt = constructNewContactWithDummyIds(contactCursor, nameCursor, "", 1, "Jason Smitt");
    final ContactNumber alphabet = constructNewContactWithDummyIds(contactCursor, nameCursor, "12345678", 2, "abc def ghi jkl mno pqrs tuv wxyz");
    mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
    mTestHelper.insertNamePrefixes(db, nameCursor);
    nameCursor.close();
    contactCursor.close();
    final ArrayList<ContactNumber> result1 = getLooseMatchesFromDb("5276676484");
    assertFalse(result1.contains(jasonsmitt));
    final ArrayList<ContactNumber> result2 = getLooseMatchesFromDb("5276676488");
    assertFalse(result2.contains(jasonsmith));
    assertTrue(result2.contains(jasonsmitt));
    assertTrue(getLooseMatchesFromDb("22233344455566677778889999").contains(alphabet));
    assertTrue(getLooseMatchesFromDb("33344455566677778889999").contains(alphabet));
    assertTrue(getLooseMatchesFromDb("44455566677778889999").contains(alphabet));
    assertTrue(getLooseMatchesFromDb("55566677778889999").contains(alphabet));
    assertTrue(getLooseMatchesFromDb("66677778889999").contains(alphabet));
    assertTrue(getLooseMatchesFromDb("77778889999").contains(alphabet));
    assertTrue(getLooseMatchesFromDb("8889999").contains(alphabet));
    assertTrue(getLooseMatchesFromDb("9999").contains(alphabet));
    // Makes sure the phone number is correctly added.
    assertTrue(getLooseMatchesFromDb("12345678").contains(alphabet));
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactNumber(com.android.dialer.database.DialerDatabaseHelper.ContactNumber) MatrixCursor(android.database.MatrixCursor)

Example 7 with ContactNumber

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

the class SmartDialPrefixTest method testPutForNameTokens.

public void testPutForNameTokens() {
    final SQLiteDatabase db = mTestHelper.getWritableDatabase();
    final MatrixCursor nameCursor = constructNewNameCursor();
    final MatrixCursor contactCursor = constructNewContactCursor();
    final ContactNumber jasonfwilliams = constructNewContactWithDummyIds(contactCursor, nameCursor, "", 0, "Jason F. Williams");
    mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
    mTestHelper.insertNamePrefixes(db, nameCursor);
    nameCursor.close();
    contactCursor.close();
    assertTrue(getLooseMatchesFromDb("527").contains(jasonfwilliams));
    // 72 corresponds to sa = "Sarah Smith" but not "Jason Smitt" or "Mary Jane"
    assertTrue(getLooseMatchesFromDb("945").contains(jasonfwilliams));
    // 76 corresponds to sm = "Sarah Smith" and "Jason Smitt" but not "Mary Jane"
    assertFalse(getLooseMatchesFromDb("66").contains(jasonfwilliams));
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactNumber(com.android.dialer.database.DialerDatabaseHelper.ContactNumber) MatrixCursor(android.database.MatrixCursor)

Example 8 with ContactNumber

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

the class SmartDialPrefixTest method testAccentedCharacters.

public void testAccentedCharacters() {
    final SQLiteDatabase db = mTestHelper.getWritableDatabase();
    final MatrixCursor nameCursor = constructNewNameCursor();
    final MatrixCursor contactCursor = constructNewContactCursor();
    final ContactNumber reene = constructNewContactWithDummyIds(contactCursor, nameCursor, "0", 0, "Reenée");
    final ContactNumber bronte = constructNewContactWithDummyIds(contactCursor, nameCursor, "0", 1, "Brontë");
    mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
    mTestHelper.insertNamePrefixes(db, nameCursor);
    nameCursor.close();
    contactCursor.close();
    assertTrue(getLooseMatchesFromDb("733633").contains(reene));
    assertTrue(getLooseMatchesFromDb("276683").contains(bronte));
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactNumber(com.android.dialer.database.DialerDatabaseHelper.ContactNumber) MatrixCursor(android.database.MatrixCursor)

Example 9 with ContactNumber

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

the class SmartDialPrefixTest method testPutForInitialMatches.

public void testPutForInitialMatches() {
    final SQLiteDatabase db = mTestHelper.getWritableDatabase();
    final MatrixCursor nameCursor = constructNewNameCursor();
    final MatrixCursor contactCursor = constructNewContactCursor();
    final ContactNumber martinjuniorharry = constructNewContactWithDummyIds(contactCursor, nameCursor, "", 0, "Martin Jr Harry");
    mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
    mTestHelper.insertNamePrefixes(db, nameCursor);
    nameCursor.close();
    contactCursor.close();
    // 654 corresponds to mjh = "(M)artin (J)r (H)arry"
    assertTrue(getLooseMatchesFromDb("654").contains(martinjuniorharry));
    // The reverse (456) does not match (for now)
    assertFalse(getLooseMatchesFromDb("456").contains(martinjuniorharry));
    // 6542 corresponds to mjha = "(M)artin (J)r (Ha)rry"
    assertTrue(getLooseMatchesFromDb("6542").contains(martinjuniorharry));
    // 542 corresponds to jha = "Martin (J)r (Ha)rry"
    assertTrue(getLooseMatchesFromDb("542").contains(martinjuniorharry));
    // 642 corresponds to mha = "(M)artin Jr (Ha)rry"
    assertTrue(getLooseMatchesFromDb("642").contains(martinjuniorharry));
    // 6542779 (M)artin (J)r (Harry)
    assertTrue(getLooseMatchesFromDb("6542779").contains(martinjuniorharry));
    // 65742779 (M)artin (Jr) (Harry)
    assertTrue(getLooseMatchesFromDb("65742779").contains(martinjuniorharry));
    // 542779 Martin (J)r (Harry)
    assertTrue(getLooseMatchesFromDb("542779").contains(martinjuniorharry));
    // 547 doesn't match
    assertFalse(getLooseMatchesFromDb("547").contains(martinjuniorharry));
    // 655 doesn't match
    assertFalse(getLooseMatchesFromDb("655").contains(martinjuniorharry));
    // 653 doesn't match
    assertFalse(getLooseMatchesFromDb("653").contains(martinjuniorharry));
    // 6543 doesn't match
    assertFalse(getLooseMatchesFromDb("6543").contains(martinjuniorharry));
    // 7 actual rows, + 1 for the dummy number we added
    assertEquals(8, mTestHelper.countPrefixTableRows(db));
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactNumber(com.android.dialer.database.DialerDatabaseHelper.ContactNumber) MatrixCursor(android.database.MatrixCursor)

Example 10 with ContactNumber

use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber 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) {
        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;
}
Also used : ContactNumber(com.android.dialer.database.DialerDatabaseHelper.ContactNumber) DialerDatabaseHelper(com.android.dialer.database.DialerDatabaseHelper) MatrixCursor(android.database.MatrixCursor)

Aggregations

MatrixCursor (android.database.MatrixCursor)16 ContactNumber (com.android.dialer.database.DialerDatabaseHelper.ContactNumber)16 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)12 DialerDatabaseHelper (com.android.dialer.database.DialerDatabaseHelper)4