Merge "Revert "TextView setText/append methods set movement method"" into nyc-dev

This commit is contained in:
Siyamed Sinir
2016-03-29 23:59:13 +00:00
committed by Android (Google) Code Review
2 changed files with 28 additions and 57 deletions

View File

@@ -3411,17 +3411,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
/** /**
* Sets whether the movement method will automatically be set to {@link LinkMovementMethod} * Sets whether the movement method will automatically be set to
* after {@link #setText} or {@link #append} is called. The movement method is set if one of the * {@link LinkMovementMethod} if {@link #setAutoLinkMask} has been
* following is true: * set to nonzero and links are detected in {@link #setText}.
* <ul> * The default is true.
* <li>{@link #setAutoLinkMask} has been set to nonzero and links are detected in
* {@link #setText} or {@link #append}.
* <li>The input for {@link #setText} or {@link #append} contains a {@link ClickableSpan}.
* </ul>
*
* <p>This function does not have an immediate effect, movement method will be set only after a
* call to {@link #setText} or {@link #append}. The default is true.</p>
* *
* @attr ref android.R.styleable#TextView_linksClickable * @attr ref android.R.styleable#TextView_linksClickable
*/ */
@@ -3431,14 +3424,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} }
/** /**
* Returns whether the movement method will automatically be set to {@link LinkMovementMethod} * Returns whether the movement method will automatically be set to
* after {@link #setText} or {@link #append} is called. * {@link LinkMovementMethod} if {@link #setAutoLinkMask} has been
* * set to nonzero and links are detected in {@link #setText}.
* See {@link #setLinksClickable} for details. * The default is true.
*
* <p>The default is true.</p>
*
* @see #setLinksClickable
* *
* @attr ref android.R.styleable#TextView_linksClickable * @attr ref android.R.styleable#TextView_linksClickable
*/ */
@@ -4032,19 +4021,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
((Editable) mText).append(text, start, end); ((Editable) mText).append(text, start, end);
boolean hasClickableSpans = false;
if (mAutoLinkMask != 0) { if (mAutoLinkMask != 0) {
hasClickableSpans = Linkify.addLinks((Spannable) mText, mAutoLinkMask); boolean linksWereAdded = Linkify.addLinks((Spannable) mText, mAutoLinkMask);
} else if (mLinksClickable && text instanceof Spanned) { // Do not change the movement method for text that support text selection as it
ClickableSpan[] clickableSpans = // would prevent an arbitrary cursor displacement.
((Spanned) text).getSpans(0, text.length(), ClickableSpan.class); if (linksWereAdded && mLinksClickable && !textCanBeSelected()) {
hasClickableSpans = clickableSpans != null && clickableSpans.length > 0; setMovementMethod(LinkMovementMethod.getInstance());
} }
// Do not change the movement method for text that supports text selection as it
// would prevent an arbitrary cursor displacement.
if (hasClickableSpans && mLinksClickable && !textCanBeSelected()) {
setMovementMethod(LinkMovementMethod.getInstance());
} }
} }
@@ -4397,7 +4380,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
text = TextUtils.stringOrSpannedString(text); text = TextUtils.stringOrSpannedString(text);
} }
boolean hasClickableSpans = false;
if (mAutoLinkMask != 0) { if (mAutoLinkMask != 0) {
Spannable s2; Spannable s2;
@@ -4407,32 +4389,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
s2 = mSpannableFactory.newSpannable(text); s2 = mSpannableFactory.newSpannable(text);
} }
hasClickableSpans = Linkify.addLinks(s2, mAutoLinkMask); if (Linkify.addLinks(s2, mAutoLinkMask)) {
if (hasClickableSpans) {
text = s2; text = s2;
} type = (type == BufferType.EDITABLE) ? BufferType.EDITABLE : BufferType.SPANNABLE;
} else if (mLinksClickable && text instanceof Spanned) {
ClickableSpan[] clickableSpans =
((Spanned) text).getSpans(0, text.length(), ClickableSpan.class);
hasClickableSpans = clickableSpans != null && clickableSpans.length > 0;
if (hasClickableSpans && !(text instanceof Spannable)) {
text = mSpannableFactory.newSpannable(text);
}
}
if (hasClickableSpans) { /*
type = (type == BufferType.EDITABLE) ? BufferType.EDITABLE : BufferType.SPANNABLE; * We must go ahead and set the text before changing the
/* * movement method, because setMovementMethod() may call
* We must go ahead and set the text before changing the * setText() again to try to upgrade the buffer type.
* movement method, because setMovementMethod() may call */
* setText() again to try to upgrade the buffer type. mText = text;
*/
mText = text;
// Do not change the movement method for text that supports text selection as it // Do not change the movement method for text that support text selection as it
// would prevent an arbitrary cursor displacement. // would prevent an arbitrary cursor displacement.
if (mLinksClickable && !textCanBeSelected()) { if (mLinksClickable && !textCanBeSelected()) {
setMovementMethod(LinkMovementMethod.getInstance()); setMovementMethod(LinkMovementMethod.getInstance());
}
} }
} }

View File

@@ -4384,8 +4384,7 @@ i
<attr name="autoLink" /> <attr name="autoLink" />
<!-- If set to false, keeps the movement method from being set <!-- If set to false, keeps the movement method from being set
to the link movement method even if autoLink causes links to the link movement method even if autoLink causes links
to be found or the input text contains a to be found. -->
{@link android.text.style.ClickableSpan ClickableSpan}. -->
<attr name="linksClickable" format="boolean" /> <attr name="linksClickable" format="boolean" />
<!-- If set, specifies that this TextView has a numeric input method. <!-- If set, specifies that this TextView has a numeric input method.
The default is false. The default is false.