Changeset 36 for bbtracker/trunk/src/org/bbtracker/mobile/Preferences.java
- Timestamp:
- 07/28/07 19:48:14 (5 years ago)
- File:
-
- 1 edited
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 }
Note: See TracChangeset
for help on using the changeset viewer.