jackpal/Android-Terminal-Emulator — pull request #276 by morae (2013-10-24 06:41:56+00:00)
Title: Clickable URLs in Android Terminal Emulator

This pull request contains code to implement clickable URLs in Android Terminal Emulator.

The general idea is that the `EmulatorView` class now contains a data structure called `mLinkLayer`, to store potential URLs at each row/column position on the current view. The data structure is cleared every time `updateSize` is called (so, when the size is actually changed, or when something a new character is drawn to the screen, etc), and lines of links are parsed one line at a time by a method called `createLinks`, which is called by the `onDraw` method after a line of text is drawn.

`createLinks` supports multi-line-wrap links, and works by getting the Transcript line at the row being drawn, checking if its wrap flag is set, and concatenating multiple rows together if necessary. The result is then turned into a `SpannableString`, and URLs are matched using the `Linkify` class.

The resulting URLs are then painted into `mLinkLayer` at the location of the text, such that they can be retrieved by touching the screen anywhere on the link. Retrieval is handled by the `getURLat` method, which converts screen coordinates into matrix coordinates, and then returns the link at that location, if any.

To handle touch events, the `onSingleTapUp` method of the Term class has been updated to check for links at the tap location. An `execURL` method has also been added to create an Intent that allows the URL to be opened by a web browser, etc.

Other changes:
* A couple of wrapper functions have been added to the `TranscriptScreen` class to facilitate getting data from `UnicodeTranscript` to `EmulatorView`

* For some reason, the lineWrap flag was not getting set for lines being typed by the user; instead, it was only being set for lines output by the terminal. I added a fix by forcing the current line's lineWrap flag to be set when the `mAboutToAutoWrap` flag becomes true. This may be a kludge; I am not sure if it has side-effects.

Issues:
* Links are not automatically underlined. As structured, this would be a challenge to implement. Several routines would have to be modified to allow the EmulatorView to signal the Renderer to change the text style. However, I don't think this is a necessary feature, especially since touch screens don't really have a concept of "hovering" over a link.

* Only web URLs are linkified, not other types of links such as email addresses. This would not be too difficult to implement - one would have to change the type of the data structure from URLSpan to a more general type of Span, and do some type checking to make sure the right Intent gets generated.