From 7dd0f0b3cf1885142cb6c59196da3a62fcc0c675 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sat, 19 Dec 2015 23:24:45 -0800 Subject: [PATCH] Avoid another UI race exposed by NVIDIA Shield Portable - Use AtomicBoolean to avoid spurious extra taps/clicks/presses --- .../java/org/deadc0de/apple2ix/Apple2Activity.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Android/app/src/main/java/org/deadc0de/apple2ix/Apple2Activity.java b/Android/app/src/main/java/org/deadc0de/apple2ix/Apple2Activity.java index 32b90534..c37bee6d 100644 --- a/Android/app/src/main/java/org/deadc0de/apple2ix/Apple2Activity.java +++ b/Android/app/src/main/java/org/deadc0de/apple2ix/Apple2Activity.java @@ -513,15 +513,25 @@ public class Apple2Activity extends Activity { final String quickSavePath = Apple2DisksMenu.getDataDir(this) + File.separator + SAVE_FILE; + final AtomicBoolean selectionAlreadyHandled = new AtomicBoolean(false); + AlertDialog saveRestoreDialog = new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setCancelable(true).setTitle(R.string.saverestore).setMessage(R.string.saverestore_choice).setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { + if (!selectionAlreadyHandled.compareAndSet(false, true)) { + Log.v(TAG, "OMG, avoiding nasty UI race in save/restore onClick()"); + return; + } Apple2Activity.this.nativeSaveState(quickSavePath); Apple2Activity.this.mMainMenu.dismiss(); } }).setNeutralButton(R.string.restore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { + if (!selectionAlreadyHandled.compareAndSet(false, true)) { + Log.v(TAG, "OMG, avoiding nasty UI race in save/restore onClick()"); + return; + } String jsonData = Apple2Activity.this.nativeLoadState(quickSavePath); try {