Merge "Don't use highlighting in non-selectable text. Also fixes potential discrepancy in indexes for Linkified entities." into pi-dev
am: 847446d7f8
Change-Id: I1ad63dda26b397c26fa05520103e504bcf6f8127
This commit is contained in:
@@ -505,7 +505,7 @@ public final class TextLinks implements Parcelable {
|
||||
public void onClick(View widget) {
|
||||
if (widget instanceof TextView) {
|
||||
final TextView textView = (TextView) widget;
|
||||
textView.requestActionMode(mTextLink);
|
||||
textView.requestActionMode(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,6 @@ import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.textclassifier.TextClassification;
|
||||
import android.view.textclassifier.TextClassificationManager;
|
||||
import android.view.textclassifier.TextLinks;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.TextView.Drawables;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
@@ -2118,13 +2117,12 @@ public class Editor {
|
||||
getSelectionActionModeHelper().startSelectionActionModeAsync(adjustSelection);
|
||||
}
|
||||
|
||||
void startLinkActionModeAsync(TextLinks.TextLink link) {
|
||||
Preconditions.checkNotNull(link);
|
||||
void startLinkActionModeAsync(int start, int end) {
|
||||
if (!(mTextView.getText() instanceof Spannable)) {
|
||||
return;
|
||||
}
|
||||
stopTextActionMode();
|
||||
getSelectionActionModeHelper().startLinkActionModeAsync(link);
|
||||
getSelectionActionModeHelper().startLinkActionModeAsync(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,6 @@ import android.view.textclassifier.TextClassification;
|
||||
import android.view.textclassifier.TextClassificationConstants;
|
||||
import android.view.textclassifier.TextClassificationManager;
|
||||
import android.view.textclassifier.TextClassifier;
|
||||
import android.view.textclassifier.TextLinks;
|
||||
import android.view.textclassifier.TextSelection;
|
||||
import android.view.textclassifier.logging.Logger;
|
||||
import android.view.textclassifier.logging.SelectionEvent;
|
||||
@@ -133,17 +132,13 @@ public final class SelectionActionModeHelper {
|
||||
/**
|
||||
* Starts Link ActionMode.
|
||||
*/
|
||||
public void startLinkActionModeAsync(TextLinks.TextLink textLink) {
|
||||
mSelectionTracker.onOriginalSelection(
|
||||
getText(mTextView),
|
||||
mTextView.getSelectionStart(),
|
||||
mTextView.getSelectionEnd(),
|
||||
true /*isLink*/);
|
||||
public void startLinkActionModeAsync(int start, int end) {
|
||||
mSelectionTracker.onOriginalSelection(getText(mTextView), start, end, true /*isLink*/);
|
||||
cancelAsyncTask();
|
||||
if (skipTextClassification()) {
|
||||
startLinkActionMode(null);
|
||||
} else {
|
||||
resetTextClassificationHelper(textLink.getStart(), textLink.getEnd());
|
||||
resetTextClassificationHelper(start, end);
|
||||
mTextClassificationAsyncTask = new TextClassificationAsyncTask(
|
||||
mTextView,
|
||||
mTextClassificationHelper.getTimeoutDuration(),
|
||||
@@ -244,15 +239,15 @@ public final class SelectionActionModeHelper {
|
||||
@Editor.TextActionMode int actionMode, @Nullable SelectionResult result) {
|
||||
final CharSequence text = getText(mTextView);
|
||||
if (result != null && text instanceof Spannable
|
||||
&& (mTextView.isTextSelectable()
|
||||
|| mTextView.isTextEditable()
|
||||
|| actionMode == Editor.TextActionMode.TEXT_LINK)) {
|
||||
&& (mTextView.isTextSelectable() || mTextView.isTextEditable())) {
|
||||
// Do not change the selection if TextClassifier should be dark launched.
|
||||
if (!mTextClassificationSettings.isModelDarkLaunchEnabled()) {
|
||||
Selection.setSelection((Spannable) text, result.mStart, result.mEnd);
|
||||
mTextView.invalidate();
|
||||
}
|
||||
mTextClassification = result.mClassification;
|
||||
} else if (actionMode == Editor.TextActionMode.TEXT_LINK) {
|
||||
mTextClassification = result.mClassification;
|
||||
} else {
|
||||
mTextClassification = null;
|
||||
}
|
||||
|
||||
@@ -11499,12 +11499,27 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
* @return Whether or not we're attempting to start the action mode.
|
||||
* @hide
|
||||
*/
|
||||
public boolean requestActionMode(@NonNull TextLinks.TextLink link) {
|
||||
public boolean requestActionMode(@NonNull TextLinks.TextLinkSpan clickedSpan) {
|
||||
Preconditions.checkNotNull(clickedSpan);
|
||||
final TextLinks.TextLink link = clickedSpan.getTextLink();
|
||||
Preconditions.checkNotNull(link);
|
||||
createEditorIfNeeded();
|
||||
mEditor.startLinkActionModeAsync(link);
|
||||
|
||||
if (!(mText instanceof Spanned)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final int start = ((Spanned) mText).getSpanStart(clickedSpan);
|
||||
final int end = ((Spanned) mText).getSpanEnd(clickedSpan);
|
||||
|
||||
if (start < 0 || end < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mEditor.startLinkActionModeAsync(start, end);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user