Changeset 50


Ignore:
Timestamp:
08/07/07 18:19:01 (6 years ago)
Author:
saua
Message:

update StatusTile? for bigger font size and implement two-line layout

Location:
bbtracker/trunk/src/org/bbtracker/mobile/gui
Files:
2 edited

Legend:

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

    r33 r50  
    5252                super.sizeChanged(w, h); 
    5353 
    54                 final int statusHeight = statusTile.getPreferredHeight(); 
     54                final int statusHeight = statusTile.getPreferredHeight(w); 
    5555                trackTile.resize(0, 0, w, h - (statusHeight + 1)); 
    5656                statusTile.resize(0, h - statusHeight, w, statusHeight); 
  • bbtracker/trunk/src/org/bbtracker/mobile/gui/StatusTile.java

    r36 r50  
    1212 
    1313public class StatusTile extends Tile { 
     14 
     15        /* 
     16         * The MAX_* constants represent the string values that each field can take that take up the maximum amount of 
     17         * horizontal space. 
     18         */ 
    1419        private static final String MAX_DEGREE_STRING = "99" + Utils.DEGREE + "99" + Utils.MINUTE + "99.99" + Utils.SECOND + 
    1520                        "W"; 
     
    1722        private static final String MAX_COURSE_STRING = "399" + Utils.DEGREE; 
    1823 
     24        private static final String MAX_SPEED_STRING = "999.9km/h"; 
     25 
     26        private static final String MAX_ELEVATION_STRING = "9999m"; 
     27 
     28        private static final String MAX_LENGTH_STRING = "9999.9km"; 
     29 
     30        private static final String MAX_POINT_STRING = "9999/9999"; 
     31 
    1932        private static final int MARGIN = 2; 
    2033 
    21         private static final int GAP = 5; 
     34        private static final int MINIMAL_GAP = 5; 
    2235 
    2336        private final TrackManager manager; 
    2437 
    25         private final Font font; 
     38        private Font font; 
    2639 
    27         private final int latWidth; 
     40        private int latWidth; 
    2841 
    29         private final int courseWidth; 
     42        private int courseWidth; 
     43 
     44        private int speedWidth; 
     45 
     46        private int elevationWidth; 
     47 
     48        private int lengthWidth; 
     49 
     50        private int pointWidth; 
     51 
     52        private boolean twoLineLayout = true; 
    3053 
    3154        public StatusTile(final TrackManager manager) { 
    3255                this.manager = manager; 
    33                 font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL); 
     56                setFontSize(Font.SIZE_MEDIUM); 
     57        } 
     58 
     59        private void setFontSize(final int fontSize) { 
     60                font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, fontSize); 
    3461                latWidth = font.stringWidth(MAX_DEGREE_STRING); 
    3562                courseWidth = font.stringWidth(MAX_COURSE_STRING); 
     63                speedWidth = font.stringWidth(MAX_SPEED_STRING); 
     64                elevationWidth = font.stringWidth(MAX_ELEVATION_STRING); 
     65                lengthWidth = font.stringWidth(MAX_LENGTH_STRING); 
     66                pointWidth = font.stringWidth(MAX_POINT_STRING); 
     67                twoLineLayout = fitsTwoLineLayout(width); 
     68        } 
     69 
     70        protected void onResize() { 
     71                twoLineLayout = fitsTwoLineLayout(width); 
     72        } 
     73 
     74        protected boolean fitsTwoLineLayout(final int width) { 
     75                final int twoLineWidth = (MARGIN + MINIMAL_GAP + latWidth) * 2 + lengthWidth; 
     76                return width >= twoLineWidth; 
    3677        } 
    3778 
     
    78119                final String length = unit.distanceToString(lengthValue); 
    79120 
    80                 int y = MARGIN; 
     121                final int line1 = MARGIN; 
     122                final int line2 = line1 + font.getHeight(); 
     123                final int latLonWidth; // the space available for latitude and longitude combined, it's also used for 
     124                // speed/course/elevation 
     125                if (twoLineLayout) { 
     126                        final int spareSpace = width - (MARGIN * 2 + latWidth * 2 + Math.max(lengthWidth, pointWidth)); 
     127                        latLonWidth = latWidth * 2 + spareSpace / 2; 
     128                } else { 
     129                        latLonWidth = width - 2 * MARGIN; 
     130                } 
    81131 
    82                 final int lonPos = MARGIN + latWidth; 
    83                 final int latPos = MARGIN + latWidth * 2 + GAP; 
    84                 final int rightPos = width - MARGIN; 
     132                // longitude / latitude (always on line 1) 
     133                g.drawString(lon, MARGIN + latLonWidth / 2, line1, Graphics.TOP | Graphics.RIGHT); 
     134                g.drawString(lat, MARGIN + latLonWidth, line1, Graphics.TOP | Graphics.RIGHT); 
    85135 
    86                 g.drawString(lon, lonPos, y, Graphics.TOP | Graphics.RIGHT); 
    87                 g.drawString(lat, latPos, y, Graphics.TOP | Graphics.RIGHT); 
    88                 g.drawString(length, rightPos, y, Graphics.TOP | Graphics.RIGHT); 
    89                 y += font.getHeight(); 
    90                 g.drawString(speed, lonPos, y, Graphics.TOP | Graphics.RIGHT); 
    91                 g.drawString(course, lonPos + GAP + GAP + courseWidth, y, Graphics.TOP | Graphics.RIGHT); 
    92                 g.drawString(elevation, latPos, y, Graphics.TOP | Graphics.RIGHT); 
    93                 g.drawString(point, rightPos, y, Graphics.TOP | Graphics.RIGHT); 
     136                final int spaceForCourse = latLonWidth - speedWidth - elevationWidth; 
     137                final int courseX = MARGIN + speedWidth + (spaceForCourse + courseWidth) / 2; 
     138 
     139                // speed / course / elevation (always on line 2) 
     140                g.drawString(speed, MARGIN + speedWidth, line2, Graphics.TOP | Graphics.RIGHT); 
     141                g.drawString(course, courseX, line2, Graphics.TOP | Graphics.RIGHT); 
     142                g.drawString(elevation, MARGIN + latLonWidth, line2, Graphics.TOP | Graphics.RIGHT); 
     143 
     144                final int lengthX; 
     145                int lengthY; 
     146                final int pointX; 
     147                int pointY; 
     148 
     149                if (twoLineLayout) { 
     150                        lengthX = width - MARGIN; 
     151                        lengthY = line1; 
     152                        pointX = lengthX; 
     153                        pointY = line2; 
     154                } else { 
     155                        lengthX = width / 2; 
     156                        lengthY = line2 + font.getHeight(); 
     157                        pointX = width - MARGIN; 
     158                        pointY = lengthY; 
     159                } 
     160                g.drawString(length, lengthX, lengthY, Graphics.TOP | Graphics.RIGHT); 
     161                g.drawString(point, pointX, pointY, Graphics.TOP | Graphics.RIGHT); 
    94162        } 
    95163 
    96         public int getPreferredHeight() { 
    97                 return (MARGIN + font.getHeight()) * 2; 
     164        public void showNotify() { 
     165                // nothing to do 
     166        } 
     167 
     168        public int getPreferredHeight(final int width) { 
     169                final int lineCount = fitsTwoLineLayout(width) ? 2 : 3; 
     170                return MARGIN + font.getHeight() * lineCount + MARGIN; 
    98171        } 
    99172} 
Note: See TracChangeset for help on using the changeset viewer.