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