From 6da7e935f9a36ae2246a5e4ad713e495880b3dea Mon Sep 17 00:00:00 2001 From: Gilles Debunne Date: Tue, 7 Dec 2010 14:28:14 -0800 Subject: [PATCH] No NPE in Browser when pasting in WebTextView. Bug 3258790 Change-Id: I25d67ee85babb1bb3e4d05ea7b4e4d3756c60411 --- core/java/android/widget/TextView.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index f348976ed1d42..144cf9c433b78 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -7388,14 +7388,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } private boolean canSelectText() { - return textCanBeSelected() && mText.length() != 0; + return hasSelectionController() && mText.length() != 0; } private boolean textCanBeSelected() { // prepareCursorController() relies on this method. // If you change this condition, make sure prepareCursorController is called anywhere // the value of this condition might be changed. - return (mText instanceof Spannable && mMovement != null && mMovement.canSelectArbitrarily()); + return mText instanceof Spannable && mMovement != null && mMovement.canSelectArbitrarily(); } private boolean canCut() { @@ -7529,6 +7529,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } private void selectCurrentWord() { + if (!canSelectText()) { + return; + } + if (hasPasswordTransformationMethod()) { // selectCurrentWord is not available on a password field and would return an // arbitrary 10-charater selection around pressed position. Select all instead. @@ -7544,7 +7548,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener minOffset = getSelectionStart(); maxOffset = getSelectionEnd(); } else { - // selectionModifierCursorController is guaranteed to exist at that point SelectionModifierCursorController selectionController = getSelectionController(); minOffset = selectionController.getMinTouchOffset(); maxOffset = selectionController.getMaxTouchOffset(); @@ -7921,12 +7924,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener selectCurrentWord(); ActionMode.Callback actionModeCallback = new SelectionActionModeCallback(); - if (actionModeCallback != null) { - mSelectionActionMode = startActionMode(actionModeCallback); - return mSelectionActionMode != null; - } - - return false; + mSelectionActionMode = startActionMode(actionModeCallback); + return mSelectionActionMode != null; } /**