Changeset 14
- Timestamp:
- 07/25/07 21:25:52 (6 years ago)
- Location:
- bbtracker/trunk/src/org/bbtracker/mobile
- Files:
-
- 4 edited
-
TrackListener.java (modified) (1 diff)
-
TrackManager.java (modified) (7 diffs)
-
gui/MainCanvas.java (modified) (2 diffs)
-
gui/StatusTile.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bbtracker/trunk/src/org/bbtracker/mobile/TrackListener.java
r4 r14 6 6 public void newPoint(TrackPoint newPoint, boolean boundsChanged, boolean newSegment); 7 7 8 public void currentPointChanged(final TrackPoint newPoint, int newIndex); 9 8 10 public void stateChanged(int newState); 9 11 } -
bbtracker/trunk/src/org/bbtracker/mobile/TrackManager.java
r7 r14 35 35 private TrackPoint currentPoint; 36 36 37 private int currentPointIndex = -1; 38 37 39 private boolean trackInterrupted; 38 40 … … 60 62 } 61 63 64 public int getCurrentPointIndex() { 65 return currentPointIndex; 66 } 67 62 68 public Track getTrack() { 63 69 return track; … … 68 74 return; 69 75 } 70 boolean boundsChanged = false;71 boolean newSegment = false;72 76 if (location.isValid()) { 77 boolean boundsChanged = false; 78 boolean newSegment = false; 73 79 if (trackInterrupted == true) { 74 80 newSegment = true; … … 79 85 coordinates.getLongitude(), coordinates.getAltitude(), location.getSpeed(), location.getCourse(), 80 86 false); 81 if (track != null && state != STATE_STATIC) { 87 if (track != null) { 88 currentPointIndex = track.getPointCount(); 82 89 boundsChanged = track.addPoint(trackPoint); 83 90 } 84 91 currentPoint = trackPoint; 85 92 fireNewPoint(currentPoint, boundsChanged, newSegment); 93 fireCurrentPointChanged(); 86 94 providerStateChanged(provider, provider.getState()); 87 95 } else { 88 fireNewPoint(null, boundsChanged, newSegment);96 fireNewPoint(null, false, false); 89 97 } 90 98 } … … 142 150 } 143 151 152 private void fireCurrentPointChanged() { 153 if (listeners == null) { 154 return; 155 } 156 157 final Enumeration e = listeners.elements(); 158 while (e.hasMoreElements()) { 159 ((TrackListener) e.nextElement()).currentPointChanged(currentPoint, currentPointIndex); 160 } 161 } 162 144 163 /** 145 164 * Start a new track. … … 156 175 track = new Track(name); 157 176 state = STATE_TRACKING; 177 178 currentPointIndex = -1; 179 currentPoint = null; 180 fireStateChanged(); 181 fireCurrentPointChanged(); 158 182 } 159 183 … … 174 198 if (track == null || track.getPointCount() == 0) { 175 199 currentPoint = null; 200 currentPointIndex = -1; 176 201 } else { 177 202 currentPoint = track.getPoint(0); 178 } 203 currentPointIndex = 0; 204 } 205 fireStateChanged(); 206 fireCurrentPointChanged(); 179 207 } 180 208 -
bbtracker/trunk/src/org/bbtracker/mobile/gui/MainCanvas.java
r7 r14 87 87 88 88 public void newPoint(final TrackPoint newPoint, final boolean boundsChanged, final boolean newSegment) { 89 trackTile.setCurrentPoint(newPoint);90 89 if (boundsChanged) { 91 90 trackTile.onResize(); // XXX Make that nicer 92 91 } 93 if (isShown()) { 94 repaint(); 95 } 92 repaint(); 93 } 94 95 public void currentPointChanged(final TrackPoint newPoint, final int newIndex) { 96 trackTile.setCurrentPoint(newPoint); 97 repaint(); 96 98 } 97 99 98 100 public void stateChanged(final int newState) { 99 if (isShown()) { 100 repaint(); 101 } 101 repaint(); 102 102 } 103 103 … … 119 119 setTrack(newTrack); 120 120 } 121 trackTile.onResize(); 121 122 manager.addPointListener(this); 122 123 } -
bbtracker/trunk/src/org/bbtracker/mobile/gui/StatusTile.java
r4 r14 10 10 11 11 public class StatusTile extends Tile { 12 13 private static final int TOP_LEFT = Graphics.TOP | Graphics.LEFT; 14 15 private static final String LABEL_LONGITUDE = "Long.: "; 16 17 private static final String LABEL_LATITUDE = "Lat.: "; 18 19 private static final String LABEL_POINTS = "Points: "; 20 21 private static final String LABEL_AGE = "Age: "; 22 23 private static final String LABEL_SPEED = "Speed: "; 24 25 private static final String LABEL_COURSE = "Course: "; 12 public static final String MAX_DEGREE_STRING = "99" + Utils.DEGREE + "99" + Utils.MINUTE + "99.99" + Utils.SECOND + 13 "W"; 26 14 27 15 private static final int MARGIN = 2; 28 16 17 private static final int GAP = 5; 18 29 19 private final TrackManager manager; 30 20 31 private final Font labelFont;21 private final Font font; 32 22 33 private final Font valueFont; 34 35 private final int lineHeight; 36 37 private final int leftLabelWidth; 38 39 private final int rightLabelWidth; 40 41 private final int rightValueWidth; 23 private final int latWidth; 42 24 43 25 public StatusTile(final TrackManager manager) { 44 26 this.manager = manager; 45 labelFont = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL); 46 valueFont = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL); 47 lineHeight = Math.max(labelFont.getHeight(), valueFont.getHeight()); 48 49 int w; 50 51 w = maxWidth(labelFont, LABEL_LATITUDE, -1); 52 w = maxWidth(labelFont, LABEL_LONGITUDE, w); 53 w = maxWidth(labelFont, LABEL_SPEED, w); 54 leftLabelWidth = w; 55 56 w = maxWidth(labelFont, LABEL_POINTS, -1); 57 w = maxWidth(labelFont, LABEL_AGE, w); 58 w = maxWidth(labelFont, LABEL_COURSE, w); 59 rightLabelWidth = w; 60 61 rightValueWidth = valueFont.stringWidth("9999"); 62 } 63 64 private static final int maxWidth(final Font f, final String s, final int prevMax) { 65 final int w = f.stringWidth(s); 66 return Math.max(prevMax, w); 27 font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL); 28 latWidth = font.stringWidth(MAX_DEGREE_STRING); 67 29 } 68 30 … … 70 32 final Track track = manager.getTrack(); 71 33 final TrackPoint p = manager.getCurrentPoint(); 34 final int pi = manager.getCurrentPointIndex(); 72 35 73 36 g.setColor(0x00ffffff); 74 37 g.fillRect(0, 0, width, height); 75 38 g.setColor(0x00000000); 76 g.setFont( labelFont);39 g.setFont(font); 77 40 78 final String points = track == null ? "-" : String.valueOf(track.getPointCount()); 41 final String point; 42 if (pi == -1) { 43 point = "-"; 44 } else { 45 point = (pi + 1) + "/" + track.getPointCount(); 46 } 79 47 final String lon; 80 48 final String lat; 81 final String age;82 49 final String speed; 83 50 final String course; 51 final String elevation; 84 52 if (p != null) { 85 53 lon = Utils.longitudeToString(p.getLongitude()); … … 87 55 speed = Utils.speedToString(p.getSpeed()); 88 56 course = Utils.courseToString(p.getCourse()); 89 age = String.valueOf(((int) (System.currentTimeMillis() - p.getTimestamp()) / 100) / 10f) + 's';57 elevation = Utils.elevationToString(p.getElevation()); 90 58 } else { 91 59 lon = "-"; 92 60 lat = "-"; 93 speed = "- ";94 course = "-" ;95 age = "-";61 speed = "- km/h"; 62 course = "-" + Utils.DEGREE; 63 elevation = "-m"; 96 64 } 97 65 98 66 int y = MARGIN; 99 int left = MARGIN;100 int right = width - rightLabelWidth - rightValueWidth - MARGIN;101 g.setFont(labelFont);102 g.drawString(LABEL_LONGITUDE, left, y, TOP_LEFT);103 g.drawString(LABEL_POINTS, right, y, TOP_LEFT);104 y += lineHeight;105 g.drawString(LABEL_LATITUDE, left, y, TOP_LEFT);106 g.drawString(LABEL_AGE, right, y, TOP_LEFT);107 y += lineHeight;108 g.drawString(LABEL_SPEED, left, y, TOP_LEFT);109 g.drawString(LABEL_COURSE, right, y, TOP_LEFT);110 67 111 left += leftLabelWidth;112 right += rightLabelWidth;113 y =MARGIN;114 g.drawString(lon, left, y, TOP_LEFT); 115 g.drawString( points, right, y, TOP_LEFT);116 y += lineHeight;117 g.drawString( lat, left, y, TOP_LEFT);118 g.drawString(age, right, y, TOP_LEFT);119 y += lineHeight;120 g.drawString( speed, left, y, TOP_LEFT);121 g.drawString( course, right, y, TOP_LEFT);68 final int leftColumn = MARGIN + latWidth; 69 final int middleColumn = MARGIN + latWidth * 2 + GAP; 70 final int rightBorder = width - MARGIN; 71 72 g.drawString(lon, leftColumn, y, Graphics.TOP | Graphics.RIGHT); 73 g.drawString(lat, middleColumn, y, Graphics.TOP | Graphics.RIGHT); 74 g.drawString(elevation, rightBorder, y, Graphics.TOP | Graphics.RIGHT); 75 y += font.getHeight(); 76 g.drawString(speed, leftColumn, y, Graphics.TOP | Graphics.RIGHT); 77 g.drawString(course, middleColumn, y, Graphics.TOP | Graphics.RIGHT); 78 g.drawString(point, rightBorder, y, Graphics.TOP | Graphics.RIGHT); 122 79 } 123 80 124 81 public int getPreferredHeight() { 125 return MARGIN + lineHeight * 3 + MARGIN;82 return (MARGIN + font.getHeight()) * 2; 126 83 } 127 84 }
Note: See TracChangeset
for help on using the changeset viewer.