|
22 | 22 | import static com.android.interactive.Automator.AUTOMATION_FILE; |
23 | 23 |
|
24 | 24 | import android.graphics.PixelFormat; |
| 25 | +import android.os.Handler; |
| 26 | +import android.os.Looper; |
25 | 27 | import android.util.Log; |
26 | 28 | import android.view.Gravity; |
27 | 29 | import android.view.LayoutInflater; |
@@ -247,27 +249,32 @@ public boolean hasFailed() { |
247 | 249 | * Adds a button to the interaction prompt. |
248 | 250 | */ |
249 | 251 | 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 | + }); |
256 | 261 | } |
257 | 262 |
|
258 | 263 | /** |
259 | 264 | * Adds small button with a single up/down arrow, used for moving the text box to the |
260 | 265 | * bottom of the screen in case it covers some critical area of the app |
261 | 266 | */ |
262 | | - |
263 | 267 | 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 | + }); |
271 | 278 | } |
272 | 279 |
|
273 | 280 | /** |
|
0 commit comments