Loading core/java/android/widget/Editor.java +53 −0 Original line number Diff line number Diff line Loading @@ -1189,6 +1189,9 @@ public class Editor { } public boolean performLongClick(boolean handled) { if (TextView.DEBUG_CURSOR) { logCursor("performLongClick", "handled=%s", handled); } // Long press in empty space moves cursor and starts the insertion action mode. if (!handled && !isPositionOnText(mLastDownPositionX, mLastDownPositionY) && mInsertionControllerEnabled) { Loading Loading @@ -1252,6 +1255,10 @@ public class Editor { } void onFocusChanged(boolean focused, int direction) { if (TextView.DEBUG_CURSOR) { logCursor("onFocusChanged", "focused=%s", focused); } mShowCursor = SystemClock.uptimeMillis(); ensureEndedBatchEdit(); Loading Loading @@ -1450,12 +1457,22 @@ public class Editor { } else { mTapState = TAP_STATE_TRIPLE_CLICK; } if (TextView.DEBUG_CURSOR) { logCursor("updateTapState", "ACTION_DOWN: %s tap detected", (mTapState == TAP_STATE_DOUBLE_TAP ? "double" : "triple")); } } else { mTapState = TAP_STATE_FIRST_TAP; if (TextView.DEBUG_CURSOR) { logCursor("updateTapState", "ACTION_DOWN: first tap detected"); } } } if (action == MotionEvent.ACTION_UP) { mLastTouchUpTime = SystemClock.uptimeMillis(); if (TextView.DEBUG_CURSOR) { logCursor("updateTapState", "ACTION_UP"); } } } Loading Loading @@ -2354,6 +2371,9 @@ public class Editor { } void onTouchUpEvent(MotionEvent event) { if (TextView.DEBUG_CURSOR) { logCursor("onTouchUpEvent", null); } if (getSelectionActionModeHelper().resetSelection( getTextView().getOffsetForPosition(event.getX(), event.getY()))) { return; Loading Loading @@ -2481,6 +2501,9 @@ public class Editor { loadCursorDrawable(); final int left = clampHorizontalPosition(mDrawableForCursor, horizontal); final int width = mDrawableForCursor.getIntrinsicWidth(); if (TextView.DEBUG_CURSOR) { logCursor("updateCursorPosition", "left=%s, top=%s", left, (top - mTempRect.top)); } mDrawableForCursor.setBounds(left, top - mTempRect.top, left + width, bottom + mTempRect.bottom); } Loading Loading @@ -4621,6 +4644,11 @@ public class Editor { } public void show() { if (TextView.DEBUG_CURSOR) { logCursor(getClass().getSimpleName() + ": HandleView: show()", "offset=%s", getCurrentCursorOffset()); } if (isShowing()) return; getPositionListener().addSubscriber(this, true /* local position may change */); Loading @@ -4637,6 +4665,11 @@ public class Editor { } public void hide() { if (TextView.DEBUG_CURSOR) { logCursor(getClass().getSimpleName() + ": HandleView: hide()", "offset=%s", getCurrentCursorOffset()); } dismiss(); getPositionListener().removeSubscriber(this); Loading Loading @@ -5033,6 +5066,11 @@ public class Editor { @Override public boolean onTouchEvent(MotionEvent ev) { if (TextView.DEBUG_CURSOR) { logCursor(this.getClass().getSimpleName() + ": HandleView: onTouchEvent", MotionEvent.actionToString(ev.getActionMasked())); } updateFloatingToolbarVisibility(ev); switch (ev.getActionMasked()) { Loading Loading @@ -5951,6 +5989,10 @@ public class Editor { distanceSquared < doubleTapSlop * doubleTapSlop; if (stayedInArea && (isMouse || isPositionOnText(eventX, eventY))) { if (TextView.DEBUG_CURSOR) { logCursor("SelectionModifierCursorController: onTouchEvent", "ACTION_DOWN: select and start drag"); } if (mTapState == TAP_STATE_DOUBLE_TAP) { selectCurrentWordAndStartDrag(); } else if (mTapState == TAP_STATE_TRIPLE_CLICK) { Loading Loading @@ -6028,6 +6070,9 @@ public class Editor { break; case MotionEvent.ACTION_UP: if (TextView.DEBUG_CURSOR) { logCursor("SelectionModifierCursorController: onTouchEvent", "ACTION_UP"); } if (!isDragAcceleratorActive()) { break; } Loading Loading @@ -7119,4 +7164,12 @@ public class Editor { return resolveInfo.loadLabel(mPackageManager); } } private static void logCursor(String location, @Nullable String msgFormat, Object ... msgArgs) { if (msgFormat == null) { Log.d(TAG, location); } else { Log.d(TAG, location + ": " + String.format(msgFormat, msgArgs)); } } } core/java/android/widget/TextView.java +24 −1 Original line number Diff line number Diff line Loading @@ -345,6 +345,8 @@ import java.util.function.Supplier; public class TextView extends View implements ViewTreeObserver.OnPreDrawListener { static final String LOG_TAG = "TextView"; static final boolean DEBUG_EXTRACT = false; static final boolean DEBUG_CURSOR = false; private static final float[] TEMP_POSITION = new float[2]; // Enum for the "typeface" XML parameter. Loading Loading @@ -10857,6 +10859,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @Override public boolean onTouchEvent(MotionEvent event) { if (DEBUG_CURSOR) { logCursor("onTouchEvent", MotionEvent.actionToString(event.getActionMasked())); } final int action = event.getActionMasked(); if (mEditor != null) { mEditor.onTouchEvent(event); Loading @@ -10868,6 +10874,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } final boolean superResult = super.onTouchEvent(event); if (DEBUG_CURSOR) { logCursor("onTouchEvent", "superResult=%s", superResult); } /* * Don't handle the release after a long press, because it will move the selection away from Loading @@ -10876,7 +10885,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ if (mEditor != null && mEditor.mDiscardNextActionUp && action == MotionEvent.ACTION_UP) { mEditor.mDiscardNextActionUp = false; if (DEBUG_CURSOR) { logCursor("onTouchEvent", "release after long press detected"); } if (mEditor.mIsInsertionActionModeStartPending) { mEditor.startInsertionActionMode(); mEditor.mIsInsertionActionModeStartPending = false; Loading Loading @@ -12254,6 +12265,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @Override public boolean performLongClick() { if (DEBUG_CURSOR) { logCursor("performLongClick", null); } boolean handled = false; boolean performedHapticFeedback = false; Loading Loading @@ -13481,4 +13496,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener TextView.this.spanChange(buf, what, s, -1, e, -1); } } private static void logCursor(String location, @Nullable String msgFormat, Object ... msgArgs) { if (msgFormat == null) { Log.d(LOG_TAG, location); } else { Log.d(LOG_TAG, location + ": " + String.format(msgFormat, msgArgs)); } } } Loading
core/java/android/widget/Editor.java +53 −0 Original line number Diff line number Diff line Loading @@ -1189,6 +1189,9 @@ public class Editor { } public boolean performLongClick(boolean handled) { if (TextView.DEBUG_CURSOR) { logCursor("performLongClick", "handled=%s", handled); } // Long press in empty space moves cursor and starts the insertion action mode. if (!handled && !isPositionOnText(mLastDownPositionX, mLastDownPositionY) && mInsertionControllerEnabled) { Loading Loading @@ -1252,6 +1255,10 @@ public class Editor { } void onFocusChanged(boolean focused, int direction) { if (TextView.DEBUG_CURSOR) { logCursor("onFocusChanged", "focused=%s", focused); } mShowCursor = SystemClock.uptimeMillis(); ensureEndedBatchEdit(); Loading Loading @@ -1450,12 +1457,22 @@ public class Editor { } else { mTapState = TAP_STATE_TRIPLE_CLICK; } if (TextView.DEBUG_CURSOR) { logCursor("updateTapState", "ACTION_DOWN: %s tap detected", (mTapState == TAP_STATE_DOUBLE_TAP ? "double" : "triple")); } } else { mTapState = TAP_STATE_FIRST_TAP; if (TextView.DEBUG_CURSOR) { logCursor("updateTapState", "ACTION_DOWN: first tap detected"); } } } if (action == MotionEvent.ACTION_UP) { mLastTouchUpTime = SystemClock.uptimeMillis(); if (TextView.DEBUG_CURSOR) { logCursor("updateTapState", "ACTION_UP"); } } } Loading Loading @@ -2354,6 +2371,9 @@ public class Editor { } void onTouchUpEvent(MotionEvent event) { if (TextView.DEBUG_CURSOR) { logCursor("onTouchUpEvent", null); } if (getSelectionActionModeHelper().resetSelection( getTextView().getOffsetForPosition(event.getX(), event.getY()))) { return; Loading Loading @@ -2481,6 +2501,9 @@ public class Editor { loadCursorDrawable(); final int left = clampHorizontalPosition(mDrawableForCursor, horizontal); final int width = mDrawableForCursor.getIntrinsicWidth(); if (TextView.DEBUG_CURSOR) { logCursor("updateCursorPosition", "left=%s, top=%s", left, (top - mTempRect.top)); } mDrawableForCursor.setBounds(left, top - mTempRect.top, left + width, bottom + mTempRect.bottom); } Loading Loading @@ -4621,6 +4644,11 @@ public class Editor { } public void show() { if (TextView.DEBUG_CURSOR) { logCursor(getClass().getSimpleName() + ": HandleView: show()", "offset=%s", getCurrentCursorOffset()); } if (isShowing()) return; getPositionListener().addSubscriber(this, true /* local position may change */); Loading @@ -4637,6 +4665,11 @@ public class Editor { } public void hide() { if (TextView.DEBUG_CURSOR) { logCursor(getClass().getSimpleName() + ": HandleView: hide()", "offset=%s", getCurrentCursorOffset()); } dismiss(); getPositionListener().removeSubscriber(this); Loading Loading @@ -5033,6 +5066,11 @@ public class Editor { @Override public boolean onTouchEvent(MotionEvent ev) { if (TextView.DEBUG_CURSOR) { logCursor(this.getClass().getSimpleName() + ": HandleView: onTouchEvent", MotionEvent.actionToString(ev.getActionMasked())); } updateFloatingToolbarVisibility(ev); switch (ev.getActionMasked()) { Loading Loading @@ -5951,6 +5989,10 @@ public class Editor { distanceSquared < doubleTapSlop * doubleTapSlop; if (stayedInArea && (isMouse || isPositionOnText(eventX, eventY))) { if (TextView.DEBUG_CURSOR) { logCursor("SelectionModifierCursorController: onTouchEvent", "ACTION_DOWN: select and start drag"); } if (mTapState == TAP_STATE_DOUBLE_TAP) { selectCurrentWordAndStartDrag(); } else if (mTapState == TAP_STATE_TRIPLE_CLICK) { Loading Loading @@ -6028,6 +6070,9 @@ public class Editor { break; case MotionEvent.ACTION_UP: if (TextView.DEBUG_CURSOR) { logCursor("SelectionModifierCursorController: onTouchEvent", "ACTION_UP"); } if (!isDragAcceleratorActive()) { break; } Loading Loading @@ -7119,4 +7164,12 @@ public class Editor { return resolveInfo.loadLabel(mPackageManager); } } private static void logCursor(String location, @Nullable String msgFormat, Object ... msgArgs) { if (msgFormat == null) { Log.d(TAG, location); } else { Log.d(TAG, location + ": " + String.format(msgFormat, msgArgs)); } } }
core/java/android/widget/TextView.java +24 −1 Original line number Diff line number Diff line Loading @@ -345,6 +345,8 @@ import java.util.function.Supplier; public class TextView extends View implements ViewTreeObserver.OnPreDrawListener { static final String LOG_TAG = "TextView"; static final boolean DEBUG_EXTRACT = false; static final boolean DEBUG_CURSOR = false; private static final float[] TEMP_POSITION = new float[2]; // Enum for the "typeface" XML parameter. Loading Loading @@ -10857,6 +10859,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @Override public boolean onTouchEvent(MotionEvent event) { if (DEBUG_CURSOR) { logCursor("onTouchEvent", MotionEvent.actionToString(event.getActionMasked())); } final int action = event.getActionMasked(); if (mEditor != null) { mEditor.onTouchEvent(event); Loading @@ -10868,6 +10874,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } final boolean superResult = super.onTouchEvent(event); if (DEBUG_CURSOR) { logCursor("onTouchEvent", "superResult=%s", superResult); } /* * Don't handle the release after a long press, because it will move the selection away from Loading @@ -10876,7 +10885,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ if (mEditor != null && mEditor.mDiscardNextActionUp && action == MotionEvent.ACTION_UP) { mEditor.mDiscardNextActionUp = false; if (DEBUG_CURSOR) { logCursor("onTouchEvent", "release after long press detected"); } if (mEditor.mIsInsertionActionModeStartPending) { mEditor.startInsertionActionMode(); mEditor.mIsInsertionActionModeStartPending = false; Loading Loading @@ -12254,6 +12265,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @Override public boolean performLongClick() { if (DEBUG_CURSOR) { logCursor("performLongClick", null); } boolean handled = false; boolean performedHapticFeedback = false; Loading Loading @@ -13481,4 +13496,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener TextView.this.spanChange(buf, what, s, -1, e, -1); } } private static void logCursor(String location, @Nullable String msgFormat, Object ... msgArgs) { if (msgFormat == null) { Log.d(LOG_TAG, location); } else { Log.d(LOG_TAG, location + ": " + String.format(msgFormat, msgArgs)); } } }