Merge "Fixes around text selection"
This commit is contained in:
committed by
Android (Google) Code Review
commit
26b5cf40b1
@@ -232,8 +232,7 @@ public class ArrowKeyMovementMethod extends BaseMovementMethod implements Moveme
|
|||||||
|
|
||||||
if (widget.isFocused() && !widget.didTouchFocusSelect()) {
|
if (widget.isFocused() && !widget.didTouchFocusSelect()) {
|
||||||
if (action == MotionEvent.ACTION_DOWN) {
|
if (action == MotionEvent.ACTION_DOWN) {
|
||||||
boolean cap = isSelecting(buffer);
|
if (isSelecting(buffer)) {
|
||||||
if (cap) {
|
|
||||||
int offset = widget.getOffsetForPosition(event.getX(), event.getY());
|
int offset = widget.getOffsetForPosition(event.getX(), event.getY());
|
||||||
|
|
||||||
buffer.setSpan(LAST_TAP_DOWN, offset, offset, Spannable.SPAN_POINT_POINT);
|
buffer.setSpan(LAST_TAP_DOWN, offset, offset, Spannable.SPAN_POINT_POINT);
|
||||||
@@ -245,9 +244,7 @@ public class ArrowKeyMovementMethod extends BaseMovementMethod implements Moveme
|
|||||||
widget.getParent().requestDisallowInterceptTouchEvent(true);
|
widget.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
}
|
}
|
||||||
} else if (action == MotionEvent.ACTION_MOVE) {
|
} else if (action == MotionEvent.ACTION_MOVE) {
|
||||||
boolean cap = isSelecting(buffer);
|
if (isSelecting(buffer) && handled) {
|
||||||
|
|
||||||
if (cap && handled) {
|
|
||||||
// Before selecting, make sure we've moved out of the "slop".
|
// Before selecting, make sure we've moved out of the "slop".
|
||||||
// handled will be true, if we're in select mode AND we're
|
// handled will be true, if we're in select mode AND we're
|
||||||
// OUT of the slop
|
// OUT of the slop
|
||||||
@@ -279,7 +276,7 @@ public class ArrowKeyMovementMethod extends BaseMovementMethod implements Moveme
|
|||||||
if (isSelecting(buffer)) {
|
if (isSelecting(buffer)) {
|
||||||
buffer.removeSpan(LAST_TAP_DOWN);
|
buffer.removeSpan(LAST_TAP_DOWN);
|
||||||
Selection.extendSelection(buffer, offset);
|
Selection.extendSelection(buffer, offset);
|
||||||
} else {
|
} else if (!widget.shouldIgnoreActionUpEvent()) {
|
||||||
Selection.setSelection(buffer, offset);
|
Selection.setSelection(buffer, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,12 +147,10 @@ public class Touch {
|
|||||||
int nx = widget.getScrollX() + (int) dx;
|
int nx = widget.getScrollX() + (int) dx;
|
||||||
int ny = widget.getScrollY() + (int) dy;
|
int ny = widget.getScrollY() + (int) dy;
|
||||||
|
|
||||||
int padding = widget.getTotalPaddingTop() +
|
int padding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
|
||||||
widget.getTotalPaddingBottom();
|
|
||||||
Layout layout = widget.getLayout();
|
Layout layout = widget.getLayout();
|
||||||
|
|
||||||
ny = Math.min(ny, layout.getHeight() - (widget.getHeight() -
|
ny = Math.min(ny, layout.getHeight() - (widget.getHeight() - padding));
|
||||||
padding));
|
|
||||||
ny = Math.max(ny, 0);
|
ny = Math.max(ny, 0);
|
||||||
|
|
||||||
int oldX = widget.getScrollX();
|
int oldX = widget.getScrollX();
|
||||||
@@ -161,8 +159,7 @@ public class Touch {
|
|||||||
scrollTo(widget, layout, nx, ny);
|
scrollTo(widget, layout, nx, ny);
|
||||||
|
|
||||||
// If we actually scrolled, then cancel the up action.
|
// If we actually scrolled, then cancel the up action.
|
||||||
if (oldX != widget.getScrollX()
|
if (oldX != widget.getScrollX() || oldY != widget.getScrollY()) {
|
||||||
|| oldY != widget.getScrollY()) {
|
|
||||||
widget.cancelLongPress();
|
widget.cancelLongPress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8243,10 +8243,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
return superResult;
|
return superResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean touchIsFinished = action == MotionEvent.ACTION_UP && !mIgnoreActionUpEvent &&
|
final boolean touchIsFinished = (action == MotionEvent.ACTION_UP) &&
|
||||||
isFocused();
|
!shouldIgnoreActionUpEvent() && isFocused();
|
||||||
|
|
||||||
if ((mMovement != null || onCheckIsTextEditor()) && isEnabled()
|
if ((mMovement != null || onCheckIsTextEditor()) && isEnabled()
|
||||||
&& mText instanceof Spannable && mLayout != null) {
|
&& mText instanceof Spannable && mLayout != null) {
|
||||||
boolean handled = false;
|
boolean handled = false;
|
||||||
|
|
||||||
@@ -8254,9 +8254,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
handled |= mMovement.onTouchEvent(this, (Spannable) mText, event);
|
handled |= mMovement.onTouchEvent(this, (Spannable) mText, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mLinksClickable && mAutoLinkMask != 0 && mTextIsSelectable && touchIsFinished) {
|
if (touchIsFinished && mLinksClickable && mAutoLinkMask != 0 && mTextIsSelectable) {
|
||||||
// The LinkMovementMethod which should handle taps on links has not been installed
|
// The LinkMovementMethod which should handle taps on links has not been installed
|
||||||
// to support text selection. We reproduce its behavior here to open links.
|
// on non editable text that support text selection.
|
||||||
|
// We reproduce its behavior here to open links for these.
|
||||||
ClickableSpan[] links = ((Spannable) mText).getSpans(getSelectionStart(),
|
ClickableSpan[] links = ((Spannable) mText).getSpans(getSelectionStart(),
|
||||||
getSelectionEnd(), ClickableSpan.class);
|
getSelectionEnd(), ClickableSpan.class);
|
||||||
|
|
||||||
@@ -8266,7 +8267,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((isTextEditable() || mTextIsSelectable) && touchIsFinished) {
|
if (touchIsFinished && (isTextEditable() || mTextIsSelectable)) {
|
||||||
// Show the IME, except when selecting in read-only text.
|
// Show the IME, except when selecting in read-only text.
|
||||||
final InputMethodManager imm = InputMethodManager.peekInstance();
|
final InputMethodManager imm = InputMethodManager.peekInstance();
|
||||||
if (imm != null) {
|
if (imm != null) {
|
||||||
@@ -8277,16 +8278,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean selectAllGotFocus = mSelectAllOnFocus && didTouchFocusSelect();
|
boolean selectAllGotFocus = mSelectAllOnFocus && didTouchFocusSelect();
|
||||||
if (!selectAllGotFocus && hasSelection()) {
|
hideControllers();
|
||||||
startSelectionActionMode();
|
if (!selectAllGotFocus && mText.length() > 0) {
|
||||||
} else {
|
if (isCursorInsideEasyCorrectionSpan()) {
|
||||||
hideControllers();
|
showSuggestions();
|
||||||
if (!selectAllGotFocus && mText.length() > 0) {
|
} else if (hasInsertionController()) {
|
||||||
if (isCursorInsideEasyCorrectionSpan()) {
|
getInsertionController().show();
|
||||||
showSuggestions();
|
|
||||||
} else if (hasInsertionController()) {
|
|
||||||
getInsertionController().show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8398,7 +8395,18 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
super.cancelLongPress();
|
super.cancelLongPress();
|
||||||
mIgnoreActionUpEvent = true;
|
mIgnoreActionUpEvent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is only valid during a touch event.
|
||||||
|
*
|
||||||
|
* @return true when the ACTION_UP event should be ignored, false otherwise.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public boolean shouldIgnoreActionUpEvent() {
|
||||||
|
return mIgnoreActionUpEvent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTrackballEvent(MotionEvent event) {
|
public boolean onTrackballEvent(MotionEvent event) {
|
||||||
if (mMovement != null && mText instanceof Spannable &&
|
if (mMovement != null && mText instanceof Spannable &&
|
||||||
|
|||||||
Reference in New Issue
Block a user