diff options
author | Nicolai Ehemann <en@enlightened.de> | 2013-04-12 13:37:23 +0200 |
---|---|---|
committer | Nicolai Ehemann <en@enlightened.de> | 2013-04-20 22:06:13 +0200 |
commit | 1e97e624780b3ccafff4a75f2f8f2038195b2153 (patch) | |
tree | dcf43d486a91da2770e344817076191f82faad38 /src/com/cyanogenmod/lockclock | |
parent | 4f35d4d6b565eafeedc48318533916e8705c2600 (diff) | |
download | android_packages_apps_LockClock-1e97e624780b3ccafff4a75f2f8f2038195b2153.tar.gz android_packages_apps_LockClock-1e97e624780b3ccafff4a75f2f8f2038195b2153.tar.bz2 android_packages_apps_LockClock-1e97e624780b3ccafff4a75f2f8f2038195b2153.zip |
cLock: refactorings and cleanup (no functional changes)
Change-Id: I4ca0f3eea0cb3260f248d3abc6099b45c3ed1c27
Diffstat (limited to 'src/com/cyanogenmod/lockclock')
-rwxr-xr-x | src/com/cyanogenmod/lockclock/calendar/CalendarWidgetService.java | 212 | ||||
-rw-r--r-- | src/com/cyanogenmod/lockclock/misc/CalendarInfo.java | 9 |
2 files changed, 100 insertions, 121 deletions
diff --git a/src/com/cyanogenmod/lockclock/calendar/CalendarWidgetService.java b/src/com/cyanogenmod/lockclock/calendar/CalendarWidgetService.java index 2a8fb22..d4ccb9d 100755 --- a/src/com/cyanogenmod/lockclock/calendar/CalendarWidgetService.java +++ b/src/com/cyanogenmod/lockclock/calendar/CalendarWidgetService.java @@ -260,125 +260,115 @@ class CalendarRemoteViewsFactory implements RemoteViewsFactory { CalendarContract.Events.ALL_DAY, }; - // The indices for the projection array - int EVENT_ID_INDEX = 0; - int TITLE_INDEX = 1; - int BEGIN_TIME_INDEX = 2; - int END_TIME_INDEX = 3; - int DESCRIPTION_INDEX = 4; - int LOCATION_INDEX = 5; - int ALL_DAY_INDEX = 6; - // all day events are stored in UTC, that is why we need to fetch events after 'later' Uri uri = Uri.withAppendedPath(CalendarContract.Instances.CONTENT_URI, String.format("%d/%d", now - DAY_IN_MILLIS, later + DAY_IN_MILLIS)); - Cursor cursor = null; - - try { - cursor = context.getContentResolver().query(uri, projection, - where.toString(), null, CalendarContract.Instances.BEGIN + " ASC"); + Cursor cursor = cursor = context.getContentResolver().query(uri, projection, + where.toString(), null, CalendarContract.Instances.BEGIN + " ASC"); + + if (cursor != null) { + // The indices for the projection array + final int indexEventId = cursor.getColumnIndex(CalendarContract.Instances.EVENT_ID); + final int indexTitle = cursor.getColumnIndex(CalendarContract.Events.TITLE); + final int indexBeginTime = cursor.getColumnIndex(CalendarContract.Instances.BEGIN); + final int indexEndTime = cursor.getColumnIndex(CalendarContract.Instances.END); + final int indexDescription = cursor.getColumnIndex(CalendarContract.Events.DESCRIPTION); + final int indexLocation = cursor.getColumnIndex(CalendarContract.Events.EVENT_LOCATION); + final int indexAllDay = cursor.getColumnIndex(CalendarContract.Events.ALL_DAY); + + final int showLocation = Preferences.calendarLocationMode(context); + final int showDescription = Preferences.calendarDescriptionMode(context); + final Time time = new Time(); + int eventCount = 0; + + // Iterate through returned rows to a maximum number of calendar events + while (cursor.moveToNext() && eventCount < Constants.MAX_CALENDAR_ITEMS) { + final long eventId = cursor.getLong(indexEventId); + final String title = cursor.getString(indexTitle); + long begin = cursor.getLong(indexBeginTime); + long end = cursor.getLong(indexEndTime); + final String description = cursor.getString(indexDescription); + final String location = cursor.getString(indexLocation); + final boolean allDay = cursor.getInt(indexAllDay) != 0; + int format = 0; + + if (allDay) { + begin = convertUtcToLocal(time, begin); + end = convertUtcToLocal(time, end); + } - if (cursor != null) { - final int showLocation = Preferences.calendarLocationMode(context); - final int showDescription = Preferences.calendarDescriptionMode(context); - final Time time = new Time(); - int eventCount = 0; - - cursor.moveToPosition(-1); - // Iterate through returned rows to a maximum number of calendar events - while (cursor.moveToNext() && eventCount < Constants.MAX_CALENDAR_ITEMS) { - long eventId = cursor.getLong(EVENT_ID_INDEX); - String title = cursor.getString(TITLE_INDEX); - long begin = cursor.getLong(BEGIN_TIME_INDEX); - long end = cursor.getLong(END_TIME_INDEX); - 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); - end = convertUtcToLocal(time, end); - } + if (end < now || begin > later) { + continue; + } - if (end < now || begin > later) { - continue; - } + if (D) Log.v(TAG, "Adding event: " + title + " with id: " + eventId); - if (D) Log.v(TAG, "Adding event: " + title + " with id: " + eventId); + // Start building the event details string + // Starting with the date + StringBuilder sb = new StringBuilder(); - // Start building the event details string - // Starting with the date - StringBuilder sb = new StringBuilder(); + if (allDay) { + format = Constants.CALENDAR_FORMAT_ALLDAY; + } else if (DateUtils.isToday(begin)) { + format = Constants.CALENDAR_FORMAT_TODAY; + } else { + format = Constants.CALENDAR_FORMAT_FUTURE; + } + if (allDay || begin == end) { + sb.append(DateUtils.formatDateTime(context, begin, format)); + } else { + sb.append(DateUtils.formatDateRange(context, begin, end, format)); + } - if (allDay) { - format = Constants.CALENDAR_FORMAT_ALLDAY; - } else if (DateUtils.isToday(begin)) { - format = Constants.CALENDAR_FORMAT_TODAY; - } else { - format = Constants.CALENDAR_FORMAT_FUTURE; - } - if (allDay || begin == end) { - sb.append(DateUtils.formatDateTime(context, begin, format)); - } else { - sb.append(DateUtils.formatDateRange(context, begin, end, format)); + // Add the event location if it should be shown + if (showLocation != Preferences.SHOW_NEVER && !TextUtils.isEmpty(location)) { + switch (showLocation) { + case Preferences.SHOW_FIRST_LINE: + int stringEnd = location.indexOf('\n'); + if (stringEnd == -1) { + sb.append(": " + location); + } else { + sb.append(": " + location.substring(0, stringEnd)); + } + break; + case Preferences.SHOW_ALWAYS: + sb.append(": " + location); + break; } + } - // Add the event location if it should be shown - if (showLocation != Preferences.SHOW_NEVER && !TextUtils.isEmpty(location)) { - switch (showLocation) { - case Preferences.SHOW_FIRST_LINE: - int stringEnd = location.indexOf('\n'); - if (stringEnd == -1) { - sb.append(": " + location); - } else { - sb.append(": " + location.substring(0, stringEnd)); - } - break; - case Preferences.SHOW_ALWAYS: - sb.append(": " + location); - break; - } + // Add the event description if it should be shown + if (showDescription != Preferences.SHOW_NEVER + && !TextUtils.isEmpty(description)) { + // Show the appropriate separator + if (showLocation == Preferences.SHOW_NEVER) { + sb.append(": "); + } else { + sb.append(" - "); } - // Add the event description if it should be shown - if (showDescription != Preferences.SHOW_NEVER - && !TextUtils.isEmpty(description)) { - // Show the appropriate separator - if (showLocation == Preferences.SHOW_NEVER) { - sb.append(": "); - } else { - sb.append(" - "); - } - - switch (showDescription) { - case Preferences.SHOW_FIRST_LINE: - int stringEnd = description.indexOf('\n'); - if (stringEnd == -1) { - sb.append(description); - } else { - sb.append(description.substring(0, stringEnd)); - } - break; - case Preferences.SHOW_ALWAYS: + switch (showDescription) { + case Preferences.SHOW_FIRST_LINE: + int stringEnd = description.indexOf('\n'); + if (stringEnd == -1) { sb.append(description); - break; - } + } else { + sb.append(description.substring(0, stringEnd)); + } + break; + case Preferences.SHOW_ALWAYS: + sb.append(description); + break; } - - // Add the event details to the CalendarInfo object and move to next record - newCalendarInfo.addEvent(populateEventInfo(eventId, title, sb.toString(), begin, - end, allDay)); - eventCount++; } + + // Add the event details to the CalendarInfo object and move to next record + newCalendarInfo.addEvent(new EventInfo(eventId, title, sb.toString(), begin, + end, allDay)); + eventCount++; } - } catch (Exception e) { - // Do nothing - } finally { + cursor.close(); mCalendarInfo = newCalendarInfo; - if (cursor != null) { - cursor.close(); - } } // check for first event outside of lookahead window @@ -418,24 +408,6 @@ class CalendarRemoteViewsFactory implements RemoteViewsFactory { return time.normalize(true); } - /** - * Construct the EventInfo object - */ - private static EventInfo populateEventInfo(long eventId, String title, String description, - long begin, long end, boolean allDay) { - EventInfo eventInfo = new EventInfo(); - - // Populate the fields - eventInfo.id = eventId; - eventInfo.title = title; - eventInfo.description = description; - eventInfo.start = begin; - eventInfo.end = end; - eventInfo.allDay = allDay; - - return eventInfo; - } - private static long getMinUpdateFromNow(long now) { // we update at least once a day return now + DAY_IN_MILLIS; diff --git a/src/com/cyanogenmod/lockclock/misc/CalendarInfo.java b/src/com/cyanogenmod/lockclock/misc/CalendarInfo.java index 7e634cf..277303a 100644 --- a/src/com/cyanogenmod/lockclock/misc/CalendarInfo.java +++ b/src/com/cyanogenmod/lockclock/misc/CalendarInfo.java @@ -71,7 +71,14 @@ public class CalendarInfo { public long end; public boolean allDay; - public EventInfo() { + public EventInfo(long eventId, String title, String description, long start, long end, + boolean allDay) { + this.id = eventId; + this.title = title; + this.description = description; + this.start = start; + this.end = end; + this.allDay = allDay; } @Override |