@Test public void queryNumberInAppContacts_matches_number() { String[] numbers = {"0744456740", "0744 456 740", "+40744456740", "+40 744 456740"}; for(String number : numbers) { Contact foundContact = Contact.queryNumberInAppContacts(repository, number); assertNotNull(foundContact); } String numberNotInDb = "0723456880"; assertNull(Contact.queryNumberInAppContacts(repository, numberNotInDb)); }
public static Contact queryNumberInAppContacts(Repository repository, String receivedPhoneNumber) { List<Contact> contacts = repository.getAllContacts(); PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); for (Contact contact : contacts) { String dbNumPhone = contact.getPhoneNumber(); PhoneNumberUtil.MatchType matchType = phoneUtil.isNumberMatch(receivedPhoneNumber, dbNumPhone); if (matchType != PhoneNumberUtil.MatchType.NO_MATCH && matchType != PhoneNumberUtil.MatchType.NOT_A_NUMBER) return contact; } return null; }
Contact implements Comparable<Contact>, Parcelable { public static Contact queryNumberInAppContacts(Repository repository, String receivedPhoneNumber) { List<Contact> contacts = repository.getAllContacts(); PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); for (Contact contact : contacts) { String dbNumPhone = contact.getPhoneNumber(); PhoneNumberUtil.MatchType matchType = phoneUtil.isNumberMatch(receivedPhoneNumber, dbNumPhone); if (matchType != PhoneNumberUtil.MatchType.NO_MATCH && matchType != PhoneNumberUtil.MatchType.NOT_A_NUMBER) return contact; } return null; } }
Contact implements Comparable<Contact>, Parcelable { public static Contact queryNumberInAppContacts(Repository repository, String receivedPhoneNumber) { List<Contact> contacts = repository.getAllContacts(); PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); for (Contact contact : contacts) { String dbNumPhone = contact.getPhoneNumber(); PhoneNumberUtil.MatchType matchType = phoneUtil.isNumberMatch(receivedPhoneNumber, dbNumPhone); if (matchType != PhoneNumberUtil.MatchType.NO_MATCH && matchType != PhoneNumberUtil.MatchType.NOT_A_NUMBER) return contact; } return null; } Contact();  Contact(Long id, String phoneNumber, String contactName, String photoUriStr, Integer phoneTypeCode); protected  Contact(Parcel in); }
Contact implements Comparable<Contact>, Parcelable { public static Contact queryNumberInAppContacts(Repository repository, String receivedPhoneNumber) { List<Contact> contacts = repository.getAllContacts(); PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); for (Contact contact : contacts) { String dbNumPhone = contact.getPhoneNumber(); PhoneNumberUtil.MatchType matchType = phoneUtil.isNumberMatch(receivedPhoneNumber, dbNumPhone); if (matchType != PhoneNumberUtil.MatchType.NO_MATCH && matchType != PhoneNumberUtil.MatchType.NOT_A_NUMBER) return contact; } return null; } Contact();  Contact(Long id, String phoneNumber, String contactName, String photoUriStr, Integer phoneTypeCode); protected  Contact(Parcel in); static Contact queryNumberInAppContacts(Repository repository, String receivedPhoneNumber); void update(Repository repository); void save(Repository repository); void delete(Repository repository, Context context); @Nullable static Contact queryNumberInPhoneContacts(final String number, @NonNull ContentResolver resolver); boolean isPrivateNumber(); void setIsPrivateNumber(); int compareTo(@NonNull Contact numberToCompare); String getPhoneNumber(); void setPhoneNumber(String phoneNumber); int getPhoneTypeCode(); String getPhoneTypeName(); void setPhoneType(String phoneType); void setPhoneType(int phoneTypeCode); String getContactName(); void setContactName(String contactName); Uri getPhotoUri(); void setPhotoUri(String photoUriStr); void setPhotoUri(Uri photoUri); Long getId(); void setId(Long id); Integer getColor(); void setColor(Integer color); @Override boolean equals(Object o); @Override int hashCode(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); }
Contact implements Comparable<Contact>, Parcelable { public static Contact queryNumberInAppContacts(Repository repository, String receivedPhoneNumber) { List<Contact> contacts = repository.getAllContacts(); PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); for (Contact contact : contacts) { String dbNumPhone = contact.getPhoneNumber(); PhoneNumberUtil.MatchType matchType = phoneUtil.isNumberMatch(receivedPhoneNumber, dbNumPhone); if (matchType != PhoneNumberUtil.MatchType.NO_MATCH && matchType != PhoneNumberUtil.MatchType.NOT_A_NUMBER) return contact; } return null; } Contact();  Contact(Long id, String phoneNumber, String contactName, String photoUriStr, Integer phoneTypeCode); protected  Contact(Parcel in); static Contact queryNumberInAppContacts(Repository repository, String receivedPhoneNumber); void update(Repository repository); void save(Repository repository); void delete(Repository repository, Context context); @Nullable static Contact queryNumberInPhoneContacts(final String number, @NonNull ContentResolver resolver); boolean isPrivateNumber(); void setIsPrivateNumber(); int compareTo(@NonNull Contact numberToCompare); String getPhoneNumber(); void setPhoneNumber(String phoneNumber); int getPhoneTypeCode(); String getPhoneTypeName(); void setPhoneType(String phoneType); void setPhoneType(int phoneTypeCode); String getContactName(); void setContactName(String contactName); Uri getPhotoUri(); void setPhotoUri(String photoUriStr); void setPhotoUri(Uri photoUri); Long getId(); void setId(Long id); Integer getColor(); void setColor(Integer color); @Override boolean equals(Object o); @Override int hashCode(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); static final Creator<Contact> CREATOR; }