Avoid nasty UI race manifesting on NVIDIA Shield Portable

- For some reason this device has really slow Java UI, so it exposed a case where spammy touch resulted in two
      save/restore popups and a subsequent assert on the native side if you saved while the emulation was resumed.
This commit is contained in:
Aaron Culliney 2015-12-19 22:46:29 -08:00
parent 1e573c34ad
commit e5e2f98835

View File

@ -28,6 +28,8 @@ import android.widget.TextView;
import org.deadc0de.apple2ix.basic.R; import org.deadc0de.apple2ix.basic.R;
import java.util.concurrent.atomic.AtomicBoolean;
public class Apple2MainMenu { public class Apple2MainMenu {
private final static int MENU_INSET = 20; private final static int MENU_INSET = 20;
@ -37,6 +39,9 @@ public class Apple2MainMenu {
private Apple2View mParentView = null; private Apple2View mParentView = null;
private PopupWindow mMainMenuPopup = null; private PopupWindow mMainMenuPopup = null;
private AtomicBoolean mShowingRebootQuit = new AtomicBoolean(false);
private AtomicBoolean mShowingSaveRestore = new AtomicBoolean(false);
public Apple2MainMenu(Apple2Activity activity, Apple2View parent) { public Apple2MainMenu(Apple2Activity activity, Apple2View parent) {
mActivity = activity; mActivity = activity;
mParentView = parent; mParentView = parent;
@ -74,6 +79,10 @@ public class Apple2MainMenu {
return ctx.getResources().getString(R.string.saverestore_summary); return ctx.getResources().getString(R.string.saverestore_summary);
} }
@Override public void handleSelection(Apple2MainMenu mainMenu) { @Override public void handleSelection(Apple2MainMenu mainMenu) {
if (!mainMenu.mShowingSaveRestore.compareAndSet(false, true)) {
Log.d(TAG, "OMG, avoiding nasty UI race around save/restore");
return;
}
mainMenu.mActivity.maybeSaveRestore(); mainMenu.mActivity.maybeSaveRestore();
} }
}, },
@ -85,6 +94,10 @@ public class Apple2MainMenu {
return ""; return "";
} }
@Override public void handleSelection(Apple2MainMenu mainMenu) { @Override public void handleSelection(Apple2MainMenu mainMenu) {
if (!mainMenu.mShowingRebootQuit.compareAndSet(false, true)) {
Log.d(TAG, "OMG, avoiding nasty UI race around quit/reboot");
return;
}
mainMenu.mActivity.maybeRebootQuit(); mainMenu.mActivity.maybeRebootQuit();
} }
}; };
@ -163,7 +176,7 @@ public class Apple2MainMenu {
@Override @Override
public void onDismiss() { public void onDismiss() {
Apple2MainMenu.this.mActivity.maybeResumeCPU(); Apple2MainMenu.this.mActivity.maybeResumeCPU();
} }
}); });
} }
@ -184,6 +197,9 @@ public class Apple2MainMenu {
return; return;
} }
mShowingRebootQuit.set(false);
mShowingSaveRestore.set(false);
mActivity.nativeEmulationPause(); mActivity.nativeEmulationPause();
mMainMenuPopup.showAtLocation(mParentView, Gravity.CENTER, 0, 0); mMainMenuPopup.showAtLocation(mParentView, Gravity.CENTER, 0, 0);