Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Clickable URLs in Android Terminal Emulator #276

Merged
merged 15 commits into from Nov 17, 2013
Merged

Clickable URLs in Android Terminal Emulator #276

merged 15 commits into from Nov 17, 2013

Conversation

callistabee
Copy link
Contributor

(c) 2013 Kendall Stewart

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.

@jackpal jackpal merged commit 0ee62cc into jackpal:master Nov 17, 2013
@jackpal
Copy link
Owner

jackpal commented Nov 17, 2013

Very nice! Thanks!

@chriscroome
Copy link

Thanks for adding this feature, it's greatly appreciated.

I've noticed that it appears to only support http:// URLs and not https:// ones? Would it be possible to add HTTPS support to this?

@callistabee
Copy link
Contributor Author

Hi Chris,

That's odd. I just tested it with an https:// URL and it worked for me.
It's using android.text.util.Linkify for the pattern matching, so https:// should be covered.

Can you describe the conditions that led to the failure in a little more detail?

Thanks,
Kendall

@chriscroome
Copy link

Sorry, yes it it working fine, I was simply holding my finger over the https:// URL for too long and then getting the select text options.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants