Changeset 88
- Timestamp:
- 08/23/07 22:15:34 (6 years ago)
- Location:
- bbtracker/trunk/src/org/bbtracker/mobile
- Files:
-
- 10 edited
-
BBTracker.java (modified) (9 diffs)
-
FileTrackStore.java (modified) (10 diffs)
-
IconManager.java (modified) (1 diff)
-
RMSTrackStore.java (modified) (2 diffs)
-
TrackManager.java (modified) (4 diffs)
-
gui/AboutForm.java (modified) (2 diffs)
-
gui/MainCanvas.java (modified) (1 diff)
-
gui/OptionsForm.java (modified) (1 diff)
-
gui/StatusTile.java (modified) (2 diffs)
-
gui/TracksForm.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bbtracker/trunk/src/org/bbtracker/mobile/BBTracker.java
r75 r88 18 18 package org.bbtracker.mobile; 19 19 20 import java.io.OutputStream; 21 import java.io.PrintStream; 22 import java.util.Date; 20 23 import java.util.Timer; 21 24 25 import javax.microedition.io.Connector; 26 import javax.microedition.io.file.FileConnection; 22 27 import javax.microedition.lcdui.Alert; 23 28 import javax.microedition.lcdui.AlertType; … … 34 39 import org.bbtracker.mobile.TrackStore.TrackStoreException; 35 40 import org.bbtracker.mobile.gui.MainCanvas; 41 import org.bbtracker.mobile.gui.OptionsForm; 36 42 import org.bbtracker.mobile.gui.TrackNameForm; 37 import org.bbtracker.mobile.gui.OptionsForm;38 43 import org.bbtracker.mobile.gui.TracksForm; 39 44 … … 46 51 47 52 private static BBTracker instance; 53 54 private static PrintStream logStream; 48 55 49 56 private final TrackManager trackManager; … … 80 87 nonFatal(e, "Initializing Location Provider", mainCanvas); 81 88 } 89 90 initLog(); 82 91 } 83 92 84 93 public void shutdown(final boolean destroy) { 94 log(this, "shutdown " + destroy); 85 95 if (trackManager != null) { 86 96 trackManager.shutdown(); … … 94 104 notifyDestroyed(); 95 105 } 106 if (logStream != null) { 107 logStream.close(); 108 logStream = null; 109 } 96 110 } 97 111 … … 121 135 122 136 public static void nonFatal(final Throwable t, final String action, final Displayable next) { 123 log( t);137 log(BBTracker.class, t, "non-fatal " + action); 124 138 final Alert alert = new Alert("Non-fatal Exception", "Non-fatal Exception while " + action + ": " + 125 139 t.getMessage(), null, AlertType.WARNING); … … 128 142 129 143 public static void fatal(final Throwable t, final String action) { 130 log( t);144 log(BBTracker.class, t, "fatal " + action); 131 145 final BBTracker i = getInstance(); 132 146 i.shutdown(false); … … 152 166 } 153 167 154 public static void log(final Throwable e) { 168 public static void initLog() { 169 if (logStream != null) { 170 return; 171 } 172 final String dirName = Preferences.getInstance().getTrackDirectory(); 173 final String logUrl = "file:///" + dirName + "debug.txt"; 174 try { 175 final FileConnection fileConnection = (FileConnection) Connector.open(logUrl); 176 if (!(fileConnection.exists() && fileConnection.canWrite())) { 177 fileConnection.close(); 178 return; 179 } 180 final OutputStream out = fileConnection.openOutputStream(); 181 logStream = new PrintStream(out); 182 } catch (final Throwable e) { 183 log(BBTracker.class, e, "opening " + logUrl); 184 } 185 } 186 187 public static void setLogActive(final boolean logActive) { 188 if (!logActive && logStream != null) { 189 logStream.close(); 190 logStream = null; 191 } 192 193 final String dirName = Preferences.getInstance().getTrackDirectory(); 194 final String logUrl = "file:///" + dirName + "debug.txt"; 195 try { 196 final FileConnection fileConnection = (FileConnection) Connector.open(logUrl); 197 if (logActive) { 198 if (!fileConnection.exists()) { 199 fileConnection.create(); 200 } 201 final OutputStream out = fileConnection.openOutputStream(); 202 logStream = new PrintStream(out); 203 } else { 204 if (fileConnection.exists()) { 205 fileConnection.delete(); 206 fileConnection.close(); 207 } 208 } 209 } catch (final Throwable e) { 210 log(BBTracker.class, e, "opening " + logUrl); 211 } 212 } 213 214 public static boolean isLogActive() { 215 return logStream != null; 216 } 217 218 public static void log(final Object source, final Throwable e) { 219 log(source, "Exception: " + e.toString()); 220 // this is only useful for debugging in the emulator 155 221 e.printStackTrace(); 156 222 } 157 223 158 public static void log(final String m) { 159 System.err.println(m); 224 public static void log(final Object source, final Throwable e, final String message) { 225 log(source, "Exception <" + message + ">: " + e.toString()); 226 // this is only useful for debugging in the emulator 227 e.printStackTrace(); 228 } 229 230 public static void log(final Object source, final String m) { 231 final String line = new Date() + ": [" + source + "] " + m; 232 System.err.println(line); 233 if (logStream != null) { 234 logStream.println(line); 235 } 160 236 } 161 237 … … 165 241 166 242 protected void pauseApp() { 243 log(this, "pauseApp"); 167 244 } 168 245 169 246 protected void startApp() throws MIDletStateChangeException { 247 log(this, firstStart ? "first startApp" : "startApp"); 170 248 if (firstStart) { 171 249 firstStart = false; -
bbtracker/trunk/src/org/bbtracker/mobile/FileTrackStore.java
r83 r88 34 34 result.addElement(new FileTrackStoreEntry(name, date, fileUrl)); 35 35 } catch (final IOException e) { 36 BBTracker.log("Failed to load info from " + file); 37 BBTracker.log(e); 36 BBTracker.log(this, e, "loading info from " + file); 38 37 } finally { 39 38 if (din != null) { … … 41 40 din.close(); 42 41 } catch (final IOException e) { 43 BBTracker.log( e);42 BBTracker.log(this, e); 44 43 } 45 44 } … … 50 49 return entries; 51 50 } catch (final IOException e) { 52 BBTracker.log( e);51 BBTracker.log(this, e, "loading track list"); 53 52 throw new TrackStoreException(e); 54 53 } finally { … … 58 57 } catch (final IOException e) { 59 58 // can't do anything about it 60 BBTracker.log( e);59 BBTracker.log(this, e); 61 60 } 62 61 } … … 73 72 track.writeToStream(dout); 74 73 } catch (final IOException e) { 75 BBTracker.log( e);74 BBTracker.log(this, e, "saving track"); 76 75 throw new TrackStoreException(e); 77 76 } finally { … … 81 80 } catch (final IOException e) { 82 81 // can't do anything about it 83 BBTracker.log(e);84 82 } 85 83 } … … 89 87 } catch (final IOException e) { 90 88 // can't do anything about it 91 BBTracker.log( e);89 BBTracker.log(this, e); 92 90 } 93 91 } … … 173 171 connection.delete(); 174 172 } catch (final IOException e) { 175 BBTracker.log( e);173 BBTracker.log(this, e, "deleting track"); 176 174 throw new TrackStoreException("Failed to delete track: " + e.getMessage()); 177 175 } … … 185 183 return track; 186 184 } catch (final IOException e) { 187 BBTracker.log( e);185 BBTracker.log(this, e, "loading track"); 188 186 throw new TrackStoreException("Failed to load track: " + e.getMessage()); 189 187 } finally { … … 193 191 } catch (final IOException e) { 194 192 // can't do anything about it 195 BBTracker.log( e);193 BBTracker.log(this, e); 196 194 } 197 195 } -
bbtracker/trunk/src/org/bbtracker/mobile/IconManager.java
r61 r88 91 91 icon = Image.createImage(resourceName); 92 92 } catch (final IOException e) { 93 BBTracker.log( "Couldn't read \"" + resourceName + "\": " + e.getMessage());93 BBTracker.log(this, "Couldn't read \"" + resourceName + "\": " + e.getMessage()); 94 94 icon = NO_ICON; 95 95 } -
bbtracker/trunk/src/org/bbtracker/mobile/RMSTrackStore.java
r73 r88 37 37 dis.close(); 38 38 } catch (final IOException e) { 39 BBTracker.log( e);39 BBTracker.log(this, e); 40 40 } 41 41 i++; … … 55 55 return new TrackStoreEntry[0]; 56 56 } catch (final RecordStoreException e) { 57 BBTracker.log( e);57 BBTracker.log(this, e, "listing tracks"); 58 58 throw new TrackStoreException(e); 59 59 } finally { -
bbtracker/trunk/src/org/bbtracker/mobile/TrackManager.java
r81 r88 280 280 break; 281 281 } catch (final TrackStoreException e) { 282 BBTracker.log( e);282 BBTracker.log(this, e, "saving track"); 283 283 final String msg = e.getMessage(); 284 284 error = error == null ? msg : error + "\n" + msg; … … 305 305 } catch (final IllegalArgumentException e) { 306 306 provider.setLocationListener(locationListener, -1, -1, -1); 307 BBTracker.log( e);307 BBTracker.log(this, e); 308 308 } 309 309 } … … 432 432 state = oldState; 433 433 } catch (final LocationException e) { 434 BBTracker.log( e);434 BBTracker.log(this, e); 435 435 BBTracker.getTimer().schedule(this, DELAY_PER_LEVEL * gpsRecoveryEscalation); 436 436 fireStateChanged(); … … 438 438 } 439 439 } 440 441 440 } 442 441 } -
bbtracker/trunk/src/org/bbtracker/mobile/gui/AboutForm.java
r61 r88 27 27 28 28 public class AboutForm extends Form implements CommandListener { 29 private final Command backCommand; 30 31 private final Command activeDebugCommand; 32 33 private final Command deactiveDebugCommand; 34 29 35 public AboutForm() { 30 36 super("About " + BBTracker.getName()); … … 33 39 "bbTracker is released under the GNU General Public License v2. See http://www.gnu.org/licenses/.")); 34 40 append("Icons have been taken (and sometimes modified) from the Tango Project (http://tango-project.org/) and the Human Icon Theme (Copyright 2004-2006 Canonical Ltd.). Both projects release their icons under the Creative Commons Attribution-ShareAlike 2.5 license. Any modifications I did on those icons are released under the same license."); 35 addCommand(new Command("Back", Command.BACK, 0)); 41 backCommand = new Command("Back", Command.BACK, 0); 42 activeDebugCommand = new Command("Activate Debug Log", Command.SCREEN, 1); 43 deactiveDebugCommand = new Command("Deactivate Debug Log", Command.SCREEN, 1); 44 addCommand(backCommand); 45 updateDebugCommands(); 36 46 setCommandListener(this); 37 47 } 38 48 49 private void updateDebugCommands() { 50 removeCommand(activeDebugCommand); 51 removeCommand(deactiveDebugCommand); 52 addCommand(BBTracker.isLogActive() ? deactiveDebugCommand : activeDebugCommand); 53 } 54 39 55 public void commandAction(final Command command, final Displayable source) { 40 BBTracker.getInstance().showMainCanvas(); 56 if (command == backCommand) { 57 BBTracker.getInstance().showMainCanvas(); 58 } else if (command == deactiveDebugCommand) { 59 BBTracker.setLogActive(false); 60 updateDebugCommands(); 61 } else if (command == activeDebugCommand) { 62 BBTracker.setLogActive(true); 63 updateDebugCommands(); 64 } 41 65 } 42 66 -
bbtracker/trunk/src/org/bbtracker/mobile/gui/MainCanvas.java
r85 r88 292 292 nextDisplayable = this; 293 293 } else { 294 BBTracker.log( "Unknown command: " + command + " <" + command.getLabel() + "/" + command.getLongLabel()+295 ">");294 BBTracker.log(this, "Unknown command: " + command + " <" + command.getLabel() + "/" + 295 command.getLongLabel() + ">"); 296 296 nextDisplayable = this; 297 297 } -
bbtracker/trunk/src/org/bbtracker/mobile/gui/OptionsForm.java
r82 r88 194 194 } catch (final NumberFormatException e) { 195 195 // should not happen 196 BBTracker.log( e);196 BBTracker.log(this, e, "parsing sampleInterval: " + sampleField.getString()); 197 197 } 198 198 pref.setStartAction(startTypeGroup.getSelectedIndex()); 199 199 pref.setTrackDirectory(directoryField.getString()); 200 BBTracker.initLog(); 200 201 201 202 for (int i = 0; i < Preferences.EXPORT_FORMATS.length; i++) { -
bbtracker/trunk/src/org/bbtracker/mobile/gui/StatusTile.java
r62 r88 89 89 twoLineLayout = fitsTwoLineLayout(width); 90 90 if (!twoLineLayout && width < ((MARGIN + latWidth) * 2 + MINIMAL_GAP)) { 91 BBTracker.log( "onResize: Setting Font size to small, because even three lines overlap!");91 BBTracker.log(this, "onResize: Setting Font size to small, because even three lines overlap!"); 92 92 setFontSize(Font.SIZE_SMALL); 93 93 } … … 199 199 lineCount = 3; 200 200 if (!fitsThreeLineLayout(width)) { 201 BBTracker.log("getPreferredHeight: Setting Font size to small, because even three lines overlap!"); 201 BBTracker 202 .log(this, "getPreferredHeight: Setting Font size to small, because even three lines overlap!"); 202 203 setFontSize(Font.SIZE_SMALL); 203 204 } -
bbtracker/trunk/src/org/bbtracker/mobile/gui/TracksForm.java
r75 r88 107 107 loadEntries(); 108 108 } catch (final TrackStoreException e) { 109 BBTracker.log( e);109 BBTracker.log(this, e, "deleting track and listing tracks"); 110 110 final Alert alert = new Alert("Couldn't delete Track.", "The track " + tse.getName() + 111 111 " couldn't be deleted: " + e.getMessage(), null, AlertType.INFO); … … 125 125 track = tse.loadTrack(); 126 126 } catch (final TrackStoreException e) { 127 BBTracker.log( e);127 BBTracker.log(this, e, "loading track"); 128 128 final Alert alert = new Alert("Couldn't load Track.", "The track " + tse.getName() + 129 129 " couldn't be loaded: " + e.getMessage(), null, AlertType.INFO);
Note: See TracChangeset
for help on using the changeset viewer.