diff options
Diffstat (limited to 'src/com/android/calendar/EventRecurrenceFormatter.java')
-rw-r--r-- | src/com/android/calendar/EventRecurrenceFormatter.java | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/com/android/calendar/EventRecurrenceFormatter.java b/src/com/android/calendar/EventRecurrenceFormatter.java index 1d3df701..b9e33fdd 100644 --- a/src/com/android/calendar/EventRecurrenceFormatter.java +++ b/src/com/android/calendar/EventRecurrenceFormatter.java @@ -28,6 +28,10 @@ import java.util.Calendar; public class EventRecurrenceFormatter { + + private static int[] mMonthRepeatByDayOfWeekIds; + private static String[][] mMonthRepeatByDayOfWeekStrs; + public static String getRepeatString(Context context, Resources r, EventRecurrence recurrence, boolean includeEndString) { String endString = ""; @@ -99,11 +103,17 @@ public class EventRecurrenceFormatter } case EventRecurrence.MONTHLY: { if (recurrence.bydayCount == 1) { - String[] ordinals = r.getStringArray(R.array.ordinal_labels); + int weekday = recurrence.startDate.weekDay; + // Cache this stuff so we won't have to redo work again later. + cacheMonthRepeatStrings(r, weekday); int dayNumber = (recurrence.startDate.monthDay - 1) / 7; - int day = EventRecurrence.timeDay2Day(recurrence.startDate.weekDay); - return r.getString(R.string.monthly_on_day_count, ordinals[dayNumber], - dayToString(day, DateUtils.LENGTH_LONG)) + endString; + StringBuilder sb = new StringBuilder(); + sb.append(r.getString(R.string.monthly)); + sb.append(" ("); + sb.append(mMonthRepeatByDayOfWeekStrs[weekday][dayNumber]); + sb.append(")"); + sb.append(endString); + return sb.toString(); } return r.getString(R.string.monthly) + endString; } @@ -114,6 +124,26 @@ public class EventRecurrenceFormatter return null; } + private static void cacheMonthRepeatStrings(Resources r, int weekday) { + if (mMonthRepeatByDayOfWeekIds == null) { + mMonthRepeatByDayOfWeekIds = new int[7]; + mMonthRepeatByDayOfWeekIds[0] = R.array.repeat_by_nth_sun; + mMonthRepeatByDayOfWeekIds[1] = R.array.repeat_by_nth_mon; + mMonthRepeatByDayOfWeekIds[2] = R.array.repeat_by_nth_tues; + mMonthRepeatByDayOfWeekIds[3] = R.array.repeat_by_nth_wed; + mMonthRepeatByDayOfWeekIds[4] = R.array.repeat_by_nth_thurs; + mMonthRepeatByDayOfWeekIds[5] = R.array.repeat_by_nth_fri; + mMonthRepeatByDayOfWeekIds[6] = R.array.repeat_by_nth_sat; + } + if (mMonthRepeatByDayOfWeekStrs == null) { + mMonthRepeatByDayOfWeekStrs = new String[7][]; + } + if (mMonthRepeatByDayOfWeekStrs[weekday] == null) { + mMonthRepeatByDayOfWeekStrs[weekday] = + r.getStringArray(mMonthRepeatByDayOfWeekIds[weekday]); + } + } + /** * Converts day of week to a String. * @param day a EventRecurrence constant |