diff options
author | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2012-01-10 14:08:08 +0300 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.cyanogenmod.com> | 2012-01-10 14:08:08 +0300 |
commit | 61d4b8d1a72c7d57377c57047304882d42e45bda (patch) | |
tree | 7725198b0bfb13729de0fb036c1fa7a9c733e9c9 /core | |
parent | 0ef5bab19adf26e7f4ebe64e72b9cd5fedc6c6de (diff) | |
parent | f19d4c4541ca5e32fa89d3a7e09a75f346e411e6 (diff) | |
download | frameworks_base-61d4b8d1a72c7d57377c57047304882d42e45bda.zip frameworks_base-61d4b8d1a72c7d57377c57047304882d42e45bda.tar.gz frameworks_base-61d4b8d1a72c7d57377c57047304882d42e45bda.tar.bz2 |
Merge "getNextCalendarAlarm: query instances to get recurring events right" into gingerbread
Diffstat (limited to 'core')
-rw-r--r-- | core/java/com/android/internal/widget/LockPatternUtils.java | 103 |
1 files changed, 37 insertions, 66 deletions
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java index ba31992..668b029 100644 --- a/core/java/com/android/internal/widget/LockPatternUtils.java +++ b/core/java/com/android/internal/widget/LockPatternUtils.java @@ -20,6 +20,7 @@ import android.app.admin.DevicePolicyManager; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; +import android.net.Uri; import android.os.FileObserver; import android.os.RemoteException; import android.os.ServiceManager; @@ -735,83 +736,53 @@ public class LockPatternUtils { } where.append(") "); } + + String[] projection = new String[] { + Calendar.EventsColumns.TITLE, + Calendar.Instances.BEGIN, + Calendar.EventsColumns.DESCRIPTION, + Calendar.EventsColumns.EVENT_LOCATION, + Calendar.EventsColumns.ALL_DAY + }; + + Uri uri = Uri.withAppendedPath(Calendar.Instances.CONTENT_URI, + String.format("%d/%d", now, later)); String nextCalendarAlarm = null; Cursor cursor = null; + try { - cursor = Calendar.Instances.query(mContentResolver, - new String[] { - Calendar.EventsColumns.TITLE, - Calendar.EventsColumns.DTSTART, - Calendar.EventsColumns.DTEND, - Calendar.EventsColumns.DESCRIPTION, - Calendar.EventsColumns.EVENT_LOCATION, - Calendar.EventsColumns.ALL_DAY, - }, - now, - later, - where.toString(), - Calendar.EventsColumns.DTSTART + " ASC"); + cursor = mContentResolver.query(uri, + projection, where.toString(), null, + Calendar.Instances.DEFAULT_SORT_ORDER); if (cursor != null && cursor.moveToFirst()) { - // All day events are given in UTC. This can cause them to be sorted - // as earlier events compared to a normal event on the night before - // we can fix this by doing UTC time - offset => local time and then - // compare that to the next event on the cursor. - long offset = (new Date()).getTimezoneOffset() * 60000; - String title, description, location; - Date start; - boolean allDay, isRepeat; - int i = cursor.getCount() - 1; - - do { - title = cursor.getString(0); - start = new Date(cursor.getLong(1)); - isRepeat = cursor.getLong(2) == 0; - description = cursor.getString(3); - location = cursor.getString(4); - allDay = cursor.getInt(5) != 0; - - // repeat events always report the first day of the event as - // start >.<' Fix the date then, to match today - if (isRepeat) { - java.util.Calendar today = java.util.Calendar.getInstance(); - java.util.Calendar startc = java.util.Calendar.getInstance(); - startc.setTime(start); - - // Event is repetitive in the future - if (today.getTimeInMillis() < startc.getTimeInMillis()) { - Log.i(TAG, "Repetitive event detected in the future"); - } else { - startc.set(java.util.Calendar.DATE, today.get(java.util.Calendar.DATE)); - startc.set(java.util.Calendar.MONTH, today.get(java.util.Calendar.MONTH)); - startc.set(java.util.Calendar.YEAR, today.get(java.util.Calendar.YEAR)); - - // Event already old, probably tomorrow is desired - if (today.getTimeInMillis() > startc.getTimeInMillis()) { - startc.roll(java.util.Calendar.DATE, true); - Log.i(TAG, "Repetitive event hour already old, using tomorrow"); - } - - Log.i(TAG, "Repetitive event detected, date corrected (" + - start.getTime() + " -> " + startc.getTimeInMillis() + ")"); - start = startc.getTime(); - } - } - - // i prevents out of range comparisons - // if it's not an all day event, we're sure it's the earliest event - if (i == 0 || !allDay) - break; + String title = cursor.getString(0); + long begin = cursor.getLong(1); + String description = cursor.getString(2); + String location = cursor.getString(3); + boolean allDay = cursor.getInt(4) != 0; + // Check the next event in the case of allday event. As UTC is used for allday + // events, the next event may be the one that actually starts sooner + if (allDay && !cursor.isLast()) { cursor.moveToNext(); - i = i-1; - } while ((new Date(cursor.getLong(1) - offset)).before(start)); + long nextBegin = cursor.getLong(1); + if (nextBegin < begin + TimeZone.getDefault().getOffset(begin)) { + title = cursor.getString(0); + begin = nextBegin; + description = cursor.getString(2); + location = cursor.getString(3); + allDay = cursor.getInt(4) != 0; + } + } + Date start = new Date(begin); StringBuilder sb = new StringBuilder(); - if (allDay == true) { - SimpleDateFormat sdf = new SimpleDateFormat(mContext.getString(R.string.abbrev_wday_month_day_no_year)); + if (allDay) { + SimpleDateFormat sdf = new SimpleDateFormat( + mContext.getString(R.string.abbrev_wday_month_day_no_year)); // Calendar stores all-day events in UTC -- setting the timezone ensures // the correct date is shown. sdf.setTimeZone(TimeZone.getTimeZone("UTC")); |