Skip to content

Commit 5092588

Browse files
Add interactive buttons on ui thread. am: dd3764d am: ed5e9de
Original change: https://googleplex-android-review.googlesource.com/c/platform/cts/+/25450636 Change-Id: I0aa1857e717a8787c7d7d0020223c3753161a688 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents 741724f + ed5e9de commit 5092588

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

  • common/device-side/interactive/src/main/java/com/android/interactive

common/device-side/interactive/src/main/java/com/android/interactive/Step.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import static com.android.interactive.Automator.AUTOMATION_FILE;
2323

2424
import android.graphics.PixelFormat;
25+
import android.os.Handler;
26+
import android.os.Looper;
2527
import android.util.Log;
2628
import android.view.Gravity;
2729
import android.view.LayoutInflater;
@@ -247,27 +249,32 @@ public boolean hasFailed() {
247249
* Adds a button to the interaction prompt.
248250
*/
249251
protected void addButton(String title, Runnable onClick) {
250-
Button btn = new Button(TestApis.context().instrumentedContext());
251-
btn.setText(title);
252-
btn.setOnClickListener(v -> onClick.run());
253-
254-
GridLayout layout = mInstructionView.findViewById(R.id.buttons);
255-
layout.addView(btn);
252+
// Push to UI thread to avoid animation issues when adding the button
253+
new Handler(Looper.getMainLooper()).post(() -> {
254+
Button btn = new Button(TestApis.context().instrumentedContext());
255+
btn.setText(title);
256+
btn.setOnClickListener(v -> onClick.run());
257+
258+
GridLayout layout = mInstructionView.findViewById(R.id.buttons);
259+
layout.addView(btn);
260+
});
256261
}
257262

258263
/**
259264
* Adds small button with a single up/down arrow, used for moving the text box to the
260265
* bottom of the screen in case it covers some critical area of the app
261266
*/
262-
263267
protected void addSwapButton() {
264-
Button btn = new Button(TestApis.context().instrumentedContext());
265-
// up/down arrow
266-
btn.setText("\u21F5");
267-
btn.setOnClickListener(v -> swap());
268-
269-
GridLayout layout = mInstructionView.findViewById(R.id.buttons);
270-
layout.addView(btn);
268+
// Push to UI thread to avoid animation issues when adding the button
269+
new Handler(Looper.getMainLooper()).post(() -> {
270+
Button btn = new Button(TestApis.context().instrumentedContext());
271+
// up/down arrow
272+
btn.setText("\u21F5");
273+
btn.setOnClickListener(v -> swap());
274+
275+
GridLayout layout = mInstructionView.findViewById(R.id.buttons);
276+
layout.addView(btn);
277+
});
271278
}
272279

273280
/**

0 commit comments

Comments
 (0)