Allow call to phone numbers or voice mail numbers only

It allows to call to well-formatted phone numbers or carrier specific
phone numbers starting with star sign such as *20 so that user can make
a call directly in a conversation for voice mail SMSs.

Revert "Check whether dialable only"

This reverts commit dbc43316cf.

Reason for revert: a call icon is disappeared for well-formatted phone
                   number with parentheses, dash and etc.

Test: Check the call icon in conversations for phone numbers and voice
      mail numbers.

Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
Change-Id: I1b279f8a5372b00a5a0c572f9969731f1e633389
This commit is contained in:
Taesu Lee
2020-06-09 15:18:22 +09:00
parent f3ea99181b
commit 8b347325fa
2 changed files with 18 additions and 14 deletions

View File

@@ -700,7 +700,7 @@ public class ConversationData extends BindableData {
final ParticipantData participant = this.getOtherParticipant();
if (participant != null) {
final String phoneNumber = participant.getSendDestination();
if (!TextUtils.isEmpty(phoneNumber) && MmsSmsUtils.isDialable(phoneNumber)) {
if (!TextUtils.isEmpty(phoneNumber) && MmsSmsUtils.isPhoneNumber(phoneNumber)) {
return phoneNumber;
}
}

View File

@@ -100,25 +100,29 @@ public class MmsSmsUtils {
return match.matches();
}
/** True if c is ISO-LATIN characters 0-9, *, # , + */
public static final boolean isDialable(char c) {
return (c >= '0' && c <= '9') || c == '*' || c == '#' || c == '+';
}
/**
* This pattern is intended for searching for carrier specific phone numbers starting with star
* sign and digits such as the voice mail number.
* (e.g. *20 Chile Claro)
*/
private static final Pattern PHONE_NUMBER_STARTING_WITH_STAR_PATTERN =
Pattern.compile("\\*[0-9]+");
/**
* Returns true if the address is a dialable phone number.
* Returns true if the number is a Phone number
*
* @param address the input address to be tested
* @return true if address is a dialable phone number
* @param number the input number to be tested
* @return true if number is a Phone number
*/
public static boolean isDialable(final String address) {
if (TextUtils.isEmpty(address)) {
public static boolean isPhoneNumber(final String number) {
if (TextUtils.isEmpty(number)) {
return false;
}
for (int i = 0, count = address.length(); i < count; i++) {
if (!isDialable(address.charAt(i))) {
return false;
}
Matcher match = Patterns.PHONE.matcher(number);
if (!match.matches()) {
match = PHONE_NUMBER_STARTING_WITH_STAR_PATTERN.matcher(number);
return match.matches();
}
return true;
}