diff options
-rw-r--r-- | src/com/cyanogenmod/lockclock/ClockWidgetService.java | 23 | ||||
-rw-r--r-- | src/com/cyanogenmod/lockclock/misc/Constants.java | 16 |
2 files changed, 27 insertions, 12 deletions
diff --git a/src/com/cyanogenmod/lockclock/ClockWidgetService.java b/src/com/cyanogenmod/lockclock/ClockWidgetService.java index c190dab..9e987dd 100644 --- a/src/com/cyanogenmod/lockclock/ClockWidgetService.java +++ b/src/com/cyanogenmod/lockclock/ClockWidgetService.java @@ -30,6 +30,7 @@ import android.provider.CalendarContract; import android.provider.Settings; import android.text.TextUtils; import android.text.format.DateFormat; +import android.text.format.DateUtils; import android.text.format.Time; import android.util.Log; import android.util.TypedValue; @@ -44,7 +45,6 @@ import com.cyanogenmod.lockclock.misc.WidgetUtils; import com.cyanogenmod.lockclock.weather.WeatherInfo; import com.cyanogenmod.lockclock.weather.WeatherUpdateService; -import java.text.SimpleDateFormat; import java.util.Date; import java.util.Set; @@ -481,9 +481,6 @@ public class ClockWidgetService extends IntentService { where.toString(), null, CalendarContract.Instances.BEGIN + " ASC"); if (cursor != null) { - final SimpleDateFormat allDayFormat = new SimpleDateFormat( - getString(R.string.abbrev_wday_month_day_no_year)); - final java.text.DateFormat eventFormat = DateFormat.getTimeFormat(this); final int showLocation = Preferences.calendarLocationMode(this); final int showDescription = Preferences.calendarDescriptionMode(this); final Time time = new Time(); @@ -499,6 +496,7 @@ public class ClockWidgetService extends IntentService { String description = cursor.getString(DESCRIPTION_INDEX); String location = cursor.getString(LOCATION_INDEX); boolean allDay = cursor.getInt(ALL_DAY_INDEX) != 0; + int format = 0; if (allDay) { begin = convertUtcToLocal(time, begin); @@ -513,18 +511,19 @@ public class ClockWidgetService extends IntentService { // Start building the event details string // Starting with the date - Date startDate = new Date(begin); - Date endDate = new Date(end); StringBuilder sb = new StringBuilder(); if (allDay) { - sb.append(allDayFormat.format(startDate)); + format = Constants.CALENDAR_FORMAT_ALLDAY; + } else if (DateUtils.isToday(begin)) { + format = Constants.CALENDAR_FORMAT_TODAY; } else { - sb.append(DateFormat.format("E", startDate)); - sb.append(" "); - sb.append(eventFormat.format(startDate)); - sb.append(" - "); - sb.append(eventFormat.format(endDate)); + format = Constants.CALENDAR_FORMAT_FUTURE; + } + if (allDay || begin == end) { + sb.append(DateUtils.formatDateTime(this, begin, format)); + } else { + sb.append(DateUtils.formatDateRange(this, begin, end, format)); } // Add the event location if it should be shown diff --git a/src/com/cyanogenmod/lockclock/misc/Constants.java b/src/com/cyanogenmod/lockclock/misc/Constants.java index bc62401..1307513 100644 --- a/src/com/cyanogenmod/lockclock/misc/Constants.java +++ b/src/com/cyanogenmod/lockclock/misc/Constants.java @@ -16,6 +16,8 @@ package com.cyanogenmod.lockclock.misc; +import android.text.format.DateUtils; + public class Constants { public static final boolean DEBUG = false; @@ -53,4 +55,18 @@ public class Constants { public static final String WEATHER_DATA = "weather_data"; public static final int MAX_CALENDAR_ITEMS = 3; + public static final int CALENDAR_FORMAT_TIME = + DateUtils.FORMAT_SHOW_TIME + | DateUtils.FORMAT_NO_NOON + | DateUtils.FORMAT_NO_MIDNIGHT; + public static final int CALENDAR_FORMAT_ABBREV_DATE = + DateUtils.FORMAT_SHOW_WEEKDAY + | DateUtils.FORMAT_ABBREV_ALL + | DateUtils.FORMAT_SHOW_DATE; + public static final int CALENDAR_FORMAT_ABBREV_DATETIME = + CALENDAR_FORMAT_ABBREV_DATE + | CALENDAR_FORMAT_TIME; + public static final int CALENDAR_FORMAT_ALLDAY = CALENDAR_FORMAT_ABBREV_DATE; + public static final int CALENDAR_FORMAT_TODAY = CALENDAR_FORMAT_TIME; + public static final int CALENDAR_FORMAT_FUTURE = CALENDAR_FORMAT_ABBREV_DATETIME; } |