From 5f2f820c81633beaddc32692b70e480737cdc5c1 Mon Sep 17 00:00:00 2001 From: Richard Ledley Date: Mon, 5 Feb 2018 14:55:47 +0000 Subject: [PATCH] Remove selection on nonselectable text (which would be there if a user tapped Linkified text) if a TextView loses focus. Test: bit FrameworksCoreTests:android.widget.TextViewActivityTest Bug: 67629726 Change-Id: Ifc3039f0c814c422b2d727f837ca9c88abc2ebe8 --- core/java/android/widget/Editor.java | 12 ++++ .../coretests/res/layout/activity_text_view.xml | 3 + .../src/android/widget/TextViewActivityTest.java | 67 +++++++++++++++++++--- 3 files changed, 74 insertions(+), 8 deletions(-) diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 7bb0db1cf910..ac2004db376c 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -1299,6 +1299,16 @@ public class Editor { if (mSelectionModifierCursorController != null) { mSelectionModifierCursorController.resetTouchOffsets(); } + + ensureNoSelectionIfNonSelectable(); + } + } + + private void ensureNoSelectionIfNonSelectable() { + // This could be the case if a TextLink has been tapped. + if (!mTextView.textCanBeSelected() && mTextView.hasSelection()) { + Selection.setSelection((Spannable) mTextView.getText(), + mTextView.length(), mTextView.length()); } } @@ -1382,6 +1392,8 @@ public class Editor { // Don't leave us in the middle of a batch edit. Same as in onFocusChanged ensureEndedBatchEdit(); + + ensureNoSelectionIfNonSelectable(); } } diff --git a/core/tests/coretests/res/layout/activity_text_view.xml b/core/tests/coretests/res/layout/activity_text_view.xml index dca16564aa11..d5be87dbae6b 100644 --- a/core/tests/coretests/res/layout/activity_text_view.xml +++ b/core/tests/coretests/res/layout/activity_text_view.xml @@ -24,6 +24,9 @@ android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="wrap_content" /> +