blob: e249e4f933d44a6655a347a270bb5ef0b8f34dfd [file] [log] [blame]
Paul Soulos899aa212014-06-11 12:04:43 -07001package com.android.contacts.interactions;
2
3import com.android.contacts.R;
4
5import android.content.ContentValues;
6import android.content.ContentUris;
7import android.content.Context;
8import android.content.Intent;
9import android.content.res.Resources;
10import android.graphics.drawable.Drawable;
11import android.net.Uri;
12import android.provider.CalendarContract.Attendees;
13import android.provider.CalendarContract.Events;
Walter Jang7ce53522014-10-29 13:26:43 -070014import android.text.Spannable;
Paul Soulos899aa212014-06-11 12:04:43 -070015import android.text.TextUtils;
16import android.text.format.Time;
17import android.util.Log;
18
19/**
20 * Represents a calendar event interaction, wrapping the columns in
21 * {@link android.provider.CalendarContract.Attendees}.
22 */
23public class CalendarInteraction implements ContactInteraction {
24 private static final String TAG = CalendarInteraction.class.getSimpleName();
25
26 private static final int CALENDAR_ICON_RES = R.drawable.ic_event_24dp;
27
28 private ContentValues mValues;
29
30 public CalendarInteraction(ContentValues values) {
31 mValues = values;
32 }
33
34 @Override
35 public Intent getIntent() {
36 return new Intent(Intent.ACTION_VIEW).setData(
37 ContentUris.withAppendedId(Events.CONTENT_URI, getEventId()));
38 }
39
40 @Override
41 public long getInteractionDate() {
42 return getDtstart();
43 }
44
45 @Override
46 public String getViewHeader(Context context) {
47 String title = getTitle();
48 if (TextUtils.isEmpty(title)) {
49 return context.getResources().getString(R.string.untitled_event);
50 }
51 return title;
52 }
53
54 @Override
55 public String getViewBody(Context context) {
56 return null;
57 }
58
59 @Override
60 public String getViewFooter(Context context) {
61 // Pulled from com.android.calendar.EventInfoFragment.updateEvent(View view)
62 // TODO: build callback to update time zone if different than preferences
63 String localTimezone = Time.getCurrentTimezone();
64
Paul Soulos75d5a912014-06-24 11:22:37 -070065 Long dateEnd = getDtend();
66 Long dateStart = getDtstart();
67 if (dateStart == null && dateEnd == null) {
68 return null;
69 } else if (dateEnd == null) {
70 dateEnd = dateStart;
71 } else if (dateStart == null) {
72 dateStart = dateEnd;
73 }
74
Paul Soulos899aa212014-06-11 12:04:43 -070075 String displayedDatetime = CalendarInteractionUtils.getDisplayedDatetime(
Paul Soulosc1e7ecd2014-06-30 18:06:17 -040076 dateStart, dateEnd, System.currentTimeMillis(), localTimezone,
Paul Soulos899aa212014-06-11 12:04:43 -070077 getAllDay(), context);
78
79 return displayedDatetime;
80 }
81
82 @Override
83 public Drawable getIcon(Context context) {
84 return context.getResources().getDrawable(CALENDAR_ICON_RES);
85 }
86
87 @Override
88 public Drawable getBodyIcon(Context context) {
89 return null;
90 }
91
92 @Override
93 public Drawable getFooterIcon(Context context) {
94 return null;
95 }
96
97 public String getAttendeeEmail() {
98 return mValues.getAsString(Attendees.ATTENDEE_EMAIL);
99 }
100
101 public String getAttendeeIdentity() {
102 return mValues.getAsString(Attendees.ATTENDEE_IDENTITY);
103 }
104
105 public String getAttendeeIdNamespace() {
106 return mValues.getAsString(Attendees.ATTENDEE_ID_NAMESPACE);
107 }
108
109 public String getAttendeeName() {
110 return mValues.getAsString(Attendees.ATTENDEE_NAME);
111 }
112
Paul Soulos75d5a912014-06-24 11:22:37 -0700113 public Integer getAttendeeRelationship() {
Paul Soulos899aa212014-06-11 12:04:43 -0700114 return mValues.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP);
115 }
116
Paul Soulos75d5a912014-06-24 11:22:37 -0700117 public Integer getAttendeeStatus() {
Paul Soulos899aa212014-06-11 12:04:43 -0700118 return mValues.getAsInteger(Attendees.ATTENDEE_STATUS);
119 }
120
Paul Soulos75d5a912014-06-24 11:22:37 -0700121 public Integer getAttendeeType() {
Paul Soulos899aa212014-06-11 12:04:43 -0700122 return mValues.getAsInteger(Attendees.ATTENDEE_TYPE);
123 }
124
Paul Soulos75d5a912014-06-24 11:22:37 -0700125 public Integer getEventId() {
Paul Soulos899aa212014-06-11 12:04:43 -0700126 return mValues.getAsInteger(Attendees.EVENT_ID);
127 }
128
Paul Soulos75d5a912014-06-24 11:22:37 -0700129 public Integer getAccessLevel() {
Paul Soulos899aa212014-06-11 12:04:43 -0700130 return mValues.getAsInteger(Attendees.ACCESS_LEVEL);
131 }
132
Paul Soulos75d5a912014-06-24 11:22:37 -0700133 public Boolean getAllDay() {
Paul Soulos1bbce642014-09-02 17:15:43 -0700134 return mValues.getAsInteger(Attendees.ALL_DAY) == 1 ? true : false;
Paul Soulos899aa212014-06-11 12:04:43 -0700135 }
136
Paul Soulos75d5a912014-06-24 11:22:37 -0700137 public Integer getAvailability() {
Paul Soulos899aa212014-06-11 12:04:43 -0700138 return mValues.getAsInteger(Attendees.AVAILABILITY);
139 }
140
Paul Soulos75d5a912014-06-24 11:22:37 -0700141 public Integer getCalendarId() {
Paul Soulos899aa212014-06-11 12:04:43 -0700142 return mValues.getAsInteger(Attendees.CALENDAR_ID);
143 }
144
Paul Soulos75d5a912014-06-24 11:22:37 -0700145 public Boolean getCanInviteOthers() {
Paul Soulos899aa212014-06-11 12:04:43 -0700146 return mValues.getAsBoolean(Attendees.CAN_INVITE_OTHERS);
147 }
148
149 public String getCustomAppPackage() {
150 return mValues.getAsString(Attendees.CUSTOM_APP_PACKAGE);
151 }
152
153 public String getCustomAppUri() {
154 return mValues.getAsString(Attendees.CUSTOM_APP_URI);
155 }
156
157 public String getDescription() {
158 return mValues.getAsString(Attendees.DESCRIPTION);
159 }
160
Paul Soulos75d5a912014-06-24 11:22:37 -0700161 public Integer getDisplayColor() {
Paul Soulos899aa212014-06-11 12:04:43 -0700162 return mValues.getAsInteger(Attendees.DISPLAY_COLOR);
163 }
164
Paul Soulos75d5a912014-06-24 11:22:37 -0700165 public Long getDtend() {
Paul Soulos899aa212014-06-11 12:04:43 -0700166 return mValues.getAsLong(Attendees.DTEND);
167 }
168
Paul Soulos75d5a912014-06-24 11:22:37 -0700169 public Long getDtstart() {
Paul Soulos899aa212014-06-11 12:04:43 -0700170 return mValues.getAsLong(Attendees.DTSTART);
171 }
172
173 public String getDuration() {
174 return mValues.getAsString(Attendees.DURATION);
175 }
176
Paul Soulos75d5a912014-06-24 11:22:37 -0700177 public Integer getEventColor() {
Paul Soulos899aa212014-06-11 12:04:43 -0700178 return mValues.getAsInteger(Attendees.EVENT_COLOR);
179 }
180
181 public String getEventColorKey() {
182 return mValues.getAsString(Attendees.EVENT_COLOR_KEY);
183 }
184
185 public String getEventEndTimezone() {
186 return mValues.getAsString(Attendees.EVENT_END_TIMEZONE);
187 }
188
189 public String getEventLocation() {
190 return mValues.getAsString(Attendees.EVENT_LOCATION);
191 }
192
193 public String getExdate() {
194 return mValues.getAsString(Attendees.EXDATE);
195 }
196
197 public String getExrule() {
198 return mValues.getAsString(Attendees.EXRULE);
199 }
200
Paul Soulos75d5a912014-06-24 11:22:37 -0700201 public Boolean getGuestsCanInviteOthers() {
Paul Soulos899aa212014-06-11 12:04:43 -0700202 return mValues.getAsBoolean(Attendees.GUESTS_CAN_INVITE_OTHERS);
203 }
204
Paul Soulos75d5a912014-06-24 11:22:37 -0700205 public Boolean getGuestsCanModify() {
Paul Soulos899aa212014-06-11 12:04:43 -0700206 return mValues.getAsBoolean(Attendees.GUESTS_CAN_MODIFY);
207 }
208
Paul Soulos75d5a912014-06-24 11:22:37 -0700209 public Boolean getGuestsCanSeeGuests() {
Paul Soulos899aa212014-06-11 12:04:43 -0700210 return mValues.getAsBoolean(Attendees.GUESTS_CAN_SEE_GUESTS);
211 }
212
Paul Soulos75d5a912014-06-24 11:22:37 -0700213 public Boolean getHasAlarm() {
Paul Soulos899aa212014-06-11 12:04:43 -0700214 return mValues.getAsBoolean(Attendees.HAS_ALARM);
215 }
216
Paul Soulos75d5a912014-06-24 11:22:37 -0700217 public Boolean getHasAttendeeData() {
Paul Soulos899aa212014-06-11 12:04:43 -0700218 return mValues.getAsBoolean(Attendees.HAS_ATTENDEE_DATA);
219 }
220
Paul Soulos75d5a912014-06-24 11:22:37 -0700221 public Boolean getHasExtendedProperties() {
Paul Soulos899aa212014-06-11 12:04:43 -0700222 return mValues.getAsBoolean(Attendees.HAS_EXTENDED_PROPERTIES);
223 }
224
225 public String getIsOrganizer() {
226 return mValues.getAsString(Attendees.IS_ORGANIZER);
227 }
228
Paul Soulos75d5a912014-06-24 11:22:37 -0700229 public Long getLastDate() {
Paul Soulos899aa212014-06-11 12:04:43 -0700230 return mValues.getAsLong(Attendees.LAST_DATE);
231 }
232
Paul Soulos75d5a912014-06-24 11:22:37 -0700233 public Boolean getLastSynced() {
Paul Soulos899aa212014-06-11 12:04:43 -0700234 return mValues.getAsBoolean(Attendees.LAST_SYNCED);
235 }
236
237 public String getOrganizer() {
238 return mValues.getAsString(Attendees.ORGANIZER);
239 }
240
Paul Soulos75d5a912014-06-24 11:22:37 -0700241 public Boolean getOriginalAllDay() {
Paul Soulos899aa212014-06-11 12:04:43 -0700242 return mValues.getAsBoolean(Attendees.ORIGINAL_ALL_DAY);
243 }
244
245 public String getOriginalId() {
246 return mValues.getAsString(Attendees.ORIGINAL_ID);
247 }
248
Paul Soulos75d5a912014-06-24 11:22:37 -0700249 public Long getOriginalInstanceTime() {
Paul Soulos899aa212014-06-11 12:04:43 -0700250 return mValues.getAsLong(Attendees.ORIGINAL_INSTANCE_TIME);
251 }
252
253 public String getOriginalSyncId() {
254 return mValues.getAsString(Attendees.ORIGINAL_SYNC_ID);
255 }
256
257 public String getRdate() {
258 return mValues.getAsString(Attendees.RDATE);
259 }
260
261 public String getRrule() {
262 return mValues.getAsString(Attendees.RRULE);
263 }
264
Paul Soulos75d5a912014-06-24 11:22:37 -0700265 public Integer getSelfAttendeeStatus() {
Paul Soulos899aa212014-06-11 12:04:43 -0700266 return mValues.getAsInteger(Attendees.SELF_ATTENDEE_STATUS);
267 }
268
Paul Soulos75d5a912014-06-24 11:22:37 -0700269 public Integer getStatus() {
Paul Soulos899aa212014-06-11 12:04:43 -0700270 return mValues.getAsInteger(Attendees.STATUS);
271 }
272
273 public String getTitle() {
274 return mValues.getAsString(Attendees.TITLE);
275 }
276
277 public String getUid2445() {
278 return mValues.getAsString(Attendees.UID_2445);
279 }
Paul Soulos23e28362014-08-29 14:57:08 -0700280
281 @Override
Walter Jang7ce53522014-10-29 13:26:43 -0700282 public Spannable getContentDescription(Context context) {
Paul Soulos23e28362014-08-29 14:57:08 -0700283 // The default TalkBack is good
284 return null;
285 }
Paul Soulos48290be2014-09-08 13:44:51 -0700286
287 @Override
288 public int getIconResourceId() {
289 return CALENDAR_ICON_RES;
290 }
Paul Soulos899aa212014-06-11 12:04:43 -0700291}