Loading core/api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -53317,6 +53317,7 @@ package android.view.inputmethod { method public default void performHandwritingGesture(@NonNull android.view.inputmethod.HandwritingGesture, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.IntConsumer); method public boolean performPrivateCommand(String, android.os.Bundle); method public default boolean performSpellCheck(); method public default boolean replaceText(@IntRange(from=0) int, @IntRange(from=0) int, @NonNull CharSequence, int, @Nullable android.view.inputmethod.TextAttribute); method public boolean reportFullscreenMode(boolean); method public boolean requestCursorUpdates(int); method public default boolean requestCursorUpdates(int, int); core/java/android/inputmethodservice/IRemoteInputConnectionInvoker.java +29 −0 Original line number Diff line number Diff line Loading @@ -775,4 +775,33 @@ final class IRemoteInputConnectionInvoker { return false; } } /** * Invokes {@link IRemoteInputConnection#replaceText(InputConnectionCommandHeader, int, int, * CharSequence, TextAttribute)}. * * @param start the character index where the replacement should start. * @param end the character index where the replacement should end. * @param newCursorPosition the new cursor position around the text. If > 0, this is relative to * the end of the text - 1; if <= 0, this is relative to the start of the text. So a value * of 1 will always advance you to the position after the full text being inserted. Note * that this means you can't position the cursor within the text. * @param text the text to replace. This may include styles. * @param textAttribute The extra information about the text. This value may be null. */ @AnyThread public boolean replaceText( int start, int end, @NonNull CharSequence text, int newCursorPosition, @Nullable TextAttribute textAttribute) { try { mConnection.replaceText( createHeader(), start, end, text, newCursorPosition, textAttribute); return true; } catch (RemoteException e) { return false; } } } core/java/android/inputmethodservice/RemoteInputConnection.java +11 −0 Original line number Diff line number Diff line Loading @@ -498,6 +498,17 @@ final class RemoteInputConnection implements InputConnection { return mInvoker.setImeConsumesInput(imeConsumesInput); } /** See {@link InputConnection#replaceText(int, int, CharSequence, int, TextAttribute)}. */ @AnyThread public boolean replaceText( int start, int end, @NonNull CharSequence text, int newCursorPosition, @Nullable TextAttribute textAttribute) { return mInvoker.replaceText(start, end, text, newCursorPosition, textAttribute); } @AnyThread @Override public String toString() { Loading core/java/android/view/inputmethod/BaseInputConnection.java +47 −5 Original line number Diff line number Diff line Loading @@ -897,8 +897,43 @@ public class BaseInputConnection implements InputConnection { } } private void replaceText(CharSequence text, int newCursorPosition, boolean composing) { @Override public boolean replaceText( @IntRange(from = 0) int start, @IntRange(from = 0) int end, @NonNull CharSequence text, int newCursorPosition, @Nullable TextAttribute textAttribute) { Preconditions.checkArgumentNonnegative(start); Preconditions.checkArgumentNonnegative(end); if (DEBUG) { Log.v( TAG, "replaceText " + start + ", " + end + ", " + text + ", " + newCursorPosition); } final Editable content = getEditable(); if (content == null) { return false; } beginBatchEdit(); removeComposingSpans(content); int len = content.length(); start = Math.min(start, len); end = Math.min(end, len); if (end < start) { int tmp = start; start = end; end = tmp; } replaceTextInternal(start, end, text, newCursorPosition, /*composing=*/ false); endBatchEdit(); return true; } private void replaceText(CharSequence text, int newCursorPosition, boolean composing) { final Editable content = getEditable(); if (content == null) { return; Loading Loading @@ -931,6 +966,16 @@ public class BaseInputConnection implements InputConnection { b = tmp; } } replaceTextInternal(a, b, text, newCursorPosition, composing); endBatchEdit(); } private void replaceTextInternal( int a, int b, CharSequence text, int newCursorPosition, boolean composing) { final Editable content = getEditable(); if (content == null) { return; } if (composing) { Spannable sp = null; Loading Loading @@ -974,7 +1019,6 @@ public class BaseInputConnection implements InputConnection { if (newCursorPosition < 0) newCursorPosition = 0; if (newCursorPosition > content.length()) newCursorPosition = content.length(); Selection.setSelection(content, newCursorPosition); content.replace(a, b, text); if (DEBUG) { Loading @@ -982,8 +1026,6 @@ public class BaseInputConnection implements InputConnection { lp.println("Final text:"); TextUtils.dumpSpans(content, lp, " "); } endBatchEdit(); } /** Loading core/java/android/view/inputmethod/InputConnection.java +40 −0 Original line number Diff line number Diff line Loading @@ -1329,4 +1329,44 @@ public interface InputConnection { // existing APIs. return null; } /** * Replace the specific range in the editor with suggested text. * * <p>This method finishes whatever composing text is currently active and leaves the text * as-it, replaces the specific range of text with the passed CharSequence, and then moves the * cursor according to {@code newCursorPosition}. This behaves like calling {@link * #finishComposingText()}, {@link #setSelection(int, int) setSelection(start, end)}, and then * {@link #commitText(CharSequence, int, TextAttribute) commitText(text, newCursorPosition, * textAttribute)}. * * <p>Similar to {@link #setSelection(int, int)}, the order of start and end is not important. * In effect, the region from start to end and the region from end to start is the same. Editor * authors, be ready to accept a start that is greater than end. * * @param start the character index where the replacement should start. * @param end the character index where the replacement should end. * @param newCursorPosition the new cursor position around the text. If > 0, this is relative to * the end of the text - 1; if <= 0, this is relative to the start of the text. So a value * of 1 will always advance you to the position after the full text being inserted. Note * that this means you can't position the cursor within the text. * @param text the text to replace. This may include styles. * @param textAttribute The extra information about the text. This value may be null. */ default boolean replaceText( @IntRange(from = 0) int start, @IntRange(from = 0) int end, @NonNull CharSequence text, int newCursorPosition, @Nullable TextAttribute textAttribute) { Preconditions.checkArgumentNonnegative(start); Preconditions.checkArgumentNonnegative(end); beginBatchEdit(); finishComposingText(); setSelection(start, end); commitText(text, newCursorPosition, textAttribute); endBatchEdit(); return true; } } Loading
core/api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -53317,6 +53317,7 @@ package android.view.inputmethod { method public default void performHandwritingGesture(@NonNull android.view.inputmethod.HandwritingGesture, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.IntConsumer); method public boolean performPrivateCommand(String, android.os.Bundle); method public default boolean performSpellCheck(); method public default boolean replaceText(@IntRange(from=0) int, @IntRange(from=0) int, @NonNull CharSequence, int, @Nullable android.view.inputmethod.TextAttribute); method public boolean reportFullscreenMode(boolean); method public boolean requestCursorUpdates(int); method public default boolean requestCursorUpdates(int, int);
core/java/android/inputmethodservice/IRemoteInputConnectionInvoker.java +29 −0 Original line number Diff line number Diff line Loading @@ -775,4 +775,33 @@ final class IRemoteInputConnectionInvoker { return false; } } /** * Invokes {@link IRemoteInputConnection#replaceText(InputConnectionCommandHeader, int, int, * CharSequence, TextAttribute)}. * * @param start the character index where the replacement should start. * @param end the character index where the replacement should end. * @param newCursorPosition the new cursor position around the text. If > 0, this is relative to * the end of the text - 1; if <= 0, this is relative to the start of the text. So a value * of 1 will always advance you to the position after the full text being inserted. Note * that this means you can't position the cursor within the text. * @param text the text to replace. This may include styles. * @param textAttribute The extra information about the text. This value may be null. */ @AnyThread public boolean replaceText( int start, int end, @NonNull CharSequence text, int newCursorPosition, @Nullable TextAttribute textAttribute) { try { mConnection.replaceText( createHeader(), start, end, text, newCursorPosition, textAttribute); return true; } catch (RemoteException e) { return false; } } }
core/java/android/inputmethodservice/RemoteInputConnection.java +11 −0 Original line number Diff line number Diff line Loading @@ -498,6 +498,17 @@ final class RemoteInputConnection implements InputConnection { return mInvoker.setImeConsumesInput(imeConsumesInput); } /** See {@link InputConnection#replaceText(int, int, CharSequence, int, TextAttribute)}. */ @AnyThread public boolean replaceText( int start, int end, @NonNull CharSequence text, int newCursorPosition, @Nullable TextAttribute textAttribute) { return mInvoker.replaceText(start, end, text, newCursorPosition, textAttribute); } @AnyThread @Override public String toString() { Loading
core/java/android/view/inputmethod/BaseInputConnection.java +47 −5 Original line number Diff line number Diff line Loading @@ -897,8 +897,43 @@ public class BaseInputConnection implements InputConnection { } } private void replaceText(CharSequence text, int newCursorPosition, boolean composing) { @Override public boolean replaceText( @IntRange(from = 0) int start, @IntRange(from = 0) int end, @NonNull CharSequence text, int newCursorPosition, @Nullable TextAttribute textAttribute) { Preconditions.checkArgumentNonnegative(start); Preconditions.checkArgumentNonnegative(end); if (DEBUG) { Log.v( TAG, "replaceText " + start + ", " + end + ", " + text + ", " + newCursorPosition); } final Editable content = getEditable(); if (content == null) { return false; } beginBatchEdit(); removeComposingSpans(content); int len = content.length(); start = Math.min(start, len); end = Math.min(end, len); if (end < start) { int tmp = start; start = end; end = tmp; } replaceTextInternal(start, end, text, newCursorPosition, /*composing=*/ false); endBatchEdit(); return true; } private void replaceText(CharSequence text, int newCursorPosition, boolean composing) { final Editable content = getEditable(); if (content == null) { return; Loading Loading @@ -931,6 +966,16 @@ public class BaseInputConnection implements InputConnection { b = tmp; } } replaceTextInternal(a, b, text, newCursorPosition, composing); endBatchEdit(); } private void replaceTextInternal( int a, int b, CharSequence text, int newCursorPosition, boolean composing) { final Editable content = getEditable(); if (content == null) { return; } if (composing) { Spannable sp = null; Loading Loading @@ -974,7 +1019,6 @@ public class BaseInputConnection implements InputConnection { if (newCursorPosition < 0) newCursorPosition = 0; if (newCursorPosition > content.length()) newCursorPosition = content.length(); Selection.setSelection(content, newCursorPosition); content.replace(a, b, text); if (DEBUG) { Loading @@ -982,8 +1026,6 @@ public class BaseInputConnection implements InputConnection { lp.println("Final text:"); TextUtils.dumpSpans(content, lp, " "); } endBatchEdit(); } /** Loading
core/java/android/view/inputmethod/InputConnection.java +40 −0 Original line number Diff line number Diff line Loading @@ -1329,4 +1329,44 @@ public interface InputConnection { // existing APIs. return null; } /** * Replace the specific range in the editor with suggested text. * * <p>This method finishes whatever composing text is currently active and leaves the text * as-it, replaces the specific range of text with the passed CharSequence, and then moves the * cursor according to {@code newCursorPosition}. This behaves like calling {@link * #finishComposingText()}, {@link #setSelection(int, int) setSelection(start, end)}, and then * {@link #commitText(CharSequence, int, TextAttribute) commitText(text, newCursorPosition, * textAttribute)}. * * <p>Similar to {@link #setSelection(int, int)}, the order of start and end is not important. * In effect, the region from start to end and the region from end to start is the same. Editor * authors, be ready to accept a start that is greater than end. * * @param start the character index where the replacement should start. * @param end the character index where the replacement should end. * @param newCursorPosition the new cursor position around the text. If > 0, this is relative to * the end of the text - 1; if <= 0, this is relative to the start of the text. So a value * of 1 will always advance you to the position after the full text being inserted. Note * that this means you can't position the cursor within the text. * @param text the text to replace. This may include styles. * @param textAttribute The extra information about the text. This value may be null. */ default boolean replaceText( @IntRange(from = 0) int start, @IntRange(from = 0) int end, @NonNull CharSequence text, int newCursorPosition, @Nullable TextAttribute textAttribute) { Preconditions.checkArgumentNonnegative(start); Preconditions.checkArgumentNonnegative(end); beginBatchEdit(); finishComposingText(); setSelection(start, end); commitText(text, newCursorPosition, textAttribute); endBatchEdit(); return true; } }