Heh…. this morning I posted that I’d put highlighting aside for a while, and immediately a Market comment popped up requesting highlighting…
I figured it ight be a good idea to explain why highlighting is difficult and what I’ve done so far.
The problem isn’t so much in highlighting, but in finding a way that allows reliable text selection over all versions of Android that we support. Android 2.3 added basic support, and ICS added more comprehensive support for selecting text, but in both these cases you get a popup with copy / paste operations.
What I would want for PageTurner is that when the user long-presses a word, 2 markers appear at the boundaries of that word. The user can then drag those markers to select different portions of the text. Finally, either after a short delay or by touching the selection, a dialog pops up that offers options like:
- Look up on Wikipedia
- Look up in dictionary
- Copy to clipboard
- Share text
Some of these options are already supported by long-pressing a single word, but I’d want them to be available for all selected text.
I have been hunting around StackOverflow and found some interesting posts about using an EditText instead of a TextView and configuring it to be non-editable. This allows text selection. Unfortunately, this method is incompatible with using a LinkMovementMethod, which means that clicking links no longer works.
The TextView on Android 4 has a textSelectable() property, but this always pops up a dialog with default text-edit actions, plus it would make this feature only available for a part of the users.
So… my conclusion so far is that if I want reliable text selection, I’ll have to code it myself including the code to draw and move the markers. This seems to be a strategy followed by a lot of apps, judging by the variation in selection markers I have seen.
This would require a couple of days of focused coding, something I simply don’t have the time for right now… So yes, selection is absolutely still planned, but it might take some time to get here.
Update, Dec 5: it’s a couple of months later, and I have made some interesting progress on this issue.
- Instead of using LinkMovementMethod I can check if there is a ClickableSpan in the part of the text that has just been clicked and then activate that
- I figured out how to customize the Android 4+ popup when selecting text.
This means that if I choose to only support text selection on newer platforms, I’m all set. I still want to give the 2.3 version a go though, since that would mean text-selection becomes available to a lot more users.