diff options
| author | 2010-01-17 19:06:51 -0500 | |
|---|---|---|
| committer | 2010-01-17 19:09:35 -0500 | |
| commit | 63ce8e817c9b800b4f08b64c343e533783961b6e (patch) | |
| tree | 36499efa89f6956b58d5594ce997b623589589a3 | |
| parent | ff58b5770514521ebdd48f500d8dc121a42d7eb2 (diff) | |
Make the space between the time and the AM/PM smaller by putting preceding whitespace inside the
span.
Also cache the SimpleDateFormat object because those are relatively expensive.
| -rw-r--r-- | services/java/com/android/server/status/StatusBarPolicy.java | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/services/java/com/android/server/status/StatusBarPolicy.java b/services/java/com/android/server/status/StatusBarPolicy.java index 42c02540dbc1..f5aeaf06a3c7 100644 --- a/services/java/com/android/server/status/StatusBarPolicy.java +++ b/services/java/com/android/server/status/StatusBarPolicy.java @@ -88,6 +88,8 @@ public class StatusBarPolicy { // clock private Calendar mCalendar; + private String mClockFormatString; + private SimpleDateFormat mClockFormat; private IBinder mClockIcon; private IconData mClockData; @@ -546,37 +548,48 @@ public class StatusBarPolicy { res = R.string.twelve_hour_time_format; } - String format = mContext.getString(res); + final char MAGIC1 = '\uEF00'; + final char MAGIC2 = '\uEF01'; - /* - * Search for an unquoted "a" in the format string, so we can - * add dummy characters around it to let us find it again after - * formatting and change its size. - */ - int a = -1; - boolean quoted = false; - for (int i = 0; i < format.length(); i++) { - char c = format.charAt(i); + SimpleDateFormat sdf; + String format = mContext.getString(res); + if (!format.equals(mClockFormatString)) { + /* + * Search for an unquoted "a" in the format string, so we can + * add dummy characters around it to let us find it again after + * formatting and change its size. + */ + int a = -1; + boolean quoted = false; + for (int i = 0; i < format.length(); i++) { + char c = format.charAt(i); + + if (c == '\'') { + quoted = !quoted; + } - if (c == '\'') { - quoted = !quoted; + if (!quoted && c == 'a') { + a = i; + break; + } } - if (!quoted && c == 'a') { - a = i; - break; + if (a >= 0) { + // Move a back so any whitespace before the AM/PM is also in the alternate size. + final int b = a; + while (a > 0 && Character.isWhitespace(format.charAt(a-1))) { + a--; + } + format = format.substring(0, a) + MAGIC1 + format.substring(a, b) + + "a" + MAGIC2 + format.substring(b + 1); } - } - - final char MAGIC1 = '\uEF00'; - final char MAGIC2 = '\uEF01'; - if (a >= 0) { - format = format.substring(0, a) + MAGIC1 + "a" + MAGIC2 + - format.substring(a + 1); + mClockFormat = sdf = new SimpleDateFormat(format); + mClockFormatString = format; + } else { + sdf = mClockFormat; } - - String result = new SimpleDateFormat(format).format(mCalendar.getTime()); + String result = sdf.format(mCalendar.getTime()); int magic1 = result.indexOf(MAGIC1); int magic2 = result.indexOf(MAGIC2); |