From dbe2c293e113b35b43abdb5733311782f9afe11c Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Wed, 27 May 2015 19:49:34 +0900 Subject: [PATCH] Fix: Drag handle jumps between bidi boundaries. mHotspotX and mHorizontalGravity was updated even when the handle is dragging. As a result, updatePosition() can be called with the adjusted coordinate for the updated text direction. Bug: 21131463 Change-Id: Ie3c2215a0d978db655d55693ee484f04ce5b35fa --- core/java/android/widget/Editor.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index fc84cf948a418..6c6099f22e971 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -3501,13 +3501,24 @@ public class Editor { } protected void updateDrawable() { + if (mIsDragging) { + // Don't update drawable during dragging. + return; + } final int offset = getCurrentCursorOffset(); final boolean isRtlCharAtOffset = mTextView.getLayout().isRtlCharAt(offset); final Drawable oldDrawable = mDrawable; mDrawable = isRtlCharAtOffset ? mDrawableRtl : mDrawableLtr; mHotspotX = getHotspotX(mDrawable, isRtlCharAtOffset); mHorizontalGravity = getHorizontalGravity(isRtlCharAtOffset); - if (oldDrawable != mDrawable) { + final Layout layout = mTextView.getLayout(); + if (layout != null && oldDrawable != mDrawable && isShowing()) { + // Update popup window position. + mPositionX = (int) (layout.getPrimaryHorizontal(offset) - 0.5f - mHotspotX - + getHorizontalOffset() + getCursorOffset()); + mPositionX += mTextView.viewportToContentHorizontalOffset(); + mPositionHasChanged = true; + updatePosition(mLastParentX, mLastParentY, false, false); postInvalidate(); } } @@ -3781,10 +3792,12 @@ public class Editor { case MotionEvent.ACTION_UP: filterOnTouchUp(); mIsDragging = false; + updateDrawable(); break; case MotionEvent.ACTION_CANCEL: mIsDragging = false; + updateDrawable(); break; } return true;