Changeset 36
- Timestamp:
- 07/28/07 19:48:14 (5 years ago)
- Files:
-
- 3 added
- 5 edited
-
bbtracker/trunk/src/org/bbtracker/mobile/Preferences.java (modified) (7 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/OptionsForm.java (modified) (4 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/StatusTile.java (modified) (2 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/TrackTile.java (modified) (6 diffs)
-
bbtracker_common/trunk/src/org/bbtracker/ImperialUnitConverter.java (added)
-
bbtracker_common/trunk/src/org/bbtracker/MetricUnitConverter.java (added)
-
bbtracker_common/trunk/src/org/bbtracker/UnitConverter.java (added)
-
bbtracker_common/trunk/src/org/bbtracker/Utils.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bbtracker/trunk/src/org/bbtracker/mobile/Preferences.java
r17 r36 13 13 import javax.microedition.rms.RecordStoreNotFoundException; 14 14 15 import org.bbtracker.ImperialUnitConverter; 16 import org.bbtracker.MetricUnitConverter; 17 import org.bbtracker.UnitConverter; 18 15 19 public class Preferences { 16 20 private static final String RECORD_STORE_NAME = "Preferences"; … … 24 28 public static String[] START_ACTIONS = new String[] { "Do nothing", "Initialize GPS", "Start new track" }; 25 29 30 public static final int EXPORT_KML = 0; 31 32 public static final int EXPORT_GPx = 1; 33 26 34 public static String[] EXPORT_FORMATS = new String[] { "KML (Google Earth)", "GPX" }; 35 36 public static final int UNITS_METRIC = 0; 37 38 public static final int UNITS_IMPERIAL = 1; 39 40 public static String[] UNITS = new String[] { "Metric (km/h, km, m)", "Imperial (mph, miles, feet)" }; 27 41 28 42 private static Preferences instance; … … 50 64 private int exportFormats = 0x03; // export format 0 and 1 are set 51 65 66 private int units = UNITS_METRIC; 67 52 68 private String exportDirectory; 69 70 private UnitConverter unitConverter; 53 71 54 72 private Preferences() { … … 69 87 public void setStartAction(final int startAction) { 70 88 this.startAction = startAction; 89 } 90 91 public String getExportDirectory() { 92 return exportDirectory; 93 } 94 95 public void setExportDirectory(final String exportDirectory) { 96 this.exportDirectory = exportDirectory; 97 } 98 99 public void setExportFormat(final int index, final boolean value) { 100 if (index >= EXPORT_FORMATS.length || index < 0) { 101 throw new IllegalArgumentException(); 102 } 103 if (value) { 104 exportFormats |= 1 << index; 105 } else { 106 exportFormats &= ~(1 << index); 107 } 108 } 109 110 public boolean getExportFormat(final int index) { 111 return (exportFormats & (1 << index)) != 0; 112 } 113 114 public int getUnits() { 115 return units; 116 } 117 118 public void setUnits(final int units) { 119 if (units != UNITS_METRIC && units != UNITS_IMPERIAL) { 120 throw new IllegalArgumentException(); 121 } 122 this.units = units; 123 unitConverter = null; 124 } 125 126 public UnitConverter getUnitsConverter() { 127 if (unitConverter == null) { 128 switch (units) { 129 case UNITS_METRIC: 130 unitConverter = new MetricUnitConverter(); 131 break; 132 case UNITS_IMPERIAL: 133 unitConverter = new ImperialUnitConverter(); 134 break; 135 default: 136 throw new IllegalStateException(); 137 } 138 } 139 return unitConverter; 71 140 } 72 141 … … 103 172 } 104 173 exportFormats = in.readInt(); 174 units = in.readInt(); 105 175 106 176 in.close(); … … 140 210 } 141 211 out.writeInt(exportFormats); 212 out.writeInt(units); 142 213 143 214 out.close(); … … 168 239 } 169 240 } 170 171 public String getExportDirectory() {172 return exportDirectory;173 }174 175 public void setExportDirectory(final String exportDirectory) {176 this.exportDirectory = exportDirectory;177 }178 179 public void setExportFormat(final int index, final boolean value) {180 if (index >= EXPORT_FORMATS.length || index < 0) {181 throw new IllegalArgumentException();182 }183 if (value) {184 exportFormats |= 1 << index;185 } else {186 exportFormats &= ~(1 << index);187 }188 }189 190 public boolean getExportFormat(final int index) {191 return (exportFormats & (1 << index)) != 0;192 }193 241 } -
bbtracker/trunk/src/org/bbtracker/mobile/gui/OptionsForm.java
r24 r36 34 34 private final ChoiceGroup exportFormatGroup; 35 35 36 private final ChoiceGroup unitsGroup; 37 36 38 public OptionsForm(final TrackManager trackManager) { 37 39 super("Options"); … … 43 45 sampleField = new TextField("Sample Interval in seconds: ", String.valueOf(pref.getSampleInterval()), 5, 44 46 TextField.NUMERIC); 45 startTypeGroup = new ChoiceGroup("Startup action: ", Choice.EXCLUSIVE, Preferences.START_ACTIONS, null); 47 48 unitsGroup = new ChoiceGroup("Units: ", Choice.POPUP, Preferences.UNITS, null); 49 unitsGroup.setSelectedIndex(pref.getUnits(), true); 50 51 startTypeGroup = new ChoiceGroup("Startup action: ", Choice.POPUP, Preferences.START_ACTIONS, null); 46 52 startTypeGroup.setSelectedIndex(pref.getStartAction(), true); 53 47 54 directoryField = new TextField("Export directory: ", pref.getExportDirectory(), 100, TextField.URL); 48 55 browseCommand = new Command("Browse", Command.ITEM, 1); … … 56 63 57 64 append(sampleField); 65 append(unitsGroup); 58 66 append(startTypeGroup); 59 67 append(directoryField); … … 80 88 pref.setExportFormat(i, exportFormatGroup.isSelected(i)); 81 89 } 90 91 pref.setUnits(unitsGroup.getSelectedIndex()); 82 92 83 93 pref.store(); -
bbtracker/trunk/src/org/bbtracker/mobile/gui/StatusTile.java
r31 r36 6 6 import org.bbtracker.Track; 7 7 import org.bbtracker.TrackPoint; 8 import org.bbtracker.UnitConverter; 8 9 import org.bbtracker.Utils; 10 import org.bbtracker.mobile.Preferences; 9 11 import org.bbtracker.mobile.TrackManager; 10 12 … … 50 52 point = (pi + 1) + "/" + track.getPointCount(); 51 53 } 52 final String lon; 53 final String lat; 54 final String speed; 55 final String course; 56 final String elevation; 54 double lonValue = Double.NaN; 55 double latValue = Double.NaN; 56 float speedValue = Float.NaN; 57 float courseValue = Float.NaN; 58 float elevationValue = Float.NaN; 59 double lengthValue = Double.NaN; 57 60 if (p != null) { 58 lon = Utils.longitudeToString(p.getLongitude()); 59 lat = Utils.latitudeToString(p.getLatitude()); 60 speed = Utils.speedToString(p.getSpeed()); 61 course = Utils.courseToString(p.getCourse()); 62 elevation = Utils.elevationToString(p.getElevation()); 63 } else { 64 lon = "-"; 65 lat = "-"; 66 speed = "- km/h"; 67 course = "-" + Utils.DEGREE; 68 elevation = "-m"; 61 lonValue = p.getLongitude(); 62 latValue = p.getLatitude(); 63 speedValue = p.getSpeed(); 64 courseValue = p.getCourse(); 65 elevationValue = p.getElevation(); 69 66 } 70 final String length;71 67 if (track != null) { 72 length = Utils.distanceToString(track.getLength()); 73 } else { 74 length = "-m"; 68 lengthValue = track.getLength(); 75 69 } 70 71 final String lon = Utils.longitudeToString(lonValue); 72 final String lat = Utils.latitudeToString(latValue); 73 final String course = Utils.courseToString(courseValue); 74 75 final UnitConverter unit = Preferences.getInstance().getUnitsConverter(); 76 final String speed = unit.speedToString(speedValue); 77 final String elevation = unit.elevationToString(elevationValue); 78 final String length = unit.distanceToString(lengthValue); 76 79 77 80 int y = MARGIN; -
bbtracker/trunk/src/org/bbtracker/mobile/gui/TrackTile.java
r19 r36 10 10 import org.bbtracker.TrackSegment; 11 11 import org.bbtracker.Utils; 12 import org.bbtracker.UnitConverter.ScaleConfiguration; 13 import org.bbtracker.mobile.Preferences; 12 14 13 15 public class TrackTile extends Tile { … … 30 32 private static final int SCALE_HEIGTH = 5; 31 33 34 private final Track track; 35 32 36 private double minimumLongitude, minimumLatitude; 33 37 34 38 private double scale; 35 39 36 private final Track track;37 38 40 private TrackPoint currentPoint; 39 41 40 42 private int scaleSizeInPixel; 41 43 42 private int scaleSize; 44 private String scaleLabelCenter; 45 46 private String scaleLabelRight; 43 47 44 48 public TrackTile(final Track track) { … … 87 91 .distance(minimumLatitude, minimumLongitude, minimumLatitude, maximumLongitude); 88 92 if (widthInMeter < 1) { 89 scaleSize = 0; 90 return; 91 } 92 93 final int metersAvailableForScale = (int) (widthInMeter * 0.9); 94 95 scaleSize = 1; 96 while (scaleSize < metersAvailableForScale / 10) { 97 scaleSize = scaleSize * 10; 98 } 99 if (scaleSize * 5 < metersAvailableForScale) { 100 scaleSize = scaleSize * 5; 101 } else if (scaleSize * 2 < metersAvailableForScale) { 102 scaleSize = scaleSize * 2; 103 } 104 scaleSizeInPixel = (int) (scaleSize * (width / widthInMeter)); 93 scaleSizeInPixel = 0; 94 return; 95 } 96 97 final double availableLengthInMeter = widthInMeter * 0.9; 98 99 final ScaleConfiguration conf = Preferences.getInstance().getUnitsConverter().getScaleConfiguration( 100 availableLengthInMeter); 101 102 switch (conf.lengthInUnits) { 103 case 1: 104 scaleLabelCenter = "0.5"; 105 break; 106 case 5: 107 scaleLabelCenter = "2.5"; 108 break; 109 default: 110 scaleLabelCenter = String.valueOf(conf.lengthInUnits / 2); 111 } 112 scaleLabelRight = conf.lengthInUnits + " " + conf.unit; 113 114 scaleSizeInPixel = (int) ((conf.lengthInMeter / widthInMeter) * width); 105 115 } 106 116 … … 116 126 return; 117 127 } 118 final int segmentCount = track.getSegmentCount(); 119 if (segmentCount < 1 || track.getSegment(0).getPointCount() == 0) { 128 if (track.getPointCount() == 0) { 120 129 return; 121 130 } … … 183 192 184 193 private void drawScale(final Graphics g) { 185 if (scaleSize == 0) { 186 return; 187 } 188 189 String unit; 190 int displayScaleSize; 191 192 if (scaleSize >= 1000) { 193 unit = "km"; 194 displayScaleSize = scaleSize / 1000; 195 } else { 196 unit = "m"; 197 displayScaleSize = scaleSize; 198 } 199 200 final String leftLabel = "0"; 201 final String middleLabel; 202 switch (displayScaleSize) { 203 case 1: 204 middleLabel = "0.5"; 205 break; 206 case 5: 207 middleLabel = "2.5"; 208 break; 209 default: 210 middleLabel = String.valueOf(displayScaleSize / 2); 211 } 212 final String rightLabel = displayScaleSize + " " + unit; 194 if (scaleSizeInPixel == 0) { 195 return; 196 } 213 197 214 198 final Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); 215 199 216 final int left = (font.stringWidth( leftLabel) / 2) + 2;200 final int left = (font.stringWidth("0") / 2) + 2; 217 201 g.setFont(font); 218 202 g.setColor(0x00000000); … … 221 205 222 206 final int textBottom = height - 4 - SCALE_HEIGTH; 223 g.drawString( leftLabel, left, textBottom, Graphics.BOTTOM | Graphics.HCENTER);224 g.drawString( middleLabel, left + (scaleSizeInPixel / 2), textBottom, Graphics.BOTTOM | Graphics.HCENTER);225 g.drawString( rightLabel, left + scaleSizeInPixel, textBottom, Graphics.BOTTOM | Graphics.HCENTER);207 g.drawString("0", left, textBottom, Graphics.BOTTOM | Graphics.HCENTER); 208 g.drawString(scaleLabelCenter, left + (scaleSizeInPixel / 2), textBottom, Graphics.BOTTOM | Graphics.HCENTER); 209 g.drawString(scaleLabelRight, left + scaleSizeInPixel, textBottom, Graphics.BOTTOM | Graphics.HCENTER); 226 210 } 227 211 } -
bbtracker_common/trunk/src/org/bbtracker/Utils.java
r30 r36 16 16 public static final char SECOND = '\u2033'; 17 17 18 private static final float MS_TO_KMH_FACTOR = 3.6f;19 20 18 private static final double WGS84_A = 6378137; 21 19 … … 37 35 38 36 public static String degreesToString(final double value, final char positiveChar, final char negativeChar) { 37 if (Double.isNaN(value)) { 38 return "-"; 39 } 39 40 char c; 40 41 double d; … … 131 132 } 132 133 133 /**134 * @param speed135 * the speed in m/s136 * @return a human readable String containing the speed in km/h.137 */138 public static String speedToString(final float speed) {139 final float value = speed * MS_TO_KMH_FACTOR;140 return String.valueOf(((int) (value * 10)) / 10f) + " km/h";141 }142 143 public static String courseToString(final float course) {144 if (Float.isNaN(course)) {145 return "???" + DEGREE;146 } else {147 return String.valueOf((int) (Math.floor(course + 0.5d))) + DEGREE;148 }149 }150 151 134 public static String dateToString(final Date date) { 152 135 final String orig = date.toString(); … … 203 186 } 204 187 205 public static String elevationToString(final float elevation) { 206 return ((int) elevation) + "m"; 207 } 208 209 public static String distanceToString(final double length) { 210 if (length < 1000) { 211 return ((int) length) + "m"; 188 /* 189 * (non-Javadoc) 190 * 191 * @see org.bbtracker.UnitConverter#courseToString(float) 192 */ 193 public static String courseToString(final float course) { 194 if (Float.isNaN(course)) { 195 return "???" + DEGREE; 212 196 } else { 213 return String.valueOf(( (int) (length / 100)) / 10f) + "km";197 return String.valueOf((int) (Math.floor(course + 0.5d))) + DEGREE; 214 198 } 215 199 }
Note: See TracChangeset
for help on using the changeset viewer.