summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/layout/agenda_day.xml4
-rw-r--r--res/layout/appwidget.xml4
-rw-r--r--res/layout/appwidget_day.xml36
-rw-r--r--src/com/android/calendar/Utils.java17
-rw-r--r--src/com/android/calendar/widget/CalendarAppWidgetModel.java388
-rw-r--r--src/com/android/calendar/widget/CalendarAppWidgetService.java386
-rw-r--r--tests/src/com/android/calendar/widget/CalendarAppWidgetServiceTest.java425
7 files changed, 577 insertions, 683 deletions
diff --git a/res/layout/agenda_day.xml b/res/layout/agenda_day.xml
index b2b4a1cd..26530660 100644
--- a/res/layout/agenda_day.xml
+++ b/res/layout/agenda_day.xml
@@ -4,9 +4,9 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/res/layout/appwidget.xml b/res/layout/appwidget.xml
index 7696ae1a..b8f7ba77 100644
--- a/res/layout/appwidget.xml
+++ b/res/layout/appwidget.xml
@@ -78,8 +78,6 @@
android:id="@+id/events_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:cacheColorHint="#00000000"
- android:dividerHeight="3dip"
- android:divider="#0000" />
+ android:cacheColorHint="#00000000"/>
</LinearLayout>
diff --git a/res/layout/appwidget_day.xml b/res/layout/appwidget_day.xml
new file mode 100644
index 00000000..625212a3
--- /dev/null
+++ b/res/layout/appwidget_day.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/appwidget_date"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:addStatesFromChildren="true"
+ android:focusableInTouchMode="false">
+
+ <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/date"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:background="@color/agenda_day_bar_color"
+ android:padding="4dip"
+ android:textStyle="bold"
+ android:textColor="@color/appwidget_title"
+ />
+
+</LinearLayout> \ No newline at end of file
diff --git a/src/com/android/calendar/Utils.java b/src/com/android/calendar/Utils.java
index 41b415c2..80f07370 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -39,6 +39,7 @@ import android.util.Log;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
public class Utils {
// Set to 0 until we have UI to perform undo
@@ -331,6 +332,22 @@ public class Utils {
}
/**
+ * Convert given UTC time into current local time.
+ *
+ * @param recycle Time object to recycle, otherwise null.
+ * @param utcTime Time to convert, in UTC.
+ */
+ public static long convertUtcToLocal(Time recycle, long utcTime) {
+ if (recycle == null) {
+ recycle = new Time();
+ }
+ recycle.timezone = Time.TIMEZONE_UTC;
+ recycle.set(utcTime);
+ recycle.timezone = TimeZone.getDefault().getID();
+ return recycle.normalize(true);
+ }
+
+ /**
* Scan through a cursor of calendars and check if names are duplicated.
*
* This travels a cursor containing calendar display names and fills in the provided map with
diff --git a/src/com/android/calendar/widget/CalendarAppWidgetModel.java b/src/com/android/calendar/widget/CalendarAppWidgetModel.java
index a8b6dabc..a21af757 100644
--- a/src/com/android/calendar/widget/CalendarAppWidgetModel.java
+++ b/src/com/android/calendar/widget/CalendarAppWidgetModel.java
@@ -16,34 +16,65 @@
package com.android.calendar.widget;
+import android.content.Context;
+import android.database.Cursor;
+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.view.View;
-import java.util.Arrays;
+import com.android.calendar.R;
+import com.android.calendar.Utils;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.TimeZone;
class CalendarAppWidgetModel {
- String dayOfWeek;
- String dayOfMonth;
- /*
- * TODO Refactor this so this class is used in the case of "no event"
- * So for now, this field is always View.GONE
+
+ private static final String TAG = CalendarAppWidgetModel.class.getSimpleName();
+
+ private static final boolean LOGD = false;
+
+ /**
+ * {@link RowInfo} is a class that represents a single row in the widget. It
+ * is actually only a pointer to either a {@link DayInfo} or an
+ * {@link EventInfo} instance, since a row in the widget might be either a
+ * day header or an event.
*/
- int visibNoEvents;
+ static class RowInfo {
- EventInfo[] eventInfos;
+ static final int TYPE_DAY = 0;
- public CalendarAppWidgetModel() {
- this(1);
- }
+ static final int TYPE_MEETING = 1;
+
+ /**
+ * mType is either a day header (TYPE_DAY) or an event (TYPE_MEETING)
+ */
+ final int mType;
+
+ /**
+ * If mType is TYPE_DAY, then mData is the index into day infos.
+ * Otherwise mType is TYPE_MEETING and mData is the index into event
+ * infos.
+ */
+ final int mIndex;
- public CalendarAppWidgetModel(int size) {
- eventInfos = new EventInfo[size];
- for (int i = 0; i < size; i++) {
- eventInfos[i] = new EventInfo();
+ RowInfo(int type, int index) {
+ mType = type;
+ mIndex = index;
}
- visibNoEvents = View.GONE;
}
- class EventInfo {
+ /**
+ * {@link EventInfo} is a class that represents an event in the widget. It
+ * contains all of the data necessary to display that event, including the
+ * properly localized strings and visibility settings.
+ */
+ static class EventInfo {
int visibWhen; // Visibility value for When textview (View.GONE or View.VISIBLE)
String when;
int visibWhere; // Visibility value for Where textview (View.GONE or View.VISIBLE)
@@ -52,6 +83,8 @@ class CalendarAppWidgetModel {
String title;
long start;
+ long end;
+ boolean allDay;
public EventInfo() {
visibWhen = View.GONE;
@@ -82,7 +115,9 @@ class CalendarAppWidgetModel {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + getOuterType().hashCode();
+ result = prime * result + (allDay ? 1231 : 1237);
+ result = prime * result + (int) (end ^ (end >>> 32));
+ result = prime * result + (int) (start ^ (start >>> 32));
result = prime * result + ((title == null) ? 0 : title.hashCode());
result = prime * result + visibTitle;
result = prime * result + visibWhen;
@@ -94,65 +129,320 @@ class CalendarAppWidgetModel {
@Override
public boolean equals(Object obj) {
- if (this == obj) {
+ if (this == obj)
return true;
- }
- if (obj == null) {
+ if (obj == null)
return false;
- }
- if (getClass() != obj.getClass()) {
+ if (getClass() != obj.getClass())
return false;
- }
EventInfo other = (EventInfo) obj;
+ if (allDay != other.allDay)
+ return false;
+ if (end != other.end)
+ return false;
+ if (start != other.start)
+ return false;
if (title == null) {
- if (other.title != null) {
+ if (other.title != null)
return false;
- }
- } else if (!title.equals(other.title)) {
+ } else if (!title.equals(other.title))
return false;
- }
- if (visibTitle != other.visibTitle) {
+ if (visibTitle != other.visibTitle)
return false;
- }
- if (visibWhen != other.visibWhen) {
+ if (visibWhen != other.visibWhen)
return false;
- }
- if (visibWhere != other.visibWhere) {
+ if (visibWhere != other.visibWhere)
return false;
- }
if (when == null) {
- if (other.when != null) {
+ if (other.when != null)
return false;
- }
- } else if (!when.equals(other.when)) {
+ } else if (!when.equals(other.when))
return false;
- }
if (where == null) {
- if (other.where != null) {
+ if (other.where != null)
return false;
- }
- } else if (!where.equals(other.where)) {
+ } else if (!where.equals(other.where))
return false;
- }
return true;
}
+ }
+
+ /**
+ * {@link DayInfo} is a class that represents a day header in the widget. It
+ * contains all of the data necessary to display that day header, including
+ * the properly localized string.
+ */
+ static class DayInfo {
+
+ /** The Julian day */
+ final int mJulianDay;
+
+ /** The string representation of this day header, to be displayed */
+ final String mDayLabel;
+
+ DayInfo(int julianDay, String label) {
+ mJulianDay = julianDay;
+ mDayLabel = label;
+ }
+
+ @Override
+ public String toString() {
+ return mDayLabel;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((mDayLabel == null) ? 0 : mDayLabel.hashCode());
+ result = prime * result + mJulianDay;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ DayInfo other = (DayInfo) obj;
+ if (mDayLabel == null) {
+ if (other.mDayLabel != null)
+ return false;
+ } else if (!mDayLabel.equals(other.mDayLabel))
+ return false;
+ if (mJulianDay != other.mJulianDay)
+ return false;
+ return true;
+ }
+
+ }
+
+ String mDayOfWeek;
+
+ String mDayOfMonth;
+
+ final List<RowInfo> mRowInfos;
+
+ final List<EventInfo> mEventInfos;
+
+ final List<DayInfo> mDayInfos;
+
+ final Context mContext;
+
+ final long mNow;
+
+ final long mStartOfNextDay;
+
+ final int mTodayJulianDay;
+
+ final int mMaxJulianDay;
+
+ public CalendarAppWidgetModel(Context context) {
+ mNow = System.currentTimeMillis();
+ Time time = new Time();
+ time.set(mNow);
+ time.monthDay++;
+ time.hour = 0;
+ time.minute = 0;
+ time.second = 0;
+ mStartOfNextDay = time.normalize(true);
+
+ long localOffset = TimeZone.getDefault().getOffset(mNow) / 1000;
+ mTodayJulianDay = Time.getJulianDay(mNow, localOffset);
+ mMaxJulianDay = mTodayJulianDay + CalendarAppWidgetService.MAX_DAYS - 1;
+
+ // Calendar header
+ String dayOfWeek = DateUtils.getDayOfWeekString(
+ time.weekDay + 1, DateUtils.LENGTH_MEDIUM).toUpperCase();
+
+ mDayOfWeek = dayOfWeek;
+ mDayOfMonth = Integer.toString(time.monthDay);
+
+ mEventInfos = new ArrayList<EventInfo>(50);
+ mRowInfos = new ArrayList<RowInfo>(50);
+ mDayInfos = new ArrayList<DayInfo>(8);
+ mContext = context;
+ }
+
+ public void buildFromCursor(Cursor cursor) {
+ Time recycle = new Time();
+ final ArrayList<LinkedList<RowInfo>> mBuckets =
+ new ArrayList<LinkedList<RowInfo>>(CalendarAppWidgetService.MAX_DAYS);
+ for (int i = 0; i < CalendarAppWidgetService.MAX_DAYS; i++) {
+ mBuckets.add(new LinkedList<RowInfo>());
+ }
+
+ cursor.moveToPosition(-1);
+ while (cursor.moveToNext()) {
+ int rowId = cursor.getPosition();
+ long eventId = cursor.getLong(CalendarAppWidgetService.INDEX_EVENT_ID);
+ boolean allDay = cursor.getInt(CalendarAppWidgetService.INDEX_ALL_DAY) != 0;
+ long start = cursor.getLong(CalendarAppWidgetService.INDEX_BEGIN);
+ long end = cursor.getLong(CalendarAppWidgetService.INDEX_END);
+ String title = cursor.getString(CalendarAppWidgetService.INDEX_TITLE);
+ String location = cursor.getString(CalendarAppWidgetService.INDEX_EVENT_LOCATION);
+
+ // we don't compute these ourselves because it seems to produce the
+ // wrong endDay for all day events
+ int startDay = cursor.getInt(CalendarAppWidgetService.INDEX_START_DAY);
+ int endDay = cursor.getInt(CalendarAppWidgetService.INDEX_END_DAY);
+
+ // Adjust all-day times into local timezone
+ if (allDay) {
+ start = Utils.convertUtcToLocal(recycle, start);
+ end = Utils.convertUtcToLocal(recycle, end);
+ }
- private CalendarAppWidgetModel getOuterType() {
- return CalendarAppWidgetModel.this;
+ if (LOGD) {
+ Log.d(TAG, "Row #" + rowId + " allDay:" + allDay + " start:" + start
+ + " end:" + end + " eventId:" + eventId);
+ }
+
+ // we might get some extra events when querying, in order to
+ // deal with all-day events
+ if (end < mNow) {
+ continue;
+ }
+
+ // Skip events that have already passed their flip times
+ long eventFlip = CalendarAppWidgetService.getEventFlip(start, end, allDay);
+ if (LOGD) Log.d(TAG, "Calculated flip time "
+ + CalendarAppWidgetService.formatDebugTime(eventFlip, mNow));
+ if (eventFlip < mNow) {
+ continue;
+ }
+
+ int i = mEventInfos.size();
+ mEventInfos.add(populateEventInfo(
+ allDay, start, end, startDay, endDay, title, location));
+ // populate the day buckets that this event falls into
+ int from = Math.max(startDay, mTodayJulianDay);
+ int to = Math.min(endDay, mMaxJulianDay);
+ for (int day = from; day <= to; day++) {
+ LinkedList<RowInfo> bucket = mBuckets.get(day - mTodayJulianDay);
+ RowInfo rowInfo = new RowInfo(RowInfo.TYPE_MEETING, i);
+ if (allDay) {
+ bucket.addFirst(rowInfo);
+ } else {
+ bucket.add(rowInfo);
+ }
+ }
+ }
+
+ int day = mTodayJulianDay;
+ int count = 0;
+ for (LinkedList<RowInfo> bucket : mBuckets) {
+ if (!bucket.isEmpty()) {
+ DayInfo dayInfo = populateDayInfo(day, recycle);
+ // Add the day header
+ int dayIndex = mDayInfos.size();
+ mDayInfos.add(dayInfo);
+ mRowInfos.add(new RowInfo(RowInfo.TYPE_DAY, dayIndex));
+ // Add the event row infos
+ mRowInfos.addAll(bucket);
+ count += bucket.size();
+ }
+ day++;
+ if (count >= CalendarAppWidgetService.EVENT_MIN_COUNT) {
+ break;
+ }
+ }
+ }
+
+ private EventInfo populateEventInfo(boolean allDay, long start, long end,
+ int startDay, int endDay, String title, String location) {
+ EventInfo eventInfo = new EventInfo();
+
+ boolean eventIsInProgress = start <= mNow && end > mNow;
+
+ // Compute a human-readable string for the start time of the event
+ String whenString;
+ int visibWhen;
+ if (allDay) {
+ whenString = "";
+ visibWhen = View.GONE;
+ } else {
+ int flags = DateUtils.FORMAT_ABBREV_ALL;
+ flags |= DateUtils.FORMAT_SHOW_TIME;
+ if (DateFormat.is24HourFormat(mContext)) {
+ flags |= DateUtils.FORMAT_24HOUR;
+ }
+ if (endDay > startDay) {
+ flags |= DateUtils.FORMAT_SHOW_DATE;
+ whenString = DateUtils.formatDateRange(mContext, start, end, flags);
+ } else {
+ whenString = DateUtils.formatDateRange(mContext, start, start, flags);
+ }
+ // TODO better i18n formatting
+ if (eventIsInProgress) {
+ whenString += " (";
+ whenString += mContext.getString(R.string.in_progress);
+ whenString += ")";
+ }
+ visibWhen = View.VISIBLE;
}
+ eventInfo.start = start;
+ eventInfo.end = end;
+ eventInfo.allDay = allDay;
+ eventInfo.when = whenString;
+ eventInfo.visibWhen = visibWhen;
+
+ // What
+ if (TextUtils.isEmpty(title)) {
+ eventInfo.title = mContext.getString(R.string.no_title_label);
+ } else {
+ eventInfo.title = title;
+ }
+ eventInfo.visibTitle = View.VISIBLE;
+
+ // Where
+ if (!TextUtils.isEmpty(location)) {
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.where = location;
+ } else {
+ eventInfo.visibWhere = View.GONE;
+ }
+ return eventInfo;
+ }
+
+ private DayInfo populateDayInfo(int julianDay, Time recycle) {
+ long millis = recycle.setJulianDay(julianDay);
+ int flags = DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_UTC;
+ flags |= DateUtils.FORMAT_SHOW_WEEKDAY;
+
+ String label;
+ if (julianDay == mTodayJulianDay) {
+ label = mContext.getString(R.string.today);
+ return new DayInfo(julianDay, label);
+ }
+
+ if (julianDay == mTodayJulianDay + 1) {
+ label = mContext.getString(R.string.tomorrow);
+ } else {
+ label = DateUtils.formatDateRange(mContext, millis, millis, flags);
+ }
+
+ flags = DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_UTC;
+ flags |= DateUtils.FORMAT_SHOW_DATE;
+
+ label += ", ";
+ label += DateUtils.formatDateRange(mContext, millis, millis, flags);
+
+ return new DayInfo(julianDay, label);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("\nCalendarAppWidgetModel [eventInfos=");
- builder.append(Arrays.toString(eventInfos));
- builder.append(", visibNoEvents=");
- builder.append(visibNoEvents);
+ builder.append(mEventInfos);
builder.append(", dayOfMonth=");
- builder.append(dayOfMonth);
+ builder.append(mDayOfMonth);
builder.append(", dayOfWeek=");
- builder.append(dayOfWeek);
+ builder.append(mDayOfWeek);
builder.append("]");
return builder.toString();
}
diff --git a/src/com/android/calendar/widget/CalendarAppWidgetService.java b/src/com/android/calendar/widget/CalendarAppWidgetService.java
index f2210d63..54ab4ad0 100644
--- a/src/com/android/calendar/widget/CalendarAppWidgetService.java
+++ b/src/com/android/calendar/widget/CalendarAppWidgetService.java
@@ -28,8 +28,6 @@ import android.net.Uri;
import android.provider.Calendar.Attendees;
import android.provider.Calendar.Calendars;
import android.provider.Calendar.Instances;
-import android.text.TextUtils;
-import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.text.format.Time;
import android.util.Log;
@@ -41,22 +39,22 @@ import com.google.common.annotations.VisibleForTesting;
import com.android.calendar.R;
import com.android.calendar.Utils;
+import com.android.calendar.widget.CalendarAppWidgetModel.DayInfo;
import com.android.calendar.widget.CalendarAppWidgetModel.EventInfo;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.TimeZone;
+import com.android.calendar.widget.CalendarAppWidgetModel.RowInfo;
public class CalendarAppWidgetService extends RemoteViewsService {
private static final String TAG = "CalendarAppWidgetService";
private static final boolean LOGD = false;
- private static final int EVENT_MIN_COUNT = 20;
+ static final int EVENT_MIN_COUNT = 20;
+
+ static final int EVENT_MAX_COUNT = 503;
private static final String EVENT_SORT_ORDER = Instances.START_DAY + " ASC, "
+ Instances.START_MINUTE + " ASC, " + Instances.END_DAY + " ASC, "
- + Instances.END_MINUTE + " ASC";
+ + Instances.END_MINUTE + " ASC LIMIT " + EVENT_MAX_COUNT;
// TODO can't use parameter here because provider is dropping them
private static final String EVENT_SELECTION = Calendars.SELECTED + "=1 AND "
@@ -69,6 +67,8 @@ public class CalendarAppWidgetService extends RemoteViewsService {
Instances.TITLE,
Instances.EVENT_LOCATION,
Instances.EVENT_ID,
+ Instances.START_DAY,
+ Instances.END_DAY
};
static final int INDEX_ALL_DAY = 0;
@@ -77,8 +77,12 @@ public class CalendarAppWidgetService extends RemoteViewsService {
static final int INDEX_TITLE = 3;
static final int INDEX_EVENT_LOCATION = 4;
static final int INDEX_EVENT_ID = 5;
+ static final int INDEX_START_DAY = 6;
+ static final int INDEX_END_DAY = 7;
- private static final long SEARCH_DURATION = DateUtils.WEEK_IN_MILLIS;
+ static final int MAX_DAYS = 7;
+
+ private static final long SEARCH_DURATION = MAX_DAYS * DateUtils.DAY_IN_MILLIS;
// If no next-update calculated, or bad trigger time in past, schedule
// update about six hours from now.
@@ -89,40 +93,6 @@ public class CalendarAppWidgetService extends RemoteViewsService {
return new CalendarFactory(getApplicationContext(), intent);
}
- protected static class MarkedEvents {
-
- /**
- * The row IDs of all events marked for display
- */
- List<Integer> markedIds = new ArrayList<Integer>(10);
-
- /**
- * The start time of the first marked event
- */
- long firstTime = -1;
-
- /** The number of events currently in progress */
- int inProgressCount = 0; // Number of events with same start time as the primary evt.
-
- /** The start time of the next upcoming event */
- long primaryTime = -1;
-
- /**
- * The number of events that share the same start time as the next
- * upcoming event
- */
- int primaryCount = 0; // Number of events with same start time as the secondary evt.
-
- /** The start time of the next next upcoming event */
- long secondaryTime = 1;
-
- /**
- * The number of events that share the same start time as the next next
- * upcoming event.
- */
- int secondaryCount = 0;
- }
-
protected static class CalendarFactory implements RemoteViewsService.RemoteViewsFactory {
private static final String TAG = CalendarFactory.class.getSimpleName();
@@ -158,7 +128,6 @@ public class CalendarAppWidgetService extends RemoteViewsService {
mCursor.close();
}
-
@Override
public RemoteViews getLoadingView() {
RemoteViews views = new RemoteViews(mContext.getPackageName(),
@@ -173,11 +142,29 @@ public class CalendarAppWidgetService extends RemoteViewsService {
return null;
}
- if (mModel.eventInfos.length > 0) {
+ if (mModel.mEventInfos.isEmpty() || mModel.mRowInfos.isEmpty()) {
+ RemoteViews views = new RemoteViews(mContext.getPackageName(),
+ R.layout.appwidget_no_events);
+ PendingIntent launchIntent =
+ CalendarAppWidgetProvider.getLaunchPendingIntent(
+ mContext, 0);
+ views.setOnClickPendingIntent(R.id.appwidget_no_events, launchIntent);
+ return views;
+ }
+
+
+ RowInfo rowInfo = mModel.mRowInfos.get(position);
+ if (rowInfo.mType == RowInfo.TYPE_DAY) {
+ RemoteViews views = new RemoteViews(mContext.getPackageName(),
+ R.layout.appwidget_day);
+ DayInfo dayInfo = mModel.mDayInfos.get(rowInfo.mIndex);
+ updateTextView(views, R.id.date, View.VISIBLE, dayInfo.mDayLabel);
+ return views;
+ } else {
RemoteViews views = new RemoteViews(mContext.getPackageName(),
R.layout.appwidget_row);
- EventInfo e = mModel.eventInfos[position];
+ EventInfo e = mModel.mEventInfos.get(rowInfo.mIndex);
updateTextView(views, R.id.when, e.visibWhen, e.when);
updateTextView(views, R.id.where, e.visibWhere, e.where);
@@ -188,27 +175,19 @@ public class CalendarAppWidgetService extends RemoteViewsService {
mContext, e.start);
views.setOnClickPendingIntent(R.id.appwidget_row, launchIntent);
return views;
- } else {
- RemoteViews views = new RemoteViews(mContext.getPackageName(),
- R.layout.appwidget_no_events);
- PendingIntent launchIntent =
- CalendarAppWidgetProvider.getLaunchPendingIntent(
- mContext, 0);
- views.setOnClickPendingIntent(R.id.appwidget_no_events, launchIntent);
- return views;
}
}
@Override
public int getViewTypeCount() {
- return 3;
+ return 4;
}
@Override
public int getCount() {
// if there are no events, we still return 1 to represent the "no
// events" view
- return Math.max(1, mModel.eventInfos.length);
+ return Math.max(1, mModel.mRowInfos.size());
}
@Override
@@ -230,9 +209,8 @@ public class CalendarAppWidgetService extends RemoteViewsService {
mCursor = getUpcomingInstancesCursor(
mContext.getContentResolver(), SEARCH_DURATION, now);
- MarkedEvents markedEvents = buildMarkedEvents(mCursor, now);
- mModel = buildAppWidgetModel(mContext, mCursor, markedEvents, now);
- long triggerTime = calculateUpdateTime(mCursor, markedEvents);
+ mModel = buildAppWidgetModel(mContext, mCursor);
+ long triggerTime = calculateUpdateTime(mModel);
// Schedule an alarm to wake ourselves up for the next update. We also cancel
// all existing wake-ups because PendingIntents don't match against extras.
@@ -290,102 +268,11 @@ public class CalendarAppWidgetService extends RemoteViewsService {
return matrixCursor;
}
- /**
- * Walk the given instances cursor and build a list of marked events to be
- * used when updating the widget. This structure is also used to check if
- * updates are needed.
- *
- * @param cursor Valid cursor across {@link Instances#CONTENT_URI}.
- * @param watchEventIds Specific events to watch for, setting
- * {@link MarkedEvents#watchFound} if found during marking.
- * @param now Current system time to use for this update, possibly from
- * {@link System#currentTimeMillis()}
- */
- @VisibleForTesting
- protected static MarkedEvents buildMarkedEvents(Cursor cursor, long now) {
- MarkedEvents events = new MarkedEvents();
- final Time recycle = new Time();
- final long localOffset = TimeZone.getDefault().getOffset(now);
- long targetDay = -1;
-
- cursor.moveToPosition(-1);
- while (cursor.moveToNext()) {
- int row = cursor.getPosition();
- long eventId = cursor.getLong(INDEX_EVENT_ID);
- long start = cursor.getLong(INDEX_BEGIN);
- long end = cursor.getLong(INDEX_END);
- boolean allDay = cursor.getInt(INDEX_ALL_DAY) != 0;
-
- if (LOGD) {
- Log.d(TAG, "Row #" + row + " allDay:" + allDay + " start:" + start
- + " end:" + end + " eventId:" + eventId);
- }
-
- // Adjust all-day times into local timezone
- if (allDay) {
- start = convertUtcToLocal(recycle, start);
- end = convertUtcToLocal(recycle, end);
- }
-
- // we might get some extra events when querying, in order to
- // deal with all-day events
- if (end < now) {
- continue;
- }
-
- // we have already reached our minimum event count, so we ignore
- // events past the end of that day
- long endDay = Time.getJulianDay(end, localOffset);
- if (targetDay > 0 && endDay > targetDay) {
- continue;
- }
-
- // Skip events that have already passed their flip times
- long eventFlip = getEventFlip(cursor, start, end, allDay);
- if (LOGD) Log.d(TAG, "Calculated flip time " + formatDebugTime(eventFlip, now));
- if (eventFlip < now) {
- continue;
- }
-
- events.markedIds.add(row);
- // we've reached the minimum number of events to display, so just
- // finish up whatever day we're on
- if (targetDay == -1 && events.markedIds.size() >= EVENT_MIN_COUNT) {
- targetDay = endDay;
- }
- }
- return events;
- }
-
@VisibleForTesting
protected static CalendarAppWidgetModel buildAppWidgetModel(
- Context context, Cursor cursor, MarkedEvents events, long currentTime) {
- int eventCount = events.markedIds.size();
- CalendarAppWidgetModel model = new CalendarAppWidgetModel(eventCount);
- Time time = new Time();
- time.set(currentTime);
- time.monthDay++;
- time.hour = 0;
- time.minute = 0;
- time.second = 0;
- long startOfNextDay = time.normalize(true);
-
- time.set(currentTime);
-
- // Calendar header
- String dayOfWeek = DateUtils.getDayOfWeekString(
- time.weekDay + 1, DateUtils.LENGTH_MEDIUM).toUpperCase();
-
- model.dayOfWeek = dayOfWeek;
- model.dayOfMonth = Integer.toString(time.monthDay);
-
- int i = 0;
- for (Integer id : events.markedIds) {
- populateEvent(context, cursor, id, model, time, i, true,
- startOfNextDay, currentTime);
- i++;
- }
-
+ Context context, Cursor cursor) {
+ CalendarAppWidgetModel model = new CalendarAppWidgetModel(context);
+ model.buildFromCursor(cursor);
return model;
}
@@ -396,22 +283,22 @@ public class CalendarAppWidgetService extends RemoteViewsService {
* @param cursor Valid cursor on {@link Instances#CONTENT_URI}
* @param events {@link MarkedEvents} parsed from the cursor
*/
- private long calculateUpdateTime(Cursor cursor, MarkedEvents events) {
+ private long calculateUpdateTime(CalendarAppWidgetModel model) {
long result = -1;
- if (!events.markedIds.isEmpty()) {
- cursor.moveToPosition(events.markedIds.get(0));
- long start = cursor.getLong(INDEX_BEGIN);
- long end = cursor.getLong(INDEX_END);
- boolean allDay = cursor.getInt(INDEX_ALL_DAY) != 0;
+ if (!model.mEventInfos.isEmpty()) {
+ EventInfo firstEvent = model.mEventInfos.get(0);
+ long start = firstEvent.start;
+ long end = firstEvent.end;
+ boolean allDay = firstEvent.allDay;
// Adjust all-day times into local timezone
if (allDay) {
final Time recycle = new Time();
- start = convertUtcToLocal(recycle, start);
- end = convertUtcToLocal(recycle, end);
+ start = Utils.convertUtcToLocal(recycle, start);
+ end = Utils.convertUtcToLocal(recycle, end);
}
- result = getEventFlip(cursor, start, end, allDay);
+ result = getEventFlip(start, end, allDay);
// Make sure an update happens at midnight or earlier
long midnight = getNextMidnightTimeMillis();
@@ -431,154 +318,47 @@ public class CalendarAppWidgetService extends RemoteViewsService {
return midnight;
}
- /**
- * Format given time for debugging output.
- *
- * @param unixTime Target time to report.
- * @param now Current system time from {@link System#currentTimeMillis()}
- * for calculating time difference.
- */
- static private String formatDebugTime(long unixTime, long now) {
- Time time = new Time();
- time.set(unixTime);
-
- long delta = unixTime - now;
- if (delta > DateUtils.MINUTE_IN_MILLIS) {
- delta /= DateUtils.MINUTE_IN_MILLIS;
- return String.format("[%d] %s (%+d mins)", unixTime,
- time.format("%H:%M:%S"), delta);
- } else {
- delta /= DateUtils.SECOND_IN_MILLIS;
- return String.format("[%d] %s (%+d secs)", unixTime,
- time.format("%H:%M:%S"), delta);
- }
- }
-
- /**
- * Convert given UTC time into current local time.
- *
- * @param recycle Time object to recycle, otherwise null.
- * @param utcTime Time to convert, in UTC.
- */
- static private long convertUtcToLocal(Time recycle, long utcTime) {
- if (recycle == null) {
- recycle = new Time();
- }
- recycle.timezone = Time.TIMEZONE_UTC;
- recycle.set(utcTime);
- recycle.timezone = TimeZone.getDefault().getID();
- return recycle.normalize(true);
- }
-
- /**
- * Calculate flipping point for the given event; when we should hide this
- * event and show the next one. This is defined as the end time of the
- * event.
- *
- * @param start Event start time in local timezone.
- * @param end Event end time in local timezone.
- */
- static private long getEventFlip(Cursor cursor, long start, long end, boolean allDay) {
- return end;
- }
-
static void updateTextView(RemoteViews views, int id, int visibility, String string) {
views.setViewVisibility(id, visibility);
if (visibility == View.VISIBLE) {
views.setTextViewText(id, string);
}
}
+ }
- /**
- * Pulls the information for a single event from the cursor and populates
- * the corresponding model object with the data.
- *
- * @param context a Context to use for accessing resources
- * @param cursor the cursor to retrieve the data from
- * @param rowId the ID of the row to retrieve
- * @param model the model object to populate
- * @param recycle a Time instance to recycle
- * @param eventIndex which event index in the model to populate
- * @param showTitleLocation whether or not to show the title and location
- * @param startOfNextDay the beginning of the next day
- * @param currentTime the current time
- */
- static private void populateEvent(Context context, Cursor cursor, int rowId,
- CalendarAppWidgetModel model, Time recycle, int eventIndex,
- boolean showTitleLocation, long startOfNextDay, long currentTime) {
- cursor.moveToPosition(rowId);
-
- // When
- boolean allDay = cursor.getInt(INDEX_ALL_DAY) != 0;
- long start = cursor.getLong(INDEX_BEGIN);
- long end = cursor.getLong(INDEX_END);
- if (allDay) {
- start = convertUtcToLocal(recycle, start);
- end = convertUtcToLocal(recycle, end);
- }
-
- boolean eventIsInProgress = start <= currentTime && end > currentTime;
- boolean eventIsToday = start < startOfNextDay;
- boolean eventIsTomorrow = !eventIsToday && !eventIsInProgress
- && (start < (startOfNextDay + DateUtils.DAY_IN_MILLIS));
-
- // Compute a human-readable string for the start time of the event
- String whenString;
- if (eventIsInProgress && allDay) {
- // All day events for the current day display as just "Today"
- whenString = context.getString(R.string.today);
- } else if (eventIsTomorrow && allDay) {
- // All day events for the next day display as just "Tomorrow"
- whenString = context.getString(R.string.tomorrow);
- } else {
- int flags = DateUtils.FORMAT_ABBREV_ALL;
- if (allDay) {
- flags |= DateUtils.FORMAT_UTC;
- } else {
- flags |= DateUtils.FORMAT_SHOW_TIME;
- if (DateFormat.is24HourFormat(context)) {
- flags |= DateUtils.FORMAT_24HOUR;
- }
- }
- // Show day of the week if not today or tomorrow
- if (!eventIsTomorrow && !eventIsToday) {
- flags |= DateUtils.FORMAT_SHOW_WEEKDAY;
- }
- whenString = DateUtils.formatDateRange(context, start, start, flags);
- // TODO better i18n formatting
- if (eventIsTomorrow) {
- whenString += (", ");
- whenString += context.getString(R.string.tomorrow);
- } else if (eventIsInProgress) {
- whenString += " (";
- whenString += context.getString(R.string.in_progress);
- whenString += ")";
- }
- }
-
- model.eventInfos[eventIndex].start = start;
- model.eventInfos[eventIndex].when = whenString;
- model.eventInfos[eventIndex].visibWhen = View.VISIBLE;
-
- if (showTitleLocation) {
- // What
- String titleString = cursor.getString(INDEX_TITLE);
- if (TextUtils.isEmpty(titleString)) {
- titleString = context.getString(R.string.no_title_label);
- }
- model.eventInfos[eventIndex].title = titleString;
- model.eventInfos[eventIndex].visibTitle = View.VISIBLE;
-
- // Where
- String whereString = cursor.getString(INDEX_EVENT_LOCATION);
- if (!TextUtils.isEmpty(whereString)) {
- model.eventInfos[eventIndex].visibWhere = View.VISIBLE;
- model.eventInfos[eventIndex].where = whereString;
- } else {
- model.eventInfos[eventIndex].visibWhere = View.GONE;
- }
- if (LOGD) Log.d(TAG, " Title:" + titleString + " Where:" + whereString);
- }
+ /**
+ * Format given time for debugging output.
+ *
+ * @param unixTime Target time to report.
+ * @param now Current system time from {@link System#currentTimeMillis()}
+ * for calculating time difference.
+ */
+ static String formatDebugTime(long unixTime, long now) {
+ Time time = new Time();
+ time.set(unixTime);
+
+ long delta = unixTime - now;
+ if (delta > DateUtils.MINUTE_IN_MILLIS) {
+ delta /= DateUtils.MINUTE_IN_MILLIS;
+ return String.format("[%d] %s (%+d mins)", unixTime,
+ time.format("%H:%M:%S"), delta);
+ } else {
+ delta /= DateUtils.SECOND_IN_MILLIS;
+ return String.format("[%d] %s (%+d secs)", unixTime,
+ time.format("%H:%M:%S"), delta);
}
}
+
+ /**
+ * Calculate flipping point for the given event; when we should hide this
+ * event and show the next one. This is defined as the end time of the
+ * event.
+ *
+ * @param start Event start time in local timezone.
+ * @param end Event end time in local timezone.
+ * @param allDay whether or not the event is all-day
+ */
+ static long getEventFlip(long start, long end, boolean allDay) {
+ return end;
+ }
}
diff --git a/tests/src/com/android/calendar/widget/CalendarAppWidgetServiceTest.java b/tests/src/com/android/calendar/widget/CalendarAppWidgetServiceTest.java
index e06e462d..e870e593 100644
--- a/tests/src/com/android/calendar/widget/CalendarAppWidgetServiceTest.java
+++ b/tests/src/com/android/calendar/widget/CalendarAppWidgetServiceTest.java
@@ -18,9 +18,9 @@
package com.android.calendar.widget;
import com.android.calendar.widget.CalendarAppWidgetModel;
+import com.android.calendar.widget.CalendarAppWidgetModel.EventInfo;
import com.android.calendar.widget.CalendarAppWidgetService;
import com.android.calendar.widget.CalendarAppWidgetService.CalendarFactory;
-import com.android.calendar.widget.CalendarAppWidgetService.MarkedEvents;
import java.util.TimeZone;
@@ -86,7 +86,7 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
@SmallTest
public void testGetAppWidgetModel_1Event() throws Exception {
- CalendarAppWidgetModel expected = new CalendarAppWidgetModel();
+ CalendarAppWidgetModel expected = new CalendarAppWidgetModel(getContext());
MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
@@ -95,20 +95,21 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title, location, 0));
// Expected Output
- expected.dayOfMonth = "1";
- expected.dayOfWeek = "FRI";
- expected.visibNoEvents = View.GONE;
- expected.eventInfos[0].visibWhen = View.VISIBLE;
- expected.eventInfos[0].visibWhere = View.VISIBLE;
- expected.eventInfos[0].visibTitle = View.VISIBLE;
- expected.eventInfos[0].when = "3am";
- expected.eventInfos[0].where = location;
- expected.eventInfos[0].title = title;
+ expected.mDayOfMonth = "1";
+ expected.mDayOfWeek = "FRI";
+
+ EventInfo eventInfo = new EventInfo();
+ eventInfo.visibWhen = View.VISIBLE;
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.visibTitle = View.VISIBLE;
+ eventInfo.when = "3am";
+ eventInfo.where = location;
+ eventInfo.title = title;
+ expected.mEventInfos.add(eventInfo);
// Test
- MarkedEvents events = CalendarFactory.buildMarkedEvents(cursor, now);
CalendarAppWidgetModel actual = CalendarFactory.buildAppWidgetModel(
- getContext(), cursor, events, now);
+ getContext(), cursor);
assertEquals(expected.toString(), actual.toString());
}
@@ -116,7 +117,7 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
// TODO re-enable this test when our widget behavior is finalized
@Suppress @SmallTest
public void testGetAppWidgetModel_2StaggeredEvents() throws Exception {
- CalendarAppWidgetModel expected = new CalendarAppWidgetModel(2);
+ CalendarAppWidgetModel expected = new CalendarAppWidgetModel(getContext());
MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
int i = 0;
@@ -124,22 +125,27 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
long sunday = tomorrow + DateUtils.DAY_IN_MILLIS;
// Expected Output
- expected.dayOfMonth = "1";
- expected.dayOfWeek = "FRI";
- expected.visibNoEvents = View.GONE;
- expected.eventInfos[0].visibWhen = View.VISIBLE;
- expected.eventInfos[0].visibWhere = View.VISIBLE;
- expected.eventInfos[0].visibTitle = View.VISIBLE;
- expected.eventInfos[0].when = "2am, Tomorrow";
- expected.eventInfos[0].where = location + i;
- expected.eventInfos[0].title = title + i;
+ expected.mDayOfMonth = "1";
+ expected.mDayOfWeek = "FRI";
+
+ EventInfo eventInfo = new EventInfo();
+ eventInfo.visibWhen = View.VISIBLE;
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.visibTitle = View.VISIBLE;
+ eventInfo.when = "2am, Tomorrow";
+ eventInfo.where = location + i;
+ eventInfo.title = title + i;
+ expected.mEventInfos.add(eventInfo);
+
++i;
- expected.eventInfos[1].visibWhen = View.VISIBLE;
- expected.eventInfos[1].visibWhere = View.VISIBLE;
- expected.eventInfos[1].visibTitle = View.VISIBLE;
- expected.eventInfos[1].when = "2am, Sun";
- expected.eventInfos[1].where = location + i;
- expected.eventInfos[1].title = title + i;
+ eventInfo = new EventInfo();
+ eventInfo.visibWhen = View.VISIBLE;
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.visibTitle = View.VISIBLE;
+ eventInfo.when = "2am, Sun";
+ eventInfo.where = location + i;
+ eventInfo.title = title + i;
+ expected.mEventInfos.add(eventInfo);
// Input
// allDay, begin, end, title, location, eventId
@@ -150,248 +156,8 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
++i;
// Test
- MarkedEvents events = CalendarFactory.buildMarkedEvents(cursor, now);
CalendarAppWidgetModel actual = CalendarFactory.buildAppWidgetModel(
- getContext(), cursor, events, now);
-
- assertEquals(expected.toString(), actual.toString());
-
- // Secondary test - Add two more afterwards
- cursor.addRow(getRow(0, sunday + ONE_HOUR, sunday + TWO_HOURS, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, sunday + ONE_HOUR, sunday + TWO_HOURS, title + i, location + i, 0));
-
- // Test again
- events = CalendarFactory.buildMarkedEvents(cursor, now);
- actual = CalendarFactory.buildAppWidgetModel(getContext(), cursor, events, now);
-
- assertEquals(expected.toString(), actual.toString());
- }
-
- // TODO re-enable this test when our widget behavior is finalized
- @Suppress @SmallTest
- public void testGetAppWidgetModel_2SameStartTimeEvents() throws Exception {
- CalendarAppWidgetModel expected = new CalendarAppWidgetModel();
- MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
-
- int i = 0;
- // Expected Output
- expected.dayOfMonth = "1";
- expected.dayOfWeek = "FRI";
- expected.visibNoEvents = View.GONE;
- expected.eventInfos[0].visibWhen = View.VISIBLE;
- expected.eventInfos[0].visibWhere = View.VISIBLE;
- expected.eventInfos[0].visibTitle = View.VISIBLE;
- expected.eventInfos[0].when = "3am";
- expected.eventInfos[0].where = location + i;
- expected.eventInfos[0].title = title + i;
- ++i;
- expected.eventInfos[1].visibWhen = View.VISIBLE;
- expected.eventInfos[1].visibWhere = View.VISIBLE;
- expected.eventInfos[1].visibTitle = View.VISIBLE;
- expected.eventInfos[1].when = "3am";
- expected.eventInfos[1].where = location + i;
- expected.eventInfos[1].title = title + i;
-
-
- // Input
- // allDay, begin, end, title, location, eventId
- i = 0;
- cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
- ++i;
-
- // Test
- MarkedEvents events = CalendarFactory.buildMarkedEvents(cursor, now);
- CalendarAppWidgetModel actual = CalendarFactory.buildAppWidgetModel(
- getContext(), cursor, events, now);
-
- assertEquals(expected.toString(), actual.toString());
-
- // Secondary test - Add two more afterwards
- cursor.addRow(getRow(0, now + TWO_HOURS, now + TWO_HOURS + 1, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, now + TWO_HOURS, now + TWO_HOURS + 1, title + i, location + i, 0));
-
- // Test again
- events = CalendarFactory.buildMarkedEvents(cursor, now);
- actual = CalendarFactory.buildAppWidgetModel(getContext(), cursor, events, now);
-
- assertEquals(expected.toString(), actual.toString());
- }
-
- @SmallTest
- public void testGetAppWidgetModel_1EventThen2SameStartTimeEvents() throws Exception {
- CalendarAppWidgetModel expected = new CalendarAppWidgetModel(3);
- MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
-
- // Input
- int i = 0;
- // allDay, begin, end, title, location, eventId
- cursor.addRow(getRow(0, now, now + TWO_HOURS, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
-
- // Expected Output
- expected.dayOfMonth = "1";
- expected.dayOfWeek = "FRI";
- i = 0;
- expected.visibNoEvents = View.GONE;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "2am (in progress)";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
- i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "3am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
- i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "3am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
-
- // Test
- MarkedEvents events = CalendarFactory.buildMarkedEvents(cursor, now);
- CalendarAppWidgetModel actual = CalendarFactory.buildAppWidgetModel(
- getContext(), cursor, events, now);
-
- assertEquals(expected.toString(), actual.toString());
- }
-
- // TODO re-enable this test when our widget behavior is finalized
- @Suppress @SmallTest
- public void testGetAppWidgetModel_3SameStartTimeEvents() throws Exception {
- final long now = 1262340000000L; // Fri Jan 01 2010 01:00:00 GMT-0700 (PDT)
- CalendarAppWidgetModel expected = new CalendarAppWidgetModel(3);
- MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
-
- int i = 0;
-
- // Expected Output
- expected.dayOfMonth = "1";
- expected.dayOfWeek = "FRI";
- expected.visibNoEvents = View.GONE;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "3am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
-
- i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "3am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
-
- i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "3am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
-
-
- // Input
- // allDay, begin, end, title, location, eventId
- i = 0;
- cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
- ++i;
-
- // Test
- MarkedEvents events = CalendarFactory.buildMarkedEvents(cursor, now);
- CalendarAppWidgetModel actual = CalendarFactory.buildAppWidgetModel(
- getContext(), cursor, events, now);
-
- assertEquals(expected.toString(), actual.toString());
-
- // Secondary test - Add one more afterwards
- cursor.addRow(getRow(0, now + TWO_HOURS, now + TWO_HOURS + 1, title + i, location + i, 0));
-
- // Test again, nothing should have changed, same expected result
- events = CalendarFactory.buildMarkedEvents(cursor, now);
- actual = CalendarFactory.buildAppWidgetModel(getContext(), cursor, events, now);
-
- assertEquals(expected.toString(), actual.toString());
- }
-
- @SmallTest
- public void testGetAppWidgetModel_2InProgress2After() throws Exception {
- final long now = 1262340000000L + HALF_HOUR; // Fri Jan 01 2010 01:30:00 GMT-0700 (PDT)
- CalendarAppWidgetModel expected = new CalendarAppWidgetModel(4);
- MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
-
- int i = 0;
-
- // Expected Output
- expected.dayOfMonth = "1";
- expected.dayOfWeek = "FRI";
- expected.visibNoEvents = View.GONE;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "2am (in progress)";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
-
- i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "2am (in progress)";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
-
- i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "4:30am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
-
- i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "4:30am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
-
-
- // Input
- // allDay, begin, end, title, location, eventId
- i = 0;
- cursor.addRow(getRow(0, now - HALF_HOUR, now + HALF_HOUR, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, now - HALF_HOUR, now + HALF_HOUR, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, now + TWO_HOURS, now + 3 * ONE_HOUR, title + i, location + i, 0));
- ++i;
- cursor.addRow(getRow(0, now + TWO_HOURS, now + 4 * ONE_HOUR, title + i, location + i, 0));
-
- // Test
- MarkedEvents events = CalendarFactory.buildMarkedEvents(cursor, now);
- CalendarAppWidgetModel actual = CalendarFactory.buildAppWidgetModel(
- getContext(), cursor, events, now);
+ getContext(), cursor);
assertEquals(expected.toString(), actual.toString());
}
@@ -399,29 +165,33 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
@SmallTest
public void testGetAppWidgetModel_AllDayEventToday() throws Exception {
final long now = 1262340000000L; // Fri Jan 01 2010 01:00:00 GMT-0700 (PDT)
- CalendarAppWidgetModel expected = new CalendarAppWidgetModel(2);
+ CalendarAppWidgetModel expected = new CalendarAppWidgetModel(getContext());
MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
int i = 0;
// Expected Output
- expected.dayOfMonth = "1";
- expected.dayOfWeek = "FRI";
- expected.visibNoEvents = View.GONE;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "Today";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
+ expected.mDayOfMonth = "1";
+ expected.mDayOfWeek = "FRI";
+
+ EventInfo eventInfo = new EventInfo();
+ eventInfo.visibWhen = View.VISIBLE;
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.visibTitle = View.VISIBLE;
+ eventInfo.when = "Today";
+ eventInfo.where = location + i;
+ eventInfo.title = title + i;
+ expected.mEventInfos.add(eventInfo);
i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "3am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
+ eventInfo = new EventInfo();
+ eventInfo.visibWhen = View.VISIBLE;
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.visibTitle = View.VISIBLE;
+ eventInfo.when = "3am";
+ eventInfo.where = location + i;
+ eventInfo.title = title + i;
+ expected.mEventInfos.add(eventInfo);
i = 0;
cursor.addRow(getRow(1, 1262304000000L, 1262390400000L, title + i, location + i, 0));
@@ -429,9 +199,8 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
// Test
- MarkedEvents events = CalendarFactory.buildMarkedEvents(cursor, now);
CalendarAppWidgetModel actual = CalendarFactory.buildAppWidgetModel(
- getContext(), cursor, events, now);
+ getContext(), cursor);
assertEquals(expected.toString(), actual.toString());
}
@@ -439,30 +208,33 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
@SmallTest
public void testGetAppWidgetModel_AllDayEventTomorrow() throws Exception {
final long now = 1262340000000L; // Fri Jan 01 2010 01:00:00 GMT-0700 (PDT)
- CalendarAppWidgetModel expected = new CalendarAppWidgetModel(2);
+ CalendarAppWidgetModel expected = new CalendarAppWidgetModel(getContext());
MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
int i = 0;
// Expected Output
- expected.dayOfMonth = "1";
- expected.dayOfWeek = "FRI";
- expected.visibNoEvents = View.GONE;
-
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "3am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
+ expected.mDayOfMonth = "1";
+ expected.mDayOfWeek = "FRI";
+
+ EventInfo eventInfo = new EventInfo();
+ eventInfo.visibWhen = View.VISIBLE;
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.visibTitle = View.VISIBLE;
+ eventInfo.when = "3am";
+ eventInfo.where = location + i;
+ eventInfo.title = title + i;
+ expected.mEventInfos.add(eventInfo);
i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "Tomorrow";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
+ eventInfo = new EventInfo();
+ eventInfo.visibWhen = View.VISIBLE;
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.visibTitle = View.VISIBLE;
+ eventInfo.when = "Tomorrow";
+ eventInfo.where = location + i;
+ eventInfo.title = title + i;
+ expected.mEventInfos.add(eventInfo);
i = 0;
cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
@@ -470,9 +242,8 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
cursor.addRow(getRow(1, 1262390400000L, 1262476800000L, title + i, location + i, 0));
// Test
- MarkedEvents events = CalendarFactory.buildMarkedEvents(cursor, now);
CalendarAppWidgetModel actual = CalendarFactory.buildAppWidgetModel(
- getContext(), cursor, events, now);
+ getContext(), cursor);
assertEquals(expected.toString(), actual.toString());
}
@@ -480,30 +251,33 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
@SmallTest
public void testGetAppWidgetModel_AllDayEventLater() throws Exception {
final long now = 1262340000000L; // Fri Jan 01 2010 01:00:00 GMT-0700 (PDT)
- CalendarAppWidgetModel expected = new CalendarAppWidgetModel(2);
+ CalendarAppWidgetModel expected = new CalendarAppWidgetModel(getContext());
MatrixCursor cursor = new MatrixCursor(CalendarAppWidgetService.EVENT_PROJECTION, 0);
int i = 0;
// Expected Output
- expected.dayOfMonth = "1";
- expected.dayOfWeek = "FRI";
- expected.visibNoEvents = View.GONE;
-
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "3am";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
+ expected.mDayOfMonth = "1";
+ expected.mDayOfWeek = "FRI";
+
+ EventInfo eventInfo = new EventInfo();
+ eventInfo.visibWhen = View.VISIBLE;
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.visibTitle = View.VISIBLE;
+ eventInfo.when = "3am";
+ eventInfo.where = location + i;
+ eventInfo.title = title + i;
+ expected.mEventInfos.add(eventInfo);
i++;
- expected.eventInfos[i].visibWhen = View.VISIBLE;
- expected.eventInfos[i].visibWhere = View.VISIBLE;
- expected.eventInfos[i].visibTitle = View.VISIBLE;
- expected.eventInfos[i].when = "Sun";
- expected.eventInfos[i].where = location + i;
- expected.eventInfos[i].title = title + i;
+ eventInfo = new EventInfo();
+ eventInfo.visibWhen = View.VISIBLE;
+ eventInfo.visibWhere = View.VISIBLE;
+ eventInfo.visibTitle = View.VISIBLE;
+ eventInfo.when = "Sun";
+ eventInfo.where = location + i;
+ eventInfo.title = title + i;
+ expected.mEventInfos.add(eventInfo);
i = 0;
cursor.addRow(getRow(0, now + ONE_HOUR, now + TWO_HOURS, title + i, location + i, 0));
@@ -511,9 +285,8 @@ public class CalendarAppWidgetServiceTest extends AndroidTestCase {
cursor.addRow(getRow(1, 1262476800000L, 1262563200000L, title + i, location + i, 0));
// Test
- MarkedEvents events = CalendarAppWidgetService.CalendarFactory.buildMarkedEvents(cursor, now);
CalendarAppWidgetModel actual = CalendarAppWidgetService.CalendarFactory.buildAppWidgetModel(
- getContext(), cursor, events, now);
+ getContext(), cursor);
assertEquals(expected.toString(), actual.toString());
}