This ConfirmationDelegate and Confirmation class from Ui... I essentially want to use it's "yes/no" functionality to query the user if they want to quit...
If I was using a more simple language it would be as easy as
if (ConfirmationDialog("Do you want to quit?") == true)
{
if (ConfirmationDialog("Do you want to save?") == true)
{
//save
}
return false; // let connectIQ handle the key (and exit)
}
else
{
return true; // handle the key and do not exit
}
But in monkeyC it seems much harder... I'm making ConfirmationDelegate's and initializing a Confirmation class with my message "Do you want to quit?"...
And deep in the "onReponse" function inside my ConfirmationDelegate class, I have it modify a global variable "globalUserWantsToQuit"... and I test the value of that global variable in my main function to see if the user wants to quit or not... and it's not working after all that...
Tell me; is there ANY easier (i.e. less roundabout) way to ask the user for simple input and carry on? I feel like I'm building an entire garage for where a simple door would do. Thanks in advance.
==================================================================
Oh yeah, below is the code that it seems connectIQ would have me write (I'm having it ask two questions, one for if the user wants to quit, and second if the user wants to save):
var globalUserWantsToQuit;
var globalUserWantsToSave;
class ConfirmExitDelegate extends Ui.ConfirmDelegate
{
function onResponse(value) {
if (value == 0) { globalUserWantsToQuit = false; }
else { globalUserWantsToQuit = true; }
}
}
class ConfirmSaveDelegate extends Ui.ConfirmDelegate
{
function onResponse(value) {
if (value == 0) { globalUserWantsToSave = false; }
else { globalUserWantsToSave = true; }
}
}
//... main InputDelegate class onKey function below:
var thisConfirmExit;
var thisConfirmSave;
//...
if( KEY_ESC == evt.getKey() )
{
Sys.println("ESC Button Pressed");
globalUserWantsToQuit = false; // default
thisConfirmExit = new Ui.Confirmation("do you want to exit?");
Ui.pushView( thisConfirmExit, new ConfirmExitDelegate(), Ui.SLIDE_RIGHT );
if (globalUserWantsToQuit == true)
{
globalUserWantsToSave = true; // default
thisConfirmSave = new Ui.Confirmation("do you want to save?");
Ui.pushView( thisConfirmSave, new ConfirmSaveDelegate(), Ui.SLIDE_RIGHT );
if (globalUserWantsToSave == true)
{
Sys.println("Saving Record");
}
Sys.println("Exiting");
return false; // let Garmin handle ESC input (and exit)
}
Sys.println("Not exiting");
return true; // handled ESC input
}
One easier way might be to not use global variables, and create those subvariables inside the classes. I'm just not too familiar with the "best" way to do this, in MonkeyC. I just wanted to make it work first of all, and haven't had luck yet.
Also, I believe that traditionally whenever you use "new" keyword, as in when I made those Ui.Confirmation classes, it allocates memory. I am not familiar with the details, but shouldn't I try to null these out afterwards? Should I be concerned about how long they stay alive for? Thanks...