Changeset 68


Ignore:
Timestamp:
08/13/07 22:00:20 (6 years ago)
Author:
saua
Message:

add confirmation dialog when quitting (issue #20)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bbtracker/trunk/src/org/bbtracker/mobile/gui/MainCanvas.java

    r62 r68  
    2020import java.util.TimerTask; 
    2121 
     22import javax.microedition.lcdui.Alert; 
     23import javax.microedition.lcdui.AlertType; 
    2224import javax.microedition.lcdui.Canvas; 
    2325import javax.microedition.lcdui.Command; 
     
    225227                Displayable nextDisplayable = null; 
    226228                if (command == exitCommand) { 
    227                         BBTracker.getInstance().shutdown(true); 
     229                        exitAction(); 
    228230                } else if (command == switchViewCommand) { 
    229231                        nextTileConfiguration(); 
     
    246248        } 
    247249 
     250        private void exitAction() { 
     251                final boolean isTracking = manager.getState() == TrackManager.STATE_TRACKING; 
     252                String question = "Do you really want to quit?"; 
     253                if (isTracking) { 
     254                        question += "\nThe current Track will be finished and saved."; 
     255                } 
     256                final Alert alert = new Alert("Really Quit?", question, null, AlertType.CONFIRMATION); 
     257                final Command quitCommand = new Command("Quit", Command.OK, 1); 
     258                alert.addCommand(quitCommand); 
     259                alert.addCommand(new Command("Cancel", Command.CANCEL, 0)); 
     260                alert.setCommandListener(new CommandListener() { 
     261 
     262                        public void commandAction(final Command cmd, final Displayable current) { 
     263                                if (cmd == quitCommand) { 
     264                                        BBTracker.getInstance().shutdown(true); 
     265                                } else { 
     266                                        BBTracker.getDisplay().setCurrent(MainCanvas.this); 
     267                                } 
     268                        } 
     269                }); 
     270                BBTracker.alert(alert, this); 
     271        } 
     272 
    248273        protected void keyReleased(final int keyCode) { 
    249274                final int gameAction = getGameAction(keyCode); 
Note: See TracChangeset for help on using the changeset viewer.