Changeset 56


Ignore:
Timestamp:
08/08/07 02:42:05 (6 years ago)
Author:
saua
Message:
  • add timer in BBTracker for each component to use
  • add more startup actions
Location:
bbtracker/trunk/src/org/bbtracker/mobile
Files:
2 edited

Legend:

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

    r20 r56  
    11package org.bbtracker.mobile; 
     2 
     3import java.util.Timer; 
    24 
    35import javax.microedition.lcdui.Alert; 
     
    1517import org.bbtracker.mobile.gui.MainCanvas; 
    1618import org.bbtracker.mobile.gui.NewTrackForm; 
     19import org.bbtracker.mobile.gui.TracksForm; 
    1720 
    1821public class BBTracker extends MIDlet { 
     
    2932        private final MainCanvas mainCanvas; 
    3033 
     34        private final Timer timer; 
     35 
    3136        private boolean firstStart = true; 
    3237 
     
    3742                fullname = NAME + " " + version; 
    3843 
     44                timer = new Timer(); 
     45 
    3946                trackManager = new TrackManager(); 
    4047 
    4148                mainCanvas = new MainCanvas(trackManager); 
     49 
     50                TrackStore.getInstance(); 
    4251 
    4352                try { 
     
    4756                                trackManager.initLocationProvider(); 
    4857                                break; 
    49                         case Preferences.START_ACTION_NOTHING: 
     58                        default: 
    5059                                break; 
    5160                        } 
     
    6978        } 
    7079 
    71         protected void destroyApp(final boolean force) throws MIDletStateChangeException { 
    72                 shutdown(true); 
    73         } 
    74  
    75         protected void pauseApp() { 
    76         } 
    77  
    78         protected void startApp() throws MIDletStateChangeException { 
    79                 if (firstStart) { 
    80                         if (Preferences.getInstance().getStartAction() == Preferences.START_ACTION_NEWTRACK) { 
    81                                 Display.getDisplay(this).setCurrent(new NewTrackForm(trackManager)); 
    82                         } else { 
    83                                 showMainCanvas(); 
    84                         } 
    85                         firstStart = false; 
    86                 } else { 
    87                         showMainCanvas(); 
    88                 } 
    89  
    90         } 
    91  
    92         public static Display getDisplay() { 
    93                 return Display.getDisplay(instance); 
    94         } 
    95  
    9680        public static String getFullName() { 
    9781                return fullname; 
    98         } 
    99  
    100         public static BBTracker getInstance() { 
    101                 return instance; 
    10282        } 
    10383 
     
    11090        } 
    11191 
     92        public static BBTracker getInstance() { 
     93                return instance; 
     94        } 
     95 
     96        public static Display getDisplay() { 
     97                return Display.getDisplay(instance); 
     98        } 
     99 
     100        public static Timer getTimer() { 
     101                return instance.timer; 
     102        } 
     103 
    112104        public static void nonFatal(final Throwable t, final String action, final Displayable next) { 
    113105                log(t); 
     
    115107                                t.getMessage(), null, AlertType.WARNING); 
    116108                alert(alert, next); 
    117         } 
    118  
    119         public static void alert(final Alert alert, final Displayable next) { 
    120                 getDisplay().setCurrent(alert, next != null ? next : getInstance().mainCanvas); 
    121109        } 
    122110 
     
    138126        } 
    139127 
     128        public static void alert(final Alert alert, final Displayable next) { 
     129                getDisplay().setCurrent(alert, next != null ? next : getInstance().mainCanvas); 
     130        } 
     131 
    140132        public void showMainCanvas() { 
    141133                getDisplay().setCurrent(mainCanvas); 
     
    143135 
    144136        public static void log(final Throwable e) { 
    145                 // used only for debugging 
     137                log(e.toString()); 
    146138                e.printStackTrace(); 
    147139        } 
    148140 
    149141        public static void log(final String m) { 
    150                 // used only for debugging 
    151142                System.err.println(m); 
    152143        } 
     144 
     145        protected void destroyApp(final boolean force) throws MIDletStateChangeException { 
     146                shutdown(true); 
     147        } 
     148 
     149        protected void pauseApp() { 
     150        } 
     151 
     152        protected void startApp() throws MIDletStateChangeException { 
     153                if (firstStart) { 
     154                        firstStart = false; 
     155                        final int startAction = Preferences.getInstance().getStartAction(); 
     156                        if (startAction == Preferences.START_ACTION_NEWTRACK) { 
     157                                Display.getDisplay(this).setCurrent(new NewTrackForm(trackManager)); 
     158                        } else if (startAction == Preferences.START_ACTION_TRACKS_SCREEN) { 
     159                                try { 
     160                                        Display.getDisplay(this).setCurrent(new TracksForm(trackManager)); 
     161                                } catch (final RecordStoreException e) { 
     162                                        nonFatal(e, "Opening Track Screen", mainCanvas); 
     163                                } 
     164                        } else { 
     165                                showMainCanvas(); 
     166                        } 
     167                } else { 
     168                        showMainCanvas(); 
     169                } 
     170        } 
    153171} 
  • bbtracker/trunk/src/org/bbtracker/mobile/Preferences.java

    r36 r56  
    2626        public static final int START_ACTION_NEWTRACK = 2; 
    2727 
    28         public static String[] START_ACTIONS = new String[] { "Do nothing", "Initialize GPS", "Start new track" }; 
     28        public static final int START_ACTION_TRACKS_SCREEN = 3; 
     29 
     30        public static String[] START_ACTIONS = new String[] { "Do nothing", "Initialize GPS", "Start new track", 
     31                        "Open Track Screen" }; 
    2932 
    3033        public static final int EXPORT_KML = 0; 
    3134 
    32         public static final int EXPORT_GPx = 1; 
     35        public static final int EXPORT_GPX = 1; 
    3336 
    3437        public static String[] EXPORT_FORMATS = new String[] { "KML (Google Earth)", "GPX" }; 
     
    9497 
    9598        public void setExportDirectory(final String exportDirectory) { 
    96                 this.exportDirectory = exportDirectory; 
     99                if (exportDirectory == null || exportDirectory.length() == 0) { 
     100                        this.exportDirectory = null; 
     101                } else { 
     102                        this.exportDirectory = exportDirectory; 
     103                } 
    97104        } 
    98105 
     
    170177                        if (in.readByte() != 0) { 
    171178                                exportDirectory = in.readUTF(); 
     179                        } else { 
     180                                exportDirectory = null; 
    172181                        } 
    173182                        exportFormats = in.readInt(); 
Note: See TracChangeset for help on using the changeset viewer.