diff options
author | Mady Mellor <madym@google.com> | 2015-07-11 00:26:33 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-11 00:26:35 +0000 |
commit | a9f07ccf38709be29137dec246bca7fea976a294 (patch) | |
tree | 7f7ffb10d1c025e83ebffb138c97d65204991b92 /core/java/android/widget | |
parent | 26b0f1e420c0590ea5e9c506f4f14ba4b0a873f0 (diff) | |
parent | a6a0f7829f070ea9f9a6a7c843e53f205630bfc2 (diff) | |
download | frameworks_base-a9f07ccf38709be29137dec246bca7fea976a294.zip frameworks_base-a9f07ccf38709be29137dec246bca7fea976a294.tar.gz frameworks_base-a9f07ccf38709be29137dec246bca7fea976a294.tar.bz2 |
Merge "Fix line slop issue at end of line for Thai & CJK" into mnc-dev
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/Editor.java | 58 |
1 files changed, 40 insertions, 18 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 96e033a..5c6ac56 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -16,6 +16,12 @@ package android.widget; +import java.text.BreakIterator; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; + import android.R; import android.annotation.Nullable; import android.app.PendingIntent; @@ -106,12 +112,6 @@ import com.android.internal.util.GrowingArrayUtils; import com.android.internal.util.Preconditions; import com.android.internal.widget.EditableInputConnection; -import java.text.BreakIterator; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; - /** * Helper class used by TextView to handle editable text views. @@ -127,6 +127,7 @@ public class Editor { private static int DRAG_SHADOW_MAX_TEXT_LENGTH = 20; private static final float LINE_SLOP_MULTIPLIER_FOR_HANDLEVIEWS = 0.5f; private static final int UNSET_X_VALUE = -1; + private static final int UNSET_LINE = -1; // Tag used when the Editor maintains its own separate UndoManager. private static final String UNDO_OWNER_TAG = "Editor"; @@ -3510,7 +3511,11 @@ public class Editor { // Minimum touch target size for handles private int mMinSize; // Indicates the line of text that the handle is on. - protected int mPrevLine = -1; + protected int mPrevLine = UNSET_LINE; + // Indicates the line of text that the user was touching. This can differ from mPrevLine + // when selecting text when the handles jump to the end / start of words which may be on + // a different line. + protected int mPreviousLineTouched = UNSET_LINE; public HandleView(Drawable drawableLtr, Drawable drawableRtl) { super(mTextView.getContext()); @@ -3801,6 +3806,7 @@ public class Editor { mLastParentX = positionListener.getPositionX(); mLastParentY = positionListener.getPositionY(); mIsDragging = true; + mPreviousLineTouched = UNSET_LINE; break; } @@ -4015,8 +4021,12 @@ public class Editor { Layout layout = mTextView.getLayout(); int offset; if (layout != null) { - int currLine = getCurrentLineAdjustedForSlop(layout, mPrevLine, y); + if (mPreviousLineTouched == UNSET_LINE) { + mPreviousLineTouched = mTextView.getLineAtCoordinate(y); + } + int currLine = getCurrentLineAdjustedForSlop(layout, mPreviousLineTouched, y); offset = mTextView.getOffsetAtCoordinate(currLine, x); + mPreviousLineTouched = currLine; } else { offset = mTextView.getOffsetForPosition(x, y); } @@ -4092,9 +4102,13 @@ public class Editor { return; } + if (mPreviousLineTouched == UNSET_LINE) { + mPreviousLineTouched = mTextView.getLineAtCoordinate(y); + } + boolean positionCursor = false; final int selectionEnd = mTextView.getSelectionEnd(); - int currLine = getCurrentLineAdjustedForSlop(layout, mPrevLine, y); + int currLine = getCurrentLineAdjustedForSlop(layout, mPreviousLineTouched, y); int initialOffset = mTextView.getOffsetAtCoordinate(currLine, x); if (initialOffset >= selectionEnd) { @@ -4138,9 +4152,9 @@ public class Editor { } else { final float xDiff = x - mPrevX; if (atRtl) { - isExpanding = xDiff > 0 || currLine > mPrevLine; + isExpanding = xDiff > 0 || currLine > mPreviousLineTouched; } else { - isExpanding = xDiff < 0 || currLine < mPrevLine; + isExpanding = xDiff < 0 || currLine < mPreviousLineTouched; } } @@ -4204,6 +4218,7 @@ public class Editor { offset = getNextCursorOffset(selectionEnd, false); mTouchWordDelta = 0.0f; } + mPreviousLineTouched = currLine; positionAtCursorOffset(offset, false); } mPrevX = x; @@ -4218,8 +4233,9 @@ public class Editor { @Override public boolean onTouchEvent(MotionEvent event) { boolean superResult = super.onTouchEvent(event); - if (event.getActionMasked() == MotionEvent.ACTION_UP) { - // Reset the touch word offset when the user has lifted their finger. + if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { + // Reset the touch word offset and x value when the user + // re-engages the handle. mTouchWordDelta = 0.0f; mPrevX = UNSET_X_VALUE; } @@ -4280,9 +4296,13 @@ public class Editor { return; } + if (mPreviousLineTouched == UNSET_LINE) { + mPreviousLineTouched = mTextView.getLineAtCoordinate(y); + } + boolean positionCursor = false; final int selectionStart = mTextView.getSelectionStart(); - int currLine = getCurrentLineAdjustedForSlop(layout, mPrevLine, y); + int currLine = getCurrentLineAdjustedForSlop(layout, mPreviousLineTouched, y); int initialOffset = mTextView.getOffsetAtCoordinate(currLine, x); if (initialOffset <= selectionStart) { @@ -4326,9 +4346,9 @@ public class Editor { } else { final float xDiff = x - mPrevX; if (atRtl) { - isExpanding = xDiff < 0 || currLine < mPrevLine; + isExpanding = xDiff < 0 || currLine < mPreviousLineTouched; } else { - isExpanding = xDiff > 0 || currLine > mPrevLine; + isExpanding = xDiff > 0 || currLine > mPreviousLineTouched; } } @@ -4392,6 +4412,7 @@ public class Editor { offset = getNextCursorOffset(selectionStart, true); mTouchWordDelta = 0.0f; } + mPreviousLineTouched = currLine; positionAtCursorOffset(offset, false); } mPrevX = x; @@ -4406,8 +4427,9 @@ public class Editor { @Override public boolean onTouchEvent(MotionEvent event) { boolean superResult = super.onTouchEvent(event); - if (event.getActionMasked() == MotionEvent.ACTION_UP) { - // Reset the touch word offset when the user has lifted their finger. + if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { + // Reset the touch word offset and x value when the user + // re-engages the handle. mTouchWordDelta = 0.0f; mPrevX = UNSET_X_VALUE; } |