From 359740ac6a685ed61aebf9fbca8fcc148048c7c6 Mon Sep 17 00:00:00 2001 From: Ibrahim Yilmaz Date: Wed, 28 Jun 2023 18:11:00 +0000 Subject: [PATCH] Add setTextAsync method to TextView This CL adds a setTextAsync method to the TextView class. This method allows the text to be maniputed on a background thread and set the result on main thread with Runnable. Bug: 289250881 Test: Manual by checking Notification and Widget Texts. Change-Id: I3d74f2de2503318441c868bb931a2bc447c03517 --- core/java/android/widget/TextView.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 27d8a8f23e460..b74c8795ffb1e 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -6938,11 +6938,25 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * parameters used to create the PrecomputedText mismatches * with this TextView. */ - @android.view.RemotableViewMethod + @android.view.RemotableViewMethod(asyncImpl = "setTextAsync") public final void setText(CharSequence text) { setText(text, mBufferType); } + /** + * RemotableViewMethod's asyncImpl of {@link #setText(CharSequence)}. + * This should be called on a background thread, and returns a Runnable which is then must be + * called on the main thread to complete the operation and set text. + * @param text text to be displayed + * @return Runnable that sets text; must be called on the main thread by the caller of this + * method to complete the operation + * @hide + */ + @NonNull + public Runnable setTextAsync(@Nullable CharSequence text) { + return () -> setText(text); + } + /** * Sets the text to be displayed but retains the cursor position. Same as * {@link #setText(CharSequence)} except that the cursor position (if any) is retained in the