Changeset 197


Ignore:
Timestamp:
05/02/08 15:04:09 (5 years ago)
Author:
saua
Message:

#82: Support pausing the current track
simple implementation ... I really need to think about more powerfull status messages ...

Location:
bbtracker/trunk/src/org/bbtracker/mobile
Files:
2 edited

Legend:

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

    r184 r197  
    5151        private int state; 
    5252 
     53        // true if no new points are recorded in TRACKING state. 
     54        private boolean paused; 
     55 
    5356        protected LocationProvider provider; 
    5457 
     
    7780                                        trackInterrupted = false; 
    7881                                } 
     82                                boolean currentPointChanged; 
    7983                                if (track != null) { 
    80                                         final int pointCount = track.getPointCount(); 
    81                                         if (currentPointIndex == pointCount - 1) { 
    82                                                 // activate the new point only, when the last point is currently selected. 
    83                                                 currentPointIndex = pointCount; 
    84                                                 currentPoint = location; 
     84                                        currentPointChanged = false; 
     85                                        if (!paused) { 
     86                                                final int pointCount = track.getPointCount(); 
     87                                                if (currentPointIndex == pointCount - 1) { 
     88                                                        // activate the new point only, when the last point is currently selected. 
     89                                                        currentPointIndex = pointCount; 
     90                                                        currentPoint = location; 
     91                                                        currentPointChanged = true; 
     92                                                } 
     93                                                if (newSegment) { 
     94                                                        track.newSegment(); 
     95                                                } 
     96                                                boundsChanged = track.addPoint(location); 
    8597                                        } 
    86                                         boundsChanged = track.addPoint(location); 
    8798                                } else { 
    8899                                        currentPoint = location; 
     100                                        currentPointChanged = true; 
    89101                                } 
    90                                 fireNewPoint(currentPoint, boundsChanged, newSegment); 
    91                                 fireCurrentPointChanged(); 
    92                                 providerStateChanged(provider, provider.getState()); 
     102                                fireNewPoint(location, boundsChanged, newSegment); 
     103                                if (currentPointChanged) { 
     104                                        fireCurrentPointChanged(); 
     105                                } 
    93106                        } else { 
    94107                                fireNewPoint(null, false, false); 
     
    97110 
    98111                public void providerStateChanged(final LocationProvider provider, final int newState) { 
    99                         // TODO Auto-generated method stub 
    100  
     112                        // noop 
    101113                } 
    102114        }; 
     
    182194                } 
    183195                return changed; 
     196        } 
     197 
     198        public void pauseTracking() { 
     199                if (state != STATE_TRACKING) { 
     200                        throw new IllegalStateException("Not in tracking state! Can't pause tracking!"); 
     201                } 
     202                paused = true; 
     203                final int pc = track.getPointCount(); 
     204                if (track != null && pc > 0) { 
     205                        final TrackPoint p = track.getPoint(pc - 1); 
     206                        if (p.getName() == null) { 
     207                                p.setName("paused"); 
     208                        } 
     209                } 
     210        } 
     211 
     212        public void continueTracking() { 
     213                if (state != STATE_TRACKING) { 
     214                        throw new IllegalStateException("Not in tracking state! Can't continue tracking!"); 
     215                } 
     216                trackInterrupted = true; 
     217                paused = false; 
     218        } 
     219 
     220        public boolean isPaused() { 
     221                return paused; 
    184222        } 
    185223 
     
    224262                track = new Track(name); 
    225263                state = STATE_TRACKING; 
     264                paused = false; 
    226265 
    227266                currentPointIndex = -1; 
  • bbtracker/trunk/src/org/bbtracker/mobile/gui/MainCanvas.java

    r194 r197  
    6565        private final Command stopTrackingCommand; 
    6666 
     67        private final Command pauseTrackingCommand; 
     68 
     69        private final Command continueTrackingCommand; 
     70 
    6771        private final Command tracksCommand; 
    6872 
     
    101105                newTrackCommand = new Command("Start Track", Command.SCREEN, 2); 
    102106                stopTrackingCommand = new Command("Stop Track", Command.STOP, 3); 
    103                 tracksCommand = new Command("Tracks", Command.SCREEN, 4); 
    104                 optionsCommand = new Command("Options", Command.SCREEN, 5); 
    105                 aboutCommand = new Command("About", Command.SCREEN, 6); 
     107                pauseTrackingCommand = new Command("Pause Track", Command.SCREEN, 4); 
     108                continueTrackingCommand = new Command("Continue Track", Command.SCREEN, 4); 
     109                tracksCommand = new Command("Tracks", Command.SCREEN, 5); 
     110                optionsCommand = new Command("Options", Command.SCREEN, 6); 
     111                aboutCommand = new Command("About", Command.SCREEN, 7); 
    106112                // #ifndef AVOID_FILE_API 
    107113                exportCommand = new Command("Export Track", Command.SCREEN, 1); 
     
    149155        protected void setStatusMessage(final String statusMessage, final int duration) { 
    150156                this.statusMessage = statusMessage; 
    151                 statusMessageEndTime = System.currentTimeMillis() + duration; 
    152                 BBTracker.getTimer().schedule(new RepaintTask(), duration + 10); 
     157                if (duration != -1) { 
     158                        statusMessageEndTime = System.currentTimeMillis() + duration; 
     159                        BBTracker.getTimer().schedule(new RepaintTask(), duration + 10); 
     160                } else { 
     161                        statusMessageEndTime = Long.MAX_VALUE; 
     162                } 
    153163                repaint(); 
    154164        } 
     
    211221                        setStatusMessage("Static Track"); 
    212222                        removeCommand(stopTrackingCommand); 
     223                        removeCommand(pauseTrackingCommand); 
     224                        removeCommand(continueTrackingCommand); 
    213225                        removeCommand(markPointCommand); 
    214226                        // #ifndef AVOID_FILE_API 
     
    219231                        setStatusMessage("Tracking"); 
    220232                        addCommand(stopTrackingCommand); 
     233                        addCommand(pauseTrackingCommand); 
    221234                        addCommand(markPointCommand); 
    222235                        // #ifndef AVOID_FILE_API 
     
    226239                default: 
    227240                        removeCommand(stopTrackingCommand); 
     241                        removeCommand(pauseTrackingCommand); 
     242                        removeCommand(continueTrackingCommand); 
     243                        removeCommand(markPointCommand); 
    228244                        // #ifndef AVOID_FILE_API 
    229245                        removeCommand(exportCommand); 
     
    276292                } else if (command == markPointCommand) { 
    277293                        markPointAction(); 
     294                } else if (command == pauseTrackingCommand) { 
     295                        pauseTrackingAction(); 
     296                } else if (command == continueTrackingCommand) { 
     297                        continueTrackingAction(); 
    278298                } else if (command == switchViewCommand) { 
    279299                        nextTileConfiguration(); 
     
    421441        } 
    422442 
     443        private void pauseTrackingAction() { 
     444                removeCommand(pauseTrackingCommand); 
     445                addCommand(continueTrackingCommand); 
     446                manager.pauseTracking(); 
     447                setStatusMessage("Paused!", -1); 
     448        } 
     449 
     450        private void continueTrackingAction() { 
     451                removeCommand(continueTrackingCommand); 
     452                addCommand(pauseTrackingCommand); 
     453                manager.continueTracking(); 
     454                setStatusMessage("Continuing..."); 
     455        } 
     456 
    423457        protected void keyReleased(final int keyCode) { 
    424458                final int gameAction = getGameAction(keyCode); 
Note: See TracChangeset for help on using the changeset viewer.