Ignore:
Timestamp:
07/28/07 19:48:14 (5 years ago)
Author:
saua
Message:

This should fix Issue #13

File:
1 edited

Legend:

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

    r17 r36  
    1313import javax.microedition.rms.RecordStoreNotFoundException; 
    1414 
     15import org.bbtracker.ImperialUnitConverter; 
     16import org.bbtracker.MetricUnitConverter; 
     17import org.bbtracker.UnitConverter; 
     18 
    1519public class Preferences { 
    1620        private static final String RECORD_STORE_NAME = "Preferences"; 
     
    2428        public static String[] START_ACTIONS = new String[] { "Do nothing", "Initialize GPS", "Start new track" }; 
    2529 
     30        public static final int EXPORT_KML = 0; 
     31 
     32        public static final int EXPORT_GPx = 1; 
     33 
    2634        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)" }; 
    2741 
    2842        private static Preferences instance; 
     
    5064        private int exportFormats = 0x03; // export format 0 and 1 are set 
    5165 
     66        private int units = UNITS_METRIC; 
     67 
    5268        private String exportDirectory; 
     69 
     70        private UnitConverter unitConverter; 
    5371 
    5472        private Preferences() { 
     
    6987        public void setStartAction(final int startAction) { 
    7088                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; 
    71140        } 
    72141 
     
    103172                        } 
    104173                        exportFormats = in.readInt(); 
     174                        units = in.readInt(); 
    105175 
    106176                        in.close(); 
     
    140210                        } 
    141211                        out.writeInt(exportFormats); 
     212                        out.writeInt(units); 
    142213 
    143214                        out.close(); 
     
    168239                } 
    169240        } 
    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         } 
    193241} 
Note: See TracChangeset for help on using the changeset viewer.