mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-12-27 06:29:19 +00:00
Move menu management into Apple2Activity
This commit is contained in:
parent
d6f769bcef
commit
2008c341d5
@ -45,10 +45,11 @@ public class Apple2Activity extends Activity {
|
||||
private boolean mSetUncaughtExceptionHandler = false;
|
||||
|
||||
private Apple2View mView = null;
|
||||
private Apple2SplashScreen mSplashScreen = null;
|
||||
private Apple2MainMenu mMainMenu = null;
|
||||
private ArrayList<Apple2MenuView> mMenuStack = new ArrayList<Apple2MenuView>();
|
||||
private AlertDialog mQuitDialog = null;
|
||||
private AlertDialog mRebootDialog = null;
|
||||
private Apple2SplashScreen mSplashScreen = null;
|
||||
|
||||
private int mWidth = 0;
|
||||
private int mHeight = 0;
|
||||
@ -298,25 +299,8 @@ public class Apple2Activity extends Activity {
|
||||
|
||||
// Apparently not good to leave popup/dialog windows showing when backgrounding.
|
||||
// Dismiss these popups to avoid android.view.WindowLeaked issues
|
||||
Apple2MainMenu mainMenu = mView.getMainMenu();
|
||||
if (mainMenu != null) {
|
||||
mainMenu.dismiss();
|
||||
}
|
||||
if (mQuitDialog != null && mQuitDialog.isShowing()) {
|
||||
mQuitDialog.dismiss();
|
||||
}
|
||||
if (mRebootDialog != null && mRebootDialog.isShowing()) {
|
||||
mRebootDialog.dismiss();
|
||||
}
|
||||
|
||||
// Get rid of the menu hierarchy
|
||||
Apple2MenuView apple2MenuView = null;
|
||||
do {
|
||||
apple2MenuView = popApple2View();
|
||||
if (apple2MenuView != null) {
|
||||
apple2MenuView.dismiss();
|
||||
}
|
||||
} while (apple2MenuView != null);
|
||||
// TODO FIXME : need to test/fix other popups generated in other menus ...
|
||||
dismissAllMenus();
|
||||
|
||||
nativeOnPause(true);
|
||||
}
|
||||
@ -333,15 +317,15 @@ public class Apple2Activity extends Activity {
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
Apple2MenuView apple2MenuView = popApple2View();
|
||||
Apple2MenuView apple2MenuView = peekApple2View();
|
||||
if (apple2MenuView == null) {
|
||||
mView.showMainMenu();
|
||||
showMainMenu();
|
||||
} else {
|
||||
apple2MenuView.dismiss();
|
||||
}
|
||||
return true;
|
||||
} else if (keyCode == KeyEvent.KEYCODE_MENU) {
|
||||
mView.showMainMenu();
|
||||
showMainMenu();
|
||||
return true;
|
||||
} else if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) || (keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) || (keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
|
||||
return false;
|
||||
@ -394,8 +378,7 @@ public class Apple2Activity extends Activity {
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
do {
|
||||
|
||||
Apple2MainMenu mainMenu = mView.getMainMenu();
|
||||
if (mainMenu == null) {
|
||||
if (mMainMenu == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -420,7 +403,7 @@ public class Apple2Activity extends Activity {
|
||||
}
|
||||
|
||||
if ((nativeFlags & NATIVE_TOUCH_REQUEST_SHOW_MENU) != 0) {
|
||||
mainMenu.show();
|
||||
mMainMenu.show();
|
||||
}
|
||||
|
||||
if ((nativeFlags & NATIVE_TOUCH_KEY_TAP) != 0) {
|
||||
@ -470,6 +453,10 @@ public class Apple2Activity extends Activity {
|
||||
}
|
||||
|
||||
public void graphicsInitialized(int w, int h) {
|
||||
if (mMainMenu == null) {
|
||||
mMainMenu = new Apple2MainMenu(this, mView);
|
||||
}
|
||||
|
||||
if (w < h) {
|
||||
// assure landscape dimensions
|
||||
final int w_ = w;
|
||||
@ -486,6 +473,20 @@ public class Apple2Activity extends Activity {
|
||||
showSplashScreen();
|
||||
}
|
||||
|
||||
public void showMainMenu() {
|
||||
if (mMainMenu != null) {
|
||||
Apple2SettingsMenu settingsMenu = mMainMenu.getSettingsMenu();
|
||||
Apple2DisksMenu disksMenu = mMainMenu.getDisksMenu();
|
||||
if (! (settingsMenu.isShowing() || disksMenu.isShowing()) ) {
|
||||
mMainMenu.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Apple2MainMenu getMainMenu() {
|
||||
return mMainMenu;
|
||||
}
|
||||
|
||||
public synchronized void showSplashScreen() {
|
||||
if (mSplashScreen != null && mSplashScreen.isShowing()) {
|
||||
return;
|
||||
@ -528,17 +529,25 @@ public class Apple2Activity extends Activity {
|
||||
return mMenuStack.get(lastIndex);
|
||||
}
|
||||
|
||||
public synchronized Apple2MenuView peekApple2View(int index) {
|
||||
int lastIndex = mMenuStack.size() - 1;
|
||||
if (lastIndex < 0) {
|
||||
return null;
|
||||
public void dismissAllMenus() {
|
||||
if (mMainMenu != null) {
|
||||
mMainMenu.dismiss();
|
||||
}
|
||||
if (mQuitDialog != null && mQuitDialog.isShowing()) {
|
||||
mQuitDialog.dismiss();
|
||||
}
|
||||
if (mRebootDialog != null && mRebootDialog.isShowing()) {
|
||||
mRebootDialog.dismiss();
|
||||
}
|
||||
|
||||
try {
|
||||
return mMenuStack.get(index);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
// Get rid of the menu hierarchy
|
||||
Apple2MenuView apple2MenuView;
|
||||
do {
|
||||
apple2MenuView = popApple2View();
|
||||
if (apple2MenuView != null) {
|
||||
apple2MenuView.dismissAll();
|
||||
}
|
||||
} while (apple2MenuView != null);
|
||||
}
|
||||
|
||||
public synchronized Apple2MenuView popApple2View(Apple2MenuView apple2MenuView) {
|
||||
@ -567,10 +576,6 @@ public class Apple2Activity extends Activity {
|
||||
return mView;
|
||||
}
|
||||
|
||||
public String getDataDir() {
|
||||
return mDataDir;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
@ -618,7 +623,7 @@ public class Apple2Activity extends Activity {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
nativeReboot();
|
||||
Apple2Activity.this.mView.getMainMenu().dismiss();
|
||||
Apple2Activity.this.mMainMenu.dismiss();
|
||||
}
|
||||
}).setNegativeButton(R.string.no, null).create();
|
||||
/*mRebootDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
|
@ -46,7 +46,7 @@ public class Apple2SplashScreen implements Apple2MenuView {
|
||||
prefsButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Apple2SettingsMenu settingsMenu = mActivity.getView().getMainMenu().getSettingsMenu();
|
||||
Apple2SettingsMenu settingsMenu = mActivity.getMainMenu().getSettingsMenu();
|
||||
settingsMenu.show();
|
||||
Apple2SplashScreen.this.dismiss();
|
||||
}
|
||||
|
@ -48,7 +48,6 @@ class Apple2View extends GLSurfaceView {
|
||||
private final static boolean DEBUG = false;
|
||||
|
||||
private Apple2Activity mActivity = null;
|
||||
private Apple2MainMenu mMainMenu = null;
|
||||
|
||||
public Apple2View(Apple2Activity activity) {
|
||||
super(activity.getApplication());
|
||||
@ -81,28 +80,6 @@ class Apple2View extends GLSurfaceView {
|
||||
setRenderer(new Renderer());
|
||||
}
|
||||
|
||||
public void showMainMenu() {
|
||||
if (mMainMenu != null) {
|
||||
Apple2SettingsMenu settingsMenu = mMainMenu.getSettingsMenu();
|
||||
Apple2DisksMenu disksMenu = mMainMenu.getDisksMenu();
|
||||
if (! (settingsMenu.isShowing() || disksMenu.isShowing()) ) {
|
||||
mMainMenu.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Apple2MainMenu getMainMenu() {
|
||||
return mMainMenu;
|
||||
}
|
||||
|
||||
public Apple2SettingsMenu getSettingsMenu() {
|
||||
return (mMainMenu == null) ? null : mMainMenu.getSettingsMenu();
|
||||
}
|
||||
|
||||
public Apple2DisksMenu getDisksMenu() {
|
||||
return (mMainMenu == null) ? null : mMainMenu.getDisksMenu();
|
||||
}
|
||||
|
||||
private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
|
||||
private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
|
||||
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
|
||||
@ -323,9 +300,6 @@ class Apple2View extends GLSurfaceView {
|
||||
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
Apple2View.this.mActivity.graphicsInitialized(width, height);
|
||||
if (Apple2View.this.mMainMenu == null) {
|
||||
Apple2View.this.mMainMenu = new Apple2MainMenu(Apple2View.this.mActivity, Apple2View.this);
|
||||
}
|
||||
}
|
||||
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
|
Loading…
Reference in New Issue
Block a user