public Dialog createDialog(int id) { if (id == DialogHelper.DIALOG_LOAD_FILE_EXPLORER) { return mm.getFileExplore().create(); } Dialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(mm); switch (id) { case DIALOG_FINISH_CUSTOM_LAYOUT: builder .setMessage("Do you want to save changes?") .setCancelable(false) .setPositiveButton( "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DialogHelper.savedDialog = DIALOG_NONE; mm.removeDialog(DIALOG_FINISH_CUSTOM_LAYOUT); ControlCustomizer.setEnabled(false); mm.getInputHandler().getControlCustomizer().saveDefinedControlLayout(); mm.getEmuView().setVisibility(View.VISIBLE); mm.getEmuView().requestFocus(); Emulator.resume(); mm.getInputView().invalidate(); } }) .setNegativeButton( "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DialogHelper.savedDialog = DIALOG_NONE; mm.removeDialog(DIALOG_FINISH_CUSTOM_LAYOUT); ControlCustomizer.setEnabled(false); mm.getInputHandler().getControlCustomizer().discardDefinedControlLayout(); mm.getEmuView().setVisibility(View.VISIBLE); mm.getEmuView().requestFocus(); Emulator.resume(); mm.getInputView().invalidate(); } }); dialog = builder.create(); break; case DIALOG_ROMs_DIR: builder .setMessage("Do you want to use default ROMs Path? (recomended)") .setCancelable(false) .setPositiveButton( "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DialogHelper.savedDialog = DIALOG_NONE; mm.removeDialog(DIALOG_ROMs_DIR); if (mm.getMainHelper().ensureROMsDir(mm.getMainHelper().getDefaultROMsDIR())) { mm.getPrefsHelper().setROMsDIR(mm.getMainHelper().getDefaultROMsDIR()); mm.runMAME4all(); } } }) .setNegativeButton( "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DialogHelper.savedDialog = DIALOG_NONE; mm.removeDialog(DIALOG_ROMs_DIR); mm.showDialog(DialogHelper.DIALOG_LOAD_FILE_EXPLORER); } }); dialog = builder.create(); break; case DIALOG_EXIT: builder .setMessage("Are you sure you want to exit?") .setCancelable(false) .setPositiveButton( "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // System.exit(0); android.os.Process.killProcess(android.os.Process.myPid()); } }) .setNegativeButton( "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); dialog = builder.create(); break; case DIALOG_ERROR_WRITING: builder .setMessage("Error") .setCancelable(false) .setPositiveButton( "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // System.exit(0); DialogHelper.savedDialog = DIALOG_NONE; mm.removeDialog(DIALOG_ERROR_WRITING); mm.showDialog(DialogHelper.DIALOG_LOAD_FILE_EXPLORER); } }); dialog = builder.create(); break; case DIALOG_INFO: builder .setMessage("Info") .setCancelable(false) .setPositiveButton( "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DialogHelper.savedDialog = DIALOG_NONE; Emulator.resume(); mm.removeDialog(DIALOG_INFO); } }); dialog = builder.create(); break; case DIALOG_EXIT_GAME: builder .setMessage("Are you sure you want to exit game?") .setCancelable(false) .setPositiveButton( "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DialogHelper.savedDialog = DIALOG_NONE; Emulator.resume(); Emulator.setValue(Emulator.EXIT_GAME_KEY, 1); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } Emulator.setValue(Emulator.EXIT_GAME_KEY, 0); mm.removeDialog(DIALOG_EXIT_GAME); } }) .setNegativeButton( "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Emulator.resume(); DialogHelper.savedDialog = DIALOG_NONE; mm.removeDialog(DIALOG_EXIT_GAME); } }); dialog = builder.create(); break; case DIALOG_OPTIONS: final CharSequence[] items = {"Help", "Settings", "Save", "Load", "Cancel"}; builder.setTitle("Choose an option from the menu. Press cancel to go back"); builder.setCancelable(true); builder.setItems( items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (item) { case 0: mm.getMainHelper().showHelp(); break; case 1: mm.getMainHelper().showSettings(); break; case 2: Emulator.saveState(); case 3: Emulator.restoreState(); // fallthrough case 4: Emulator.resume(); break; } DialogHelper.savedDialog = DIALOG_NONE; mm.removeDialog(DIALOG_OPTIONS); } }); builder.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { DialogHelper.savedDialog = DIALOG_NONE; Emulator.resume(); mm.removeDialog(DIALOG_OPTIONS); } }); dialog = builder.create(); break; case DIALOG_THANKS: builder .setMessage( "I am releasing everything for free, in keeping with the licensing MAME terms, which is free for non-commercial use only. This is strictly something I made because I wanted to play with it and have the skills to make it so. That said, if you are thinking on ways to support my development I suggest you to check my support page of other free works for the community.") .setCancelable(false) .setPositiveButton( "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DialogHelper.savedDialog = DIALOG_NONE; mm.getMainHelper().showWeb(); mm.removeDialog(DIALOG_THANKS); } }); dialog = builder.create(); break; case DIALOG_FULLSCREEN: final CharSequence[] items2 = {"Options", "Exit", "Cancel"}; builder.setTitle("Choose an option from the menu. Press cancel to go back"); builder.setCancelable(true); builder.setItems( items2, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (item) { case 0: mm.showDialog(DialogHelper.DIALOG_OPTIONS); break; case 1: if (!Emulator.isInMAME()) mm.showDialog(DialogHelper.DIALOG_EXIT); else mm.showDialog(DialogHelper.DIALOG_EXIT_GAME); break; case 2: Emulator.resume(); break; } DialogHelper.savedDialog = DIALOG_NONE; mm.removeDialog(DIALOG_FULLSCREEN); } }); builder.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { DialogHelper.savedDialog = DIALOG_NONE; Emulator.resume(); mm.removeDialog(DIALOG_FULLSCREEN); } }); dialog = builder.create(); break; default: dialog = null; } /* if(dialog!=null) { dialog.setCanceledOnTouchOutside(false); }*/ return dialog; }
public void removeDialogs() { if (savedDialog == DIALOG_FINISH_CUSTOM_LAYOUT) { mm.removeDialog(DIALOG_FINISH_CUSTOM_LAYOUT); DialogHelper.savedDialog = DIALOG_NONE; } }