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