Ignore:
Timestamp:
08/24/07 22:05:08 (5 years ago)
Author:
saua
Message:

Implement details screen (issue #18)

File:
1 edited

Legend:

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

    r88 r93  
    4242 
    4343public class OptionsForm extends Form implements CommandListener, ItemCommandListener { 
     44        private static final String[] FONT_SIZE_NAMES = new String[] { "Small", "Medium", "Large" }; 
     45 
    4446        private final TrackManager trackManager; 
    4547 
     
    6163 
    6264        private final ChoiceGroup statusFontSizeGroup; 
     65 
     66        private final ChoiceGroup detailsFontSizeGroup; 
    6367 
    6468        public OptionsForm(final TrackManager trackManager) { 
     
    7579                unitsGroup.setSelectedIndex(pref.getUnits(), true); 
    7680 
    77                 statusFontSizeGroup = new ChoiceGroup("Status text size: ", Choice.POPUP, new String[] { "Small", "Medium", 
    78                                 "Large" }, null); 
    79                 int selectedFontSizeItem; 
    80                 switch (pref.getStatusFontSize()) { 
    81                 case Font.SIZE_SMALL: 
    82                         selectedFontSizeItem = 0; 
    83                         break; 
    84                 case Font.SIZE_MEDIUM: 
    85                         selectedFontSizeItem = 1; 
    86                         break; 
    87                 case Font.SIZE_LARGE: 
    88                         selectedFontSizeItem = 2; 
    89                         break; 
    90                 default: 
    91                         selectedFontSizeItem = 1; 
    92                 } 
    93                 statusFontSizeGroup.setSelectedIndex(selectedFontSizeItem, true); 
     81                statusFontSizeGroup = new ChoiceGroup("Status text size: ", Choice.POPUP, FONT_SIZE_NAMES, null); 
     82                final int statusFontSizeIndex = getSelectedFontIndex(pref.getStatusFontSize()); 
     83                statusFontSizeGroup.setSelectedIndex(statusFontSizeIndex, true); 
     84 
     85                detailsFontSizeGroup = new ChoiceGroup("Details text size: ", Choice.POPUP, FONT_SIZE_NAMES, null); 
     86                final int detailsFontSizeIndex = getSelectedFontIndex(pref.getDetailsFontSize()); 
     87                detailsFontSizeGroup.setSelectedIndex(detailsFontSizeIndex, true); 
    9488 
    9589                startTypeGroup = new ChoiceGroup("Startup action: ", Choice.POPUP, Preferences.START_ACTIONS, null); 
     
    113107                append(unitsGroup); 
    114108                append(statusFontSizeGroup); 
     109                append(detailsFontSizeGroup); 
    115110                append(startTypeGroup); 
    116111                append(directoryField); 
     
    123118                addCommand(cancelCommand); 
    124119                setCommandListener(this); 
     120        } 
     121 
     122        private int getSelectedFontIndex(final int fontSize) { 
     123                int selectedIndex; 
     124                switch (fontSize) { 
     125                case Font.SIZE_SMALL: 
     126                        selectedIndex = 0; 
     127                        break; 
     128                case Font.SIZE_MEDIUM: 
     129                        selectedIndex = 1; 
     130                        break; 
     131                case Font.SIZE_LARGE: 
     132                        selectedIndex = 2; 
     133                        break; 
     134                default: 
     135                        selectedIndex = 1; 
     136                } 
     137                return selectedIndex; 
     138        } 
     139 
     140        private int getFontSize(final int selectedIndex) { 
     141                int fontSize; 
     142                switch (selectedIndex) { 
     143                case 0: 
     144                        fontSize = Font.SIZE_SMALL; 
     145                        break; 
     146                case 1: 
     147                        fontSize = Font.SIZE_MEDIUM; 
     148                        break; 
     149                case 2: 
     150                        fontSize = Font.SIZE_LARGE; 
     151                        break; 
     152                default: 
     153                        throw new IllegalStateException(); 
     154                } 
     155                return fontSize; 
    125156        } 
    126157 
     
    206237                        pref.setUnits(unitsGroup.getSelectedIndex()); 
    207238 
    208                         final int newFontSize; 
    209                         switch (statusFontSizeGroup.getSelectedIndex()) { 
    210                         case 0: 
    211                                 newFontSize = Font.SIZE_SMALL; 
    212                                 break; 
    213                         case 1: 
    214                                 newFontSize = Font.SIZE_MEDIUM; 
    215                                 break; 
    216                         case 2: 
    217                                 newFontSize = Font.SIZE_LARGE; 
    218                                 break; 
    219                         default: 
    220                                 throw new IllegalStateException(); 
    221                         } 
    222                         pref.setStatusFontSize(newFontSize); 
     239                        final int statusFontSize = getFontSize(statusFontSizeGroup.getSelectedIndex()); 
     240                        pref.setStatusFontSize(statusFontSize); 
     241 
     242                        final int detailsFontSize = getFontSize(detailsFontSizeGroup.getSelectedIndex()); 
     243                        pref.setDetailsFontSize(detailsFontSize); 
    223244 
    224245                        pref.store(); 
Note: See TracChangeset for help on using the changeset viewer.