summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Keisuke Kuroyanagi <ksk@google.com> 2016-04-07 05:22:35 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-04-07 05:22:36 +0000
commit03f1e026996a7665aefcda947ed97faae009735e (patch)
treeca4f9c5bdb54b5a8fbd06269eae80171c0f8e8fd
parent64f2ffaa7ef237a6d8181c03bb0a3bdbbc879792 (diff)
parentc14e1270cff7f12614af49b7f3a94299f4064438 (diff)
Merge "Invalidate HandleView when handle position may have to be changed." into nyc-dev
-rw-r--r--core/java/android/widget/Editor.java52
-rw-r--r--core/java/android/widget/TextView.java6
2 files changed, 49 insertions, 9 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 7055f783c584..2c3e563addea 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -1778,6 +1778,18 @@ public class Editor {
if (translate) canvas.translate(0, -cursorOffsetVertical);
}
+ void invalidateHandlesAndActionMode() {
+ if (mSelectionModifierCursorController != null) {
+ mSelectionModifierCursorController.invalidateHandles();
+ }
+ if (mInsertionPointCursorController != null) {
+ mInsertionPointCursorController.invalidateHandle();
+ }
+ if (mTextActionMode != null) {
+ mTextActionMode.invalidate();
+ }
+ }
+
/**
* Invalidates all the sub-display lists that overlap the specified character range
*/
@@ -4104,6 +4116,14 @@ public class Editor {
setMeasuredDimension(getPreferredWidth(), getPreferredHeight());
}
+ @Override
+ public void invalidate() {
+ super.invalidate();
+ if (isShowing()) {
+ positionAtCursorOffset(getCurrentCursorOffset(), true);
+ }
+ };
+
private int getPreferredWidth() {
return Math.max(mDrawable.getIntrinsicWidth(), mMinSize);
}
@@ -4170,7 +4190,12 @@ public class Editor {
return mTextView.getOffsetAtCoordinate(line, x);
}
- protected void positionAtCursorOffset(int offset, boolean parentScrolled) {
+ /**
+ * @param offset Cursor offset. Must be in [-1, length].
+ * @param forceUpdatePosition whether to force update the position. This should be true
+ * when If the parent has been scrolled, for example.
+ */
+ protected void positionAtCursorOffset(int offset, boolean forceUpdatePosition) {
// A HandleView relies on the layout, which may be nulled by external methods
Layout layout = mTextView.getLayout();
if (layout == null) {
@@ -4181,7 +4206,7 @@ public class Editor {
layout = mTextView.getLayout();
boolean offsetChanged = offset != mPreviousOffset;
- if (offsetChanged || parentScrolled) {
+ if (offsetChanged || forceUpdatePosition) {
if (offsetChanged) {
updateSelection(offset);
addPositionToTouchUpFilter(offset);
@@ -4782,13 +4807,9 @@ public class Editor {
mPrevX = x;
}
- /**
- * @param offset Cursor offset. Must be in [-1, length].
- * @param parentScrolled If the parent has been scrolled or not.
- */
@Override
- protected void positionAtCursorOffset(int offset, boolean parentScrolled) {
- super.positionAtCursorOffset(offset, parentScrolled);
+ protected void positionAtCursorOffset(int offset, boolean forceUpdatePosition) {
+ super.positionAtCursorOffset(offset, forceUpdatePosition);
mInWord = (offset != -1) && !getWordIteratorWithText().isBoundary(offset);
}
@@ -5014,6 +5035,12 @@ public class Editor {
public boolean isActive() {
return mHandle != null && mHandle.isShowing();
}
+
+ public void invalidateHandle() {
+ if (mHandle != null) {
+ mHandle.invalidate();
+ }
+ }
}
class SelectionModifierCursorController implements CursorController {
@@ -5418,6 +5445,15 @@ public class Editor {
public boolean isActive() {
return mStartHandle != null && mStartHandle.isShowing();
}
+
+ public void invalidateHandles() {
+ if (mStartHandle != null) {
+ mStartHandle.invalidate();
+ }
+ if (mEndHandle != null) {
+ mEndHandle.invalidate();
+ }
+ }
}
private class CorrectionHighlighter {
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 4483b7bab3cd..48fd58b219db 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -3350,7 +3350,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mShadowColor = color;
// Will change text clip region
- if (mEditor != null) mEditor.invalidateTextDisplayList();
+ if (mEditor != null) {
+ mEditor.invalidateTextDisplayList();
+ mEditor.invalidateHandlesAndActionMode();
+ }
invalidate();
}
@@ -8306,6 +8309,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (mEditor != null) {
if (oldStart >= 0) mEditor.invalidateTextDisplayList(mLayout, oldStart, oldEnd);
if (newStart >= 0) mEditor.invalidateTextDisplayList(mLayout, newStart, newEnd);
+ mEditor.invalidateHandlesAndActionMode();
}
}