Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Why does autolink ignore the root path of a URL?

I have a TextView with android:autoLink="web". The text contains some URLs.

For example:
http://example.com/

But when rendered, it links the name scheme and domain name but ignores the root path.

Example renders as:
http://example.com/

Why does it do this and how do I make it autolink fully qualified URLs properly?

Edit: Also, URLs followed by a fullstop or comma:
http://example.com/,

Are being rendered as:
http://example.com/,

Note that StackExchange autolinks correctly (look at the source for this question).

Edit: Sam, this is the code:

        <TextView android:id="@+id/open_source"
            android:text="@string/open_source"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#FFF"
            android:paddingBottom="10dp"
            android:autoLink="web" />

Some text:

<string name="open_source">Three examples, fully qualified http://isokeys.sourceforge.net/ missing root path http://isokeys.sourceforge.net and followed with a fullstop http://isokeys.sourceforge.net/.</string>

Should render as:
Three examples, fully qualified http://isokeys.sourceforge.net/ missing root path http://isokeys.sourceforge.net and followed with a fullstop http://isokeys.sourceforge.net/.

Is rendered as:
Three examples, fully qualified http://isokeys.sourceforge.net/ missing root path http://isokeys.sourceforge.net and followed with a fullstop http://isokeys.sourceforge.net/.

like image 367
James Haigh Avatar asked May 10 '12 18:05

James Haigh


1 Answers

I would just point out two things:
1) When you set autoLink to equal "web", in the background Android uses tools from the android.text.util package to look for actionable items contained in the text of your View object. By default, android.text.util.Linkify has its own opinion about what are and are not valid URLs (based on regex matching). If you really wanted to use URLs with a trailing slash, you or comma appended at the end, you could implement your own MatchFilter with its own regex expressions. Documentation can be found here on the Android developers site
2) The trailing slash doesn't really have any meaning in a standard URL because it is used to indicated that position in a hierarchy of resources, but if you have nothing following the slash, then you aren't traversing into another level of the hierarchy. Appending a comma or period shouldn't be valid URL syntax since that doesn't assist in location a resource among your hierarchy, so I assume Android's regex for matching ignores it to prevent you from getting a MalformedURLException when it tries to act on the link

like image 150
David C. Sainte-Claire Avatar answered Sep 27 '22 18:09

David C. Sainte-Claire