Loading core/java/android/widget/Editor.java +55 −4 Original line number Diff line number Diff line Loading @@ -8105,6 +8105,16 @@ public class Editor { private final Paint mHighlightPaint; private final Path mHighlightPath; /** * Whether it is in the progress of updating transformation method. It's needed because * {@link TextView#setTransformationMethod(TransformationMethod)} will eventually call * {@link TextView#setText(CharSequence)}. * Because it normally should exit insert mode when {@link TextView#setText(CharSequence)} * is called externally, we need this boolean to distinguish whether setText is triggered * by setTransformation or not. */ private boolean mUpdatingTransformationMethod; InsertModeController(@NonNull TextView textView) { mTextView = Objects.requireNonNull(textView); mIsInsertModeActive = false; Loading Loading @@ -8137,7 +8147,7 @@ public class Editor { final boolean isSingleLine = mTextView.isSingleLine(); mInsertModeTransformationMethod = new InsertModeTransformationMethod(offset, isSingleLine, oldTransformationMethod); mTextView.setTransformationMethodInternal(mInsertModeTransformationMethod); setTransformationMethod(mInsertModeTransformationMethod, true); Selection.setSelection((Spannable) mTextView.getText(), offset); mIsInsertModeActive = true; Loading @@ -8145,6 +8155,10 @@ public class Editor { } void exitInsertMode() { exitInsertMode(true); } void exitInsertMode(boolean updateText) { if (!mIsInsertModeActive) return; if (mInsertModeTransformationMethod == null || mInsertModeTransformationMethod != mTextView.getTransformationMethod()) { Loading @@ -8157,7 +8171,7 @@ public class Editor { final int selectionEnd = mTextView.getSelectionEnd(); final TransformationMethod oldTransformationMethod = mInsertModeTransformationMethod.getOldTransformationMethod(); mTextView.setTransformationMethodInternal(oldTransformationMethod); setTransformationMethod(oldTransformationMethod, updateText); Selection.setSelection((Spannable) mTextView.getText(), selectionStart, selectionEnd); mIsInsertModeActive = false; } Loading @@ -8177,6 +8191,32 @@ public class Editor { } } /** * Update the TransformationMethod on the {@link TextView}. * @param method the new method to be set on the {@link TextView}/ * @param updateText whether to update the text during setTransformationMethod call. */ private void setTransformationMethod(TransformationMethod method, boolean updateText) { mUpdatingTransformationMethod = true; mTextView.setTransformationMethodInternal(method, updateText); mUpdatingTransformationMethod = false; } /** * Notify the InsertMode controller that the {@link TextView} is about to set its text. */ void beforeSetText() { // TextView#setText is called because our call to // TextView#setTransformationMethodInternal in enterInsertMode() or exitInsertMode(). // Do nothing in this case. if (mUpdatingTransformationMethod) { return; } // TextView#setText is called externally. Exit InsertMode but don't update text again // when calling setTransformationMethod. exitInsertMode(/* updateText */ false); } /** * Notify the {@link InsertModeController} before the TextView's * {@link TransformationMethod} is updated. If it's not in the insert mode, Loading Loading @@ -8205,6 +8245,9 @@ public class Editor { return mInsertModeController.enterInsertMode(offset); } /** * Exit insert mode if this editor is in insert mode. */ void exitInsertMode() { if (mInsertModeController == null) return; mInsertModeController.exitInsertMode(); Loading @@ -8217,7 +8260,7 @@ public class Editor { */ void setTransformationMethod(TransformationMethod method) { if (mInsertModeController == null || !mInsertModeController.mIsInsertModeActive) { mTextView.setTransformationMethodInternal(method); mTextView.setTransformationMethodInternal(method, /* updateText */ true); return; } Loading @@ -8226,10 +8269,18 @@ public class Editor { final int selectionStart = mTextView.getSelectionStart(); final int selectionEnd = mTextView.getSelectionEnd(); method = mInsertModeController.updateTransformationMethod(method); mTextView.setTransformationMethodInternal(method); mTextView.setTransformationMethodInternal(method, /* updateText */ true); Selection.setSelection((Spannable) mTextView.getText(), selectionStart, selectionEnd); } /** * Notify that the Editor that the associated {@link TextView} is about to set its text. */ void beforeSetText() { if (mInsertModeController == null) return; mInsertModeController.beforeSetText(); } /** * Initializes the nodeInfo with smart actions. */ Loading core/java/android/widget/TextView.java +19 −3 Original line number Diff line number Diff line Loading @@ -2795,11 +2795,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (mEditor != null) { mEditor.setTransformationMethod(method); } else { setTransformationMethodInternal(method); setTransformationMethodInternal(method, /* updateText */ true); } } void setTransformationMethodInternal(@Nullable TransformationMethod method) { /** * Set the transformation that is applied to the text that this TextView is displaying, * optionally call the setText. * @param method the new transformation method to be set. * @param updateText whether the call {@link #setText} which will update the TextView to display * the new content. This method is helpful when updating * {@link TransformationMethod} inside {@link #setText}. It should only be * false if text will be updated immediately after this call, otherwise the * TextView will enter an inconsistent state. */ void setTransformationMethodInternal(@Nullable TransformationMethod method, boolean updateText) { if (method == mTransformation) { // Avoid the setText() below if the transformation is // the same. Loading @@ -2821,7 +2832,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mAllowTransformationLengthChange = false; } if (updateText) { setText(mText); } if (hasPasswordTransformationMethod()) { notifyViewAccessibilityStateChangedIfNeeded( Loading Loading @@ -7000,6 +7013,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @UnsupportedAppUsage private void setText(CharSequence text, BufferType type, boolean notifyBefore, int oldlen) { if (mEditor != null) { mEditor.beforeSetText(); } mTextSetFromXmlOrResourceId = false; if (text == null) { text = ""; Loading Loading
core/java/android/widget/Editor.java +55 −4 Original line number Diff line number Diff line Loading @@ -8105,6 +8105,16 @@ public class Editor { private final Paint mHighlightPaint; private final Path mHighlightPath; /** * Whether it is in the progress of updating transformation method. It's needed because * {@link TextView#setTransformationMethod(TransformationMethod)} will eventually call * {@link TextView#setText(CharSequence)}. * Because it normally should exit insert mode when {@link TextView#setText(CharSequence)} * is called externally, we need this boolean to distinguish whether setText is triggered * by setTransformation or not. */ private boolean mUpdatingTransformationMethod; InsertModeController(@NonNull TextView textView) { mTextView = Objects.requireNonNull(textView); mIsInsertModeActive = false; Loading Loading @@ -8137,7 +8147,7 @@ public class Editor { final boolean isSingleLine = mTextView.isSingleLine(); mInsertModeTransformationMethod = new InsertModeTransformationMethod(offset, isSingleLine, oldTransformationMethod); mTextView.setTransformationMethodInternal(mInsertModeTransformationMethod); setTransformationMethod(mInsertModeTransformationMethod, true); Selection.setSelection((Spannable) mTextView.getText(), offset); mIsInsertModeActive = true; Loading @@ -8145,6 +8155,10 @@ public class Editor { } void exitInsertMode() { exitInsertMode(true); } void exitInsertMode(boolean updateText) { if (!mIsInsertModeActive) return; if (mInsertModeTransformationMethod == null || mInsertModeTransformationMethod != mTextView.getTransformationMethod()) { Loading @@ -8157,7 +8171,7 @@ public class Editor { final int selectionEnd = mTextView.getSelectionEnd(); final TransformationMethod oldTransformationMethod = mInsertModeTransformationMethod.getOldTransformationMethod(); mTextView.setTransformationMethodInternal(oldTransformationMethod); setTransformationMethod(oldTransformationMethod, updateText); Selection.setSelection((Spannable) mTextView.getText(), selectionStart, selectionEnd); mIsInsertModeActive = false; } Loading @@ -8177,6 +8191,32 @@ public class Editor { } } /** * Update the TransformationMethod on the {@link TextView}. * @param method the new method to be set on the {@link TextView}/ * @param updateText whether to update the text during setTransformationMethod call. */ private void setTransformationMethod(TransformationMethod method, boolean updateText) { mUpdatingTransformationMethod = true; mTextView.setTransformationMethodInternal(method, updateText); mUpdatingTransformationMethod = false; } /** * Notify the InsertMode controller that the {@link TextView} is about to set its text. */ void beforeSetText() { // TextView#setText is called because our call to // TextView#setTransformationMethodInternal in enterInsertMode() or exitInsertMode(). // Do nothing in this case. if (mUpdatingTransformationMethod) { return; } // TextView#setText is called externally. Exit InsertMode but don't update text again // when calling setTransformationMethod. exitInsertMode(/* updateText */ false); } /** * Notify the {@link InsertModeController} before the TextView's * {@link TransformationMethod} is updated. If it's not in the insert mode, Loading Loading @@ -8205,6 +8245,9 @@ public class Editor { return mInsertModeController.enterInsertMode(offset); } /** * Exit insert mode if this editor is in insert mode. */ void exitInsertMode() { if (mInsertModeController == null) return; mInsertModeController.exitInsertMode(); Loading @@ -8217,7 +8260,7 @@ public class Editor { */ void setTransformationMethod(TransformationMethod method) { if (mInsertModeController == null || !mInsertModeController.mIsInsertModeActive) { mTextView.setTransformationMethodInternal(method); mTextView.setTransformationMethodInternal(method, /* updateText */ true); return; } Loading @@ -8226,10 +8269,18 @@ public class Editor { final int selectionStart = mTextView.getSelectionStart(); final int selectionEnd = mTextView.getSelectionEnd(); method = mInsertModeController.updateTransformationMethod(method); mTextView.setTransformationMethodInternal(method); mTextView.setTransformationMethodInternal(method, /* updateText */ true); Selection.setSelection((Spannable) mTextView.getText(), selectionStart, selectionEnd); } /** * Notify that the Editor that the associated {@link TextView} is about to set its text. */ void beforeSetText() { if (mInsertModeController == null) return; mInsertModeController.beforeSetText(); } /** * Initializes the nodeInfo with smart actions. */ Loading
core/java/android/widget/TextView.java +19 −3 Original line number Diff line number Diff line Loading @@ -2795,11 +2795,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (mEditor != null) { mEditor.setTransformationMethod(method); } else { setTransformationMethodInternal(method); setTransformationMethodInternal(method, /* updateText */ true); } } void setTransformationMethodInternal(@Nullable TransformationMethod method) { /** * Set the transformation that is applied to the text that this TextView is displaying, * optionally call the setText. * @param method the new transformation method to be set. * @param updateText whether the call {@link #setText} which will update the TextView to display * the new content. This method is helpful when updating * {@link TransformationMethod} inside {@link #setText}. It should only be * false if text will be updated immediately after this call, otherwise the * TextView will enter an inconsistent state. */ void setTransformationMethodInternal(@Nullable TransformationMethod method, boolean updateText) { if (method == mTransformation) { // Avoid the setText() below if the transformation is // the same. Loading @@ -2821,7 +2832,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener mAllowTransformationLengthChange = false; } if (updateText) { setText(mText); } if (hasPasswordTransformationMethod()) { notifyViewAccessibilityStateChangedIfNeeded( Loading Loading @@ -7000,6 +7013,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @UnsupportedAppUsage private void setText(CharSequence text, BufferType type, boolean notifyBefore, int oldlen) { if (mEditor != null) { mEditor.beforeSetText(); } mTextSetFromXmlOrResourceId = false; if (text == null) { text = ""; Loading