1package 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;
14import android.text.TextUtils;
15import android.text.format.Time;
16import android.util.Log;
17
18/**
19 * Represents a calendar event interaction, wrapping the columns in
20 * {@link android.provider.CalendarContract.Attendees}.
21 */
22public class CalendarInteraction implements ContactInteraction {
23    private static final String TAG = CalendarInteraction.class.getSimpleName();
24
25    private static final int CALENDAR_ICON_RES = R.drawable.ic_event_24dp;
26
27    private ContentValues mValues;
28
29    public CalendarInteraction(ContentValues values) {
30        mValues = values;
31    }
32
33    @Override
34    public Intent getIntent() {
35        return new Intent(Intent.ACTION_VIEW).setData(
36                ContentUris.withAppendedId(Events.CONTENT_URI, getEventId()));
37    }
38
39    @Override
40    public long getInteractionDate() {
41        return getDtstart();
42    }
43
44    @Override
45    public String getViewHeader(Context context) {
46        String title = getTitle();
47        if (TextUtils.isEmpty(title)) {
48            return context.getResources().getString(R.string.untitled_event);
49        }
50        return title;
51    }
52
53    @Override
54    public String getViewBody(Context context) {
55        return null;
56    }
57
58    @Override
59    public String getViewFooter(Context context) {
60        // Pulled from com.android.calendar.EventInfoFragment.updateEvent(View view)
61        // TODO: build callback to update time zone if different than preferences
62        String localTimezone = Time.getCurrentTimezone();
63
64        Long dateEnd = getDtend();
65        Long dateStart = getDtstart();
66        if (dateStart == null && dateEnd == null) {
67            return null;
68        } else if (dateEnd == null) {
69            dateEnd = dateStart;
70        } else if (dateStart == null) {
71            dateStart = dateEnd;
72        }
73
74        String displayedDatetime = CalendarInteractionUtils.getDisplayedDatetime(
75                dateStart, dateEnd, System.currentTimeMillis(), localTimezone,
76                getAllDay(), context);
77
78        return displayedDatetime;
79    }
80
81    @Override
82    public Drawable getIcon(Context context) {
83        return context.getResources().getDrawable(CALENDAR_ICON_RES);
84    }
85
86    @Override
87    public Drawable getBodyIcon(Context context) {
88        return null;
89    }
90
91    @Override
92    public Drawable getFooterIcon(Context context) {
93        return null;
94    }
95
96    public String getAttendeeEmail() {
97        return mValues.getAsString(Attendees.ATTENDEE_EMAIL);
98    }
99
100    public String getAttendeeIdentity() {
101        return mValues.getAsString(Attendees.ATTENDEE_IDENTITY);
102    }
103
104    public String getAttendeeIdNamespace() {
105        return mValues.getAsString(Attendees.ATTENDEE_ID_NAMESPACE);
106    }
107
108    public String getAttendeeName() {
109        return mValues.getAsString(Attendees.ATTENDEE_NAME);
110    }
111
112    public Integer getAttendeeRelationship() {
113        return mValues.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP);
114    }
115
116    public Integer getAttendeeStatus() {
117        return mValues.getAsInteger(Attendees.ATTENDEE_STATUS);
118    }
119
120    public Integer getAttendeeType() {
121        return mValues.getAsInteger(Attendees.ATTENDEE_TYPE);
122    }
123
124    public Integer getEventId() {
125        return mValues.getAsInteger(Attendees.EVENT_ID);
126    }
127
128    public Integer getAccessLevel() {
129        return mValues.getAsInteger(Attendees.ACCESS_LEVEL);
130    }
131
132    public Boolean getAllDay() {
133        return mValues.getAsInteger(Attendees.ALL_DAY) == 1 ? true : false;
134    }
135
136    public Integer getAvailability() {
137        return mValues.getAsInteger(Attendees.AVAILABILITY);
138    }
139
140    public Integer getCalendarId() {
141        return mValues.getAsInteger(Attendees.CALENDAR_ID);
142    }
143
144    public Boolean getCanInviteOthers() {
145        return mValues.getAsBoolean(Attendees.CAN_INVITE_OTHERS);
146    }
147
148    public String getCustomAppPackage() {
149        return mValues.getAsString(Attendees.CUSTOM_APP_PACKAGE);
150    }
151
152    public String getCustomAppUri() {
153        return mValues.getAsString(Attendees.CUSTOM_APP_URI);
154    }
155
156    public String getDescription() {
157        return mValues.getAsString(Attendees.DESCRIPTION);
158    }
159
160    public Integer getDisplayColor() {
161        return mValues.getAsInteger(Attendees.DISPLAY_COLOR);
162    }
163
164    public Long getDtend() {
165        return mValues.getAsLong(Attendees.DTEND);
166    }
167
168    public Long getDtstart() {
169        return mValues.getAsLong(Attendees.DTSTART);
170    }
171
172    public String getDuration() {
173        return mValues.getAsString(Attendees.DURATION);
174    }
175
176    public Integer getEventColor() {
177        return mValues.getAsInteger(Attendees.EVENT_COLOR);
178    }
179
180    public String getEventColorKey() {
181        return mValues.getAsString(Attendees.EVENT_COLOR_KEY);
182    }
183
184    public String getEventEndTimezone() {
185        return mValues.getAsString(Attendees.EVENT_END_TIMEZONE);
186    }
187
188    public String getEventLocation() {
189        return mValues.getAsString(Attendees.EVENT_LOCATION);
190    }
191
192    public String getExdate() {
193        return mValues.getAsString(Attendees.EXDATE);
194    }
195
196    public String getExrule() {
197        return mValues.getAsString(Attendees.EXRULE);
198    }
199
200    public Boolean getGuestsCanInviteOthers() {
201        return mValues.getAsBoolean(Attendees.GUESTS_CAN_INVITE_OTHERS);
202    }
203
204    public Boolean getGuestsCanModify() {
205        return mValues.getAsBoolean(Attendees.GUESTS_CAN_MODIFY);
206    }
207
208    public Boolean getGuestsCanSeeGuests() {
209        return mValues.getAsBoolean(Attendees.GUESTS_CAN_SEE_GUESTS);
210    }
211
212    public Boolean getHasAlarm() {
213        return mValues.getAsBoolean(Attendees.HAS_ALARM);
214    }
215
216    public Boolean getHasAttendeeData() {
217        return mValues.getAsBoolean(Attendees.HAS_ATTENDEE_DATA);
218    }
219
220    public Boolean getHasExtendedProperties() {
221        return mValues.getAsBoolean(Attendees.HAS_EXTENDED_PROPERTIES);
222    }
223
224    public String getIsOrganizer() {
225        return mValues.getAsString(Attendees.IS_ORGANIZER);
226    }
227
228    public Long getLastDate() {
229        return mValues.getAsLong(Attendees.LAST_DATE);
230    }
231
232    public Boolean getLastSynced() {
233        return mValues.getAsBoolean(Attendees.LAST_SYNCED);
234    }
235
236    public String getOrganizer() {
237        return mValues.getAsString(Attendees.ORGANIZER);
238    }
239
240    public Boolean getOriginalAllDay() {
241        return mValues.getAsBoolean(Attendees.ORIGINAL_ALL_DAY);
242    }
243
244    public String getOriginalId() {
245        return mValues.getAsString(Attendees.ORIGINAL_ID);
246    }
247
248    public Long getOriginalInstanceTime() {
249        return mValues.getAsLong(Attendees.ORIGINAL_INSTANCE_TIME);
250    }
251
252    public String getOriginalSyncId() {
253        return mValues.getAsString(Attendees.ORIGINAL_SYNC_ID);
254    }
255
256    public String getRdate() {
257        return mValues.getAsString(Attendees.RDATE);
258    }
259
260    public String getRrule() {
261        return mValues.getAsString(Attendees.RRULE);
262    }
263
264    public Integer getSelfAttendeeStatus() {
265        return mValues.getAsInteger(Attendees.SELF_ATTENDEE_STATUS);
266    }
267
268    public Integer getStatus() {
269        return mValues.getAsInteger(Attendees.STATUS);
270    }
271
272    public String getTitle() {
273        return mValues.getAsString(Attendees.TITLE);
274    }
275
276    public String getUid2445() {
277        return mValues.getAsString(Attendees.UID_2445);
278    }
279
280    @Override
281    public String getContentDescription(Context context) {
282        // The default TalkBack is good
283        return null;
284    }
285
286    @Override
287    public int getIconResourceId() {
288        return CALENDAR_ICON_RES;
289    }
290}
291