Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 1 | package com.android.contacts.interactions; |
| 2 | |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 3 | import android.content.ContentUris; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 4 | import android.content.ContentValues; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 5 | import android.content.Context; |
| 6 | import android.content.Intent; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 7 | import android.graphics.drawable.Drawable; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 8 | import android.provider.CalendarContract.Attendees; |
| 9 | import android.provider.CalendarContract.Events; |
Walter Jang | 7ce5352 | 2014-10-29 13:26:43 -0700 | [diff] [blame] | 10 | import android.text.Spannable; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 11 | import android.text.TextUtils; |
| 12 | import android.text.format.Time; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 13 | |
| 14 | import com.android.contacts.R; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 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 | |
John Shao | bd9ef3c | 2016-12-15 12:42:03 -0800 | [diff] [blame] | 23 | private static final int CALENDAR_ICON_RES = R.drawable.quantum_ic_event_vd_theme_24; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 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 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 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 | |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 72 | String displayedDatetime = CalendarInteractionUtils.getDisplayedDatetime( |
Paul Soulos | c1e7ecd | 2014-06-30 18:06:17 -0400 | [diff] [blame] | 73 | dateStart, dateEnd, System.currentTimeMillis(), localTimezone, |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 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 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 110 | public Integer getAttendeeRelationship() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 111 | return mValues.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP); |
| 112 | } |
| 113 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 114 | public Integer getAttendeeStatus() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 115 | return mValues.getAsInteger(Attendees.ATTENDEE_STATUS); |
| 116 | } |
| 117 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 118 | public Integer getAttendeeType() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 119 | return mValues.getAsInteger(Attendees.ATTENDEE_TYPE); |
| 120 | } |
| 121 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 122 | public Integer getEventId() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 123 | return mValues.getAsInteger(Attendees.EVENT_ID); |
| 124 | } |
| 125 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 126 | public Integer getAccessLevel() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 127 | return mValues.getAsInteger(Attendees.ACCESS_LEVEL); |
| 128 | } |
| 129 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 130 | public Boolean getAllDay() { |
Paul Soulos | 1bbce64 | 2014-09-02 17:15:43 -0700 | [diff] [blame] | 131 | return mValues.getAsInteger(Attendees.ALL_DAY) == 1 ? true : false; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 134 | public Integer getAvailability() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 135 | return mValues.getAsInteger(Attendees.AVAILABILITY); |
| 136 | } |
| 137 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 138 | public Integer getCalendarId() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 139 | return mValues.getAsInteger(Attendees.CALENDAR_ID); |
| 140 | } |
| 141 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 142 | public Boolean getCanInviteOthers() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 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 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 158 | public Integer getDisplayColor() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 159 | return mValues.getAsInteger(Attendees.DISPLAY_COLOR); |
| 160 | } |
| 161 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 162 | public Long getDtend() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 163 | return mValues.getAsLong(Attendees.DTEND); |
| 164 | } |
| 165 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 166 | public Long getDtstart() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 167 | return mValues.getAsLong(Attendees.DTSTART); |
| 168 | } |
| 169 | |
| 170 | public String getDuration() { |
| 171 | return mValues.getAsString(Attendees.DURATION); |
| 172 | } |
| 173 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 174 | public Integer getEventColor() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 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 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 198 | public Boolean getGuestsCanInviteOthers() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 199 | return mValues.getAsBoolean(Attendees.GUESTS_CAN_INVITE_OTHERS); |
| 200 | } |
| 201 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 202 | public Boolean getGuestsCanModify() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 203 | return mValues.getAsBoolean(Attendees.GUESTS_CAN_MODIFY); |
| 204 | } |
| 205 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 206 | public Boolean getGuestsCanSeeGuests() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 207 | return mValues.getAsBoolean(Attendees.GUESTS_CAN_SEE_GUESTS); |
| 208 | } |
| 209 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 210 | public Boolean getHasAlarm() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 211 | return mValues.getAsBoolean(Attendees.HAS_ALARM); |
| 212 | } |
| 213 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 214 | public Boolean getHasAttendeeData() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 215 | return mValues.getAsBoolean(Attendees.HAS_ATTENDEE_DATA); |
| 216 | } |
| 217 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 218 | public Boolean getHasExtendedProperties() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 219 | return mValues.getAsBoolean(Attendees.HAS_EXTENDED_PROPERTIES); |
| 220 | } |
| 221 | |
| 222 | public String getIsOrganizer() { |
| 223 | return mValues.getAsString(Attendees.IS_ORGANIZER); |
| 224 | } |
| 225 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 226 | public Long getLastDate() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 227 | return mValues.getAsLong(Attendees.LAST_DATE); |
| 228 | } |
| 229 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 230 | public Boolean getLastSynced() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 231 | return mValues.getAsBoolean(Attendees.LAST_SYNCED); |
| 232 | } |
| 233 | |
| 234 | public String getOrganizer() { |
| 235 | return mValues.getAsString(Attendees.ORGANIZER); |
| 236 | } |
| 237 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 238 | public Boolean getOriginalAllDay() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 239 | return mValues.getAsBoolean(Attendees.ORIGINAL_ALL_DAY); |
| 240 | } |
| 241 | |
| 242 | public String getOriginalId() { |
| 243 | return mValues.getAsString(Attendees.ORIGINAL_ID); |
| 244 | } |
| 245 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 246 | public Long getOriginalInstanceTime() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 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 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 262 | public Integer getSelfAttendeeStatus() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 263 | return mValues.getAsInteger(Attendees.SELF_ATTENDEE_STATUS); |
| 264 | } |
| 265 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 266 | public Integer getStatus() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 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 | } |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 277 | |
| 278 | @Override |
Walter Jang | 7ce5352 | 2014-10-29 13:26:43 -0700 | [diff] [blame] | 279 | public Spannable getContentDescription(Context context) { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 280 | // The default TalkBack is good |
| 281 | return null; |
| 282 | } |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 283 | |
| 284 | @Override |
| 285 | public int getIconResourceId() { |
| 286 | return CALENDAR_ICON_RES; |
| 287 | } |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 288 | } |