Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4afa21f9 authored by Michael Chan's avatar Michael Chan
Browse files

Prioritize geo:// links over tel:// in non-US regions DO NOT MERGE

Bug: 5727105

Change-Id: I30dc975e721b762cd920899732e69785c22c12ba
parent 7e070fca
Loading
Loading
Loading
Loading
+88 −76
Original line number Diff line number Diff line
@@ -1171,10 +1171,16 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
         * need to avoid creating overlapping spans.
         */
        String defaultPhoneRegion = System.getProperty("user.region", "US");
        boolean usRegion = "US".equalsIgnoreCase(defaultPhoneRegion);
        int phoneCount = 0;

        // For US region, use the phone lib to detect numbers
        // For non-US, skip the phone number detection if links are found already.
        if (usRegion || !linkifyFoundLinks) {
            PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
            CharSequence text = textView.getText();
        Iterable<PhoneNumberMatch> phoneIterable = phoneUtil.findNumbers(text, defaultPhoneRegion,
                PhoneNumberUtil.Leniency.POSSIBLE, Long.MAX_VALUE);
            Iterable<PhoneNumberMatch> phoneIterable = phoneUtil.findNumbers(text,
                    defaultPhoneRegion, PhoneNumberUtil.Leniency.POSSIBLE, Long.MAX_VALUE);

            /*
             * If the contents of the TextView are already Spannable (which will be the case if
@@ -1197,11 +1203,16 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
            /*
             * Insert spans for the numbers we found.  We generate "tel:" URIs.
             */
        int phoneCount = 0;
            for (PhoneNumberMatch match : phoneIterable) {
                int start = match.start();
                int end = match.end();

                // For non-US region, stop processing if the match doesn't
                // include the entire text. Should be in there at most once.
                if (!usRegion && (start != 0 || end != text.length())) {
                    break;
                }

                if (spanWillOverlap(spanText, existingSpans, start, end)) {
                    if (Log.isLoggable(TAG, Log.VERBOSE)) {
                        Log.v(TAG, "Not linkifying " + match.number().getNationalNumber() +
@@ -1220,8 +1231,8 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
                 * 6505551212x123   +1-650-555-1212;ext=123     (650) 555-1212 ext. 123
                 * +41446681800     +41-44-668-18-00            044 668 18 00
                 *
             * The conversion of NANP 7-digit numbers to RFC3966 is not compatible with our dialer
             * (which tries to dial 8 digits, and fails).  So that won't work.
                 * The conversion of NANP 7-digit numbers to RFC3966 is not compatible with our
                 * dialer (which tries to dial 8 digits, and fails).  So that won't work.
                 *
                 * The conversion of the Swiss number to NATIONAL format loses the country code,
                 * so that won't work.
@@ -1263,6 +1274,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
                    }
                }
            }
        }

        if (!linkifyFoundLinks && phoneCount == 0) {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {