use of in.uncod.android.bypass.style.TouchableUrlSpan in project plaid by nickbutcher.
the class FabOverlapTextView method onTouchEvent.
/**
* This is why you don't implement your own TextView kids; you have to handle everything!
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!(text instanceof Spanned))
return super.onTouchEvent(event);
Spannable spannedText = (Spannable) text;
boolean handled = false;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
pressedSpan = getPressedSpan(spannedText, event);
if (pressedSpan != null) {
pressedSpan.setPressed(true);
Selection.setSelection(spannedText, spannedText.getSpanStart(pressedSpan), spannedText.getSpanEnd(pressedSpan));
handled = true;
postInvalidateOnAnimation();
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
TouchableUrlSpan touchedSpan = getPressedSpan(spannedText, event);
if (pressedSpan != null && touchedSpan != pressedSpan) {
pressedSpan.setPressed(false);
pressedSpan = null;
Selection.removeSelection(spannedText);
postInvalidateOnAnimation();
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (pressedSpan != null) {
pressedSpan.setPressed(false);
pressedSpan.onClick(this);
handled = true;
postInvalidateOnAnimation();
}
pressedSpan = null;
Selection.removeSelection(spannedText);
} else {
if (pressedSpan != null) {
pressedSpan.setPressed(false);
handled = true;
postInvalidateOnAnimation();
}
pressedSpan = null;
Selection.removeSelection(spannedText);
}
return handled;
}
use of in.uncod.android.bypass.style.TouchableUrlSpan in project plaid by nickbutcher.
the class DribbbleUtils method parseDribbbleHtml.
/**
* An extension to {@link HtmlUtils#parseHtml(String, ColorStateList, int)} which adds Dribbble
* specific behaviour.
*/
public static Spanned parseDribbbleHtml(String input, ColorStateList linkTextColor, @ColorInt int linkHighlightColor) {
SpannableStringBuilder ssb = HtmlUtils.parseHtml(input, linkTextColor, linkHighlightColor);
TouchableUrlSpan[] urlSpans = ssb.getSpans(0, ssb.length(), TouchableUrlSpan.class);
for (TouchableUrlSpan urlSpan : urlSpans) {
int start = ssb.getSpanStart(urlSpan);
if (ssb.subSequence(start, start + 1).toString().equals("@")) {
int end = ssb.getSpanEnd(urlSpan);
ssb.removeSpan(urlSpan);
HttpUrl url = HttpUrl.parse(urlSpan.getURL());
long playerId = -1l;
String playerUsername = null;
try {
playerId = Long.parseLong(url.pathSegments().get(0));
} catch (NumberFormatException nfe) {
playerUsername = url.pathSegments().get(0);
}
ssb.setSpan(new PlayerSpan(urlSpan.getURL(), ssb.subSequence(start + 1, end).toString(), playerId, playerUsername, linkTextColor, linkHighlightColor), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return ssb;
}
use of in.uncod.android.bypass.style.TouchableUrlSpan in project plaid by nickbutcher.
the class HtmlUtils method linkifyPlainLinks.
private static SpannableStringBuilder linkifyPlainLinks(CharSequence input, ColorStateList linkTextColor, @ColorInt int linkHighlightColor) {
// copy of input
final SpannableString plainLinks = new SpannableString(input);
// Linkify doesn't seem to work as expected on M+
// TODO: figure out why
//Linkify.addLinks(plainLinks, Linkify.WEB_URLS);
final URLSpan[] urlSpans = plainLinks.getSpans(0, plainLinks.length(), URLSpan.class);
// add any plain links to the output
final SpannableStringBuilder ssb = new SpannableStringBuilder(input);
for (URLSpan urlSpan : urlSpans) {
ssb.removeSpan(urlSpan);
ssb.setSpan(new TouchableUrlSpan(urlSpan.getURL(), linkTextColor, linkHighlightColor), plainLinks.getSpanStart(urlSpan), plainLinks.getSpanEnd(urlSpan), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return ssb;
}
use of in.uncod.android.bypass.style.TouchableUrlSpan in project sbt-android by scala-android.
the class HtmlUtils method parseHtml.
/**
* Parse the given input using {@link TouchableUrlSpan}s
* rather than vanilla {@link android.text.style.URLSpan}s so that they respond to touch.
*
* @param input
* @param linkTextColor
* @param linkHighlightColor
* @return
*/
public static Spanned parseHtml(String input, ColorStateList linkTextColor, int linkHighlightColor) {
SpannableStringBuilder spanned = (SpannableStringBuilder) Html.fromHtml(input);
// strip any trailing newlines
while (spanned.charAt(spanned.length() - 1) == '\n') {
spanned = spanned.delete(spanned.length() - 1, spanned.length());
}
URLSpan[] urlSpans = spanned.getSpans(0, spanned.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
int start = spanned.getSpanStart(urlSpan);
int end = spanned.getSpanEnd(urlSpan);
spanned.removeSpan(urlSpan);
// spanned.subSequence(start, start + 1) == "@" TODO send to our own user activity...
// when i've written it
spanned.setSpan(new TouchableUrlSpan(urlSpan.getURL(), linkTextColor, linkHighlightColor), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return spanned;
}
use of in.uncod.android.bypass.style.TouchableUrlSpan in project sbt-android by scala-android.
the class LinkTouchMovementMethod method getPressedSpan.
private TouchableUrlSpan getPressedSpan(TextView textView, Spannable spannable, MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= textView.getTotalPaddingLeft();
y -= textView.getTotalPaddingTop();
x += textView.getScrollX();
y += textView.getScrollY();
Layout layout = textView.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
TouchableUrlSpan[] link = spannable.getSpans(off, off, TouchableUrlSpan.class);
TouchableUrlSpan touchedSpan = null;
if (link.length > 0) {
touchedSpan = link[0];
}
return touchedSpan;
}
Aggregations