OSDN Git Service

TextView.append() honors autoLink attribute
authorSiyamed Sinir <siyamed@google.com>
Tue, 10 Nov 2015 23:34:29 +0000 (15:34 -0800)
committerSiyamed Sinir <siyamed@google.com>
Thu, 12 Nov 2015 23:25:31 +0000 (15:25 -0800)
The append() method now checks if autoLink is set and adds the
URLSpans to given text before appending to the existing text.

Fixes https://code.google.com/p/android/issues/detail?id=1244
Fixes https://code.google.com/p/android/issues/detail?id=191353

Bug: 1404366
Bug: 25222125
Change-Id: I47a8beec9799e4f92ce266ceed41a634b7f7cc96

core/java/android/widget/TextView.java

index c54a574..b5d994d 100644 (file)
@@ -3975,6 +3975,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
         }
 
         ((Editable) mText).append(text, start, end);
+
+        if (mAutoLinkMask != 0) {
+            boolean linksWereAdded = Linkify.addLinks((Spannable) mText, mAutoLinkMask);
+            // Do not change the movement method for text that support text selection as it
+            // would prevent an arbitrary cursor displacement.
+            if (linksWereAdded && mLinksClickable && !textCanBeSelected()) {
+                setMovementMethod(LinkMovementMethod.getInstance());
+            }
+        }
     }
 
     private void updateTextColors() {