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) {
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;
}
use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by MoKee.
the class SmartDialPrefixTest method testPutNumbersNonNANP.
// Tests special case handling for non-NANP numbers
public void testPutNumbersNonNANP() {
SmartDialPrefix.setUserInNanpRegion(false);
final SQLiteDatabase db = mTestHelper.getWritableDatabase();
final MatrixCursor nameCursor = constructNewNameCursor();
final MatrixCursor contactCursor = constructNewContactCursor();
final ContactNumber contactno0 = constructNewContactWithDummyIds(contactCursor, nameCursor, "(415)-123-4567", 0, "Jason");
final ContactNumber contactno1 = constructNewContactWithDummyIds(contactCursor, nameCursor, "1 510-284-9170", 1, "Mike");
mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
mTestHelper.insertNamePrefixes(db, nameCursor);
nameCursor.close();
contactCursor.close();
assertTrue(getLooseMatchesFromDb("4151234567").contains(contactno0));
assertFalse(getLooseMatchesFromDb("1234567").contains(contactno0));
assertTrue(getLooseMatchesFromDb("15102849170").contains(contactno1));
assertFalse(getLooseMatchesFromDb("5102849170").contains(contactno1));
assertFalse(getLooseMatchesFromDb("2849170").contains(contactno1));
}
use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by MoKee.
the class SmartDialPrefixTest method testPutNumbersCountryCode.
public void testPutNumbersCountryCode() {
final SQLiteDatabase db = mTestHelper.getWritableDatabase();
final MatrixCursor nameCursor = constructNewNameCursor();
final MatrixCursor contactCursor = constructNewContactCursor();
final ContactNumber contactno1 = constructNewContactWithDummyIds(contactCursor, nameCursor, "+13684976334", 0, "James");
final ContactNumber contactno2 = constructNewContactWithDummyIds(contactCursor, nameCursor, "+65 9177-6930", 1, "Jason");
final ContactNumber contactno3 = constructNewContactWithDummyIds(contactCursor, nameCursor, "+85212345678", 2, "Mike");
final ContactNumber contactno4 = constructNewContactWithDummyIds(contactCursor, nameCursor, "+85112345678", 3, "Invalid");
final ContactNumber contactno5 = constructNewContactWithDummyIds(contactCursor, nameCursor, "+852", 4, "Invalid");
mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
mTestHelper.insertNamePrefixes(db, nameCursor);
nameCursor.close();
contactCursor.close();
assertTrue(getLooseMatchesFromDb("1368").contains(contactno1));
assertTrue(getLooseMatchesFromDb("368497").contains(contactno1));
assertFalse(getLooseMatchesFromDb("2368497").contains(contactno1));
assertTrue(getLooseMatchesFromDb("6591776930").contains(contactno2));
assertTrue(getLooseMatchesFromDb("91776930").contains(contactno2));
assertFalse(getLooseMatchesFromDb("591776930").contains(contactno2));
assertTrue(getLooseMatchesFromDb("85212345678").contains(contactno3));
assertTrue(getLooseMatchesFromDb("12345678").contains(contactno3));
assertFalse(getLooseMatchesFromDb("5212345678").contains(contactno3));
assertTrue(getLooseMatchesFromDb("85112345678").contains(contactno4));
assertFalse(getLooseMatchesFromDb("12345678").contains(contactno4));
}
use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by MoKee.
the class SmartDialPrefixTest method testPutForInitialMatchesForLongTokenNames.
public void testPutForInitialMatchesForLongTokenNames() {
final SQLiteDatabase db = mTestHelper.getWritableDatabase();
final MatrixCursor nameCursor = constructNewNameCursor();
final MatrixCursor contactCursor = constructNewContactCursor();
final ContactNumber alphabet = constructNewContactWithDummyIds(contactCursor, nameCursor, "12345678", 0, "abc def ghi jkl mno pqrs tuv wxyz");
mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
mTestHelper.insertNamePrefixes(db, nameCursor);
nameCursor.close();
contactCursor.close();
// Makes sure only only the first two and last two token are considered for initials.
// The cut-off constant can be set in SmartDialPrefix.java
assertTrue(getLooseMatchesFromDb("2389999").contains(alphabet));
assertTrue(getLooseMatchesFromDb("239999").contains(alphabet));
assertTrue(getLooseMatchesFromDb("23888").contains(alphabet));
assertTrue(getLooseMatchesFromDb("2333").contains(alphabet));
assertTrue(getLooseMatchesFromDb("289999").contains(alphabet));
assertTrue(getLooseMatchesFromDb("2888").contains(alphabet));
assertTrue(getLooseMatchesFromDb("29999").contains(alphabet));
assertTrue(getLooseMatchesFromDb("3888").contains(alphabet));
assertTrue(getLooseMatchesFromDb("39999").contains(alphabet));
assertTrue(getLooseMatchesFromDb("389999").contains(alphabet));
assertTrue(getLooseMatchesFromDb("89999").contains(alphabet));
}
use of com.android.dialer.database.DialerDatabaseHelper.ContactNumber in project android_packages_apps_Dialer by MoKee.
the class SmartDialPrefixTest method testPutForPartialName.
public void testPutForPartialName() {
final SQLiteDatabase db = mTestHelper.getWritableDatabase();
final MatrixCursor nameCursor = constructNewNameCursor();
final MatrixCursor contactCursor = constructNewContactCursor();
final ContactNumber maryjane = constructNewContactWithDummyIds(contactCursor, nameCursor, "", 0, "Mary Jane");
final ContactNumber sarahsmith = constructNewContactWithDummyIds(contactCursor, nameCursor, "", 1, "Sarah Smith");
final ContactNumber jasonsmitt = constructNewContactWithDummyIds(contactCursor, nameCursor, "", 2, "Jason Smitt");
mTestHelper.insertUpdatedContactsAndNumberPrefix(db, contactCursor, Long.valueOf(0));
mTestHelper.insertNamePrefixes(db, nameCursor);
nameCursor.close();
contactCursor.close();
final ArrayList<ContactNumber> result1 = getLooseMatchesFromDb("6279");
assertTrue(result1.contains(maryjane));
assertFalse(result1.contains(jasonsmitt));
// 72 corresponds to sa = "Sarah Smith" but not "Jason Smitt" or "Mary Jane"
final ArrayList<ContactNumber> result2 = getLooseMatchesFromDb("72");
assertFalse(result2.contains(maryjane));
assertTrue(result2.contains(sarahsmith));
assertFalse(result2.contains(jasonsmitt));
// 76 corresponds to sm = "Sarah Smith" and "Jason Smitt" but not "Mary Jane"
final ArrayList<ContactNumber> result3 = getLooseMatchesFromDb("76");
assertFalse(result3.contains(maryjane));
assertTrue(result3.contains(sarahsmith));
assertTrue(result3.contains(jasonsmitt));
}
Aggregations