Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 1 | package com.android.contacts.interactions; |
| 2 | |
| 3 | import com.android.contacts.R; |
| 4 | |
| 5 | import android.content.ContentValues; |
| 6 | import android.content.ContentUris; |
| 7 | import android.content.Context; |
| 8 | import android.content.Intent; |
| 9 | import android.content.res.Resources; |
| 10 | import android.graphics.drawable.Drawable; |
| 11 | import android.net.Uri; |
| 12 | import android.provider.CalendarContract.Attendees; |
| 13 | import android.provider.CalendarContract.Events; |
Walter Jang | 7ce5352 | 2014-10-29 13:26:43 -0700 | [diff] [blame] | 14 | import android.text.Spannable; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 15 | import android.text.TextUtils; |
| 16 | import android.text.format.Time; |
| 17 | import android.util.Log; |
| 18 | |
| 19 | /** |
| 20 | * Represents a calendar event interaction, wrapping the columns in |
| 21 | * {@link android.provider.CalendarContract.Attendees}. |
| 22 | */ |
| 23 | public 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 Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 65 | 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 Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 75 | String displayedDatetime = CalendarInteractionUtils.getDisplayedDatetime( |
Paul Soulos | c1e7ecd | 2014-06-30 18:06:17 -0400 | [diff] [blame] | 76 | dateStart, dateEnd, System.currentTimeMillis(), localTimezone, |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 77 | 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 Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 113 | public Integer getAttendeeRelationship() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 114 | return mValues.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP); |
| 115 | } |
| 116 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 117 | public Integer getAttendeeStatus() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 118 | return mValues.getAsInteger(Attendees.ATTENDEE_STATUS); |
| 119 | } |
| 120 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 121 | public Integer getAttendeeType() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 122 | return mValues.getAsInteger(Attendees.ATTENDEE_TYPE); |
| 123 | } |
| 124 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 125 | public Integer getEventId() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 126 | return mValues.getAsInteger(Attendees.EVENT_ID); |
| 127 | } |
| 128 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 129 | public Integer getAccessLevel() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 130 | return mValues.getAsInteger(Attendees.ACCESS_LEVEL); |
| 131 | } |
| 132 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 133 | public Boolean getAllDay() { |
Paul Soulos | 1bbce64 | 2014-09-02 17:15:43 -0700 | [diff] [blame] | 134 | return mValues.getAsInteger(Attendees.ALL_DAY) == 1 ? true : false; |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 137 | public Integer getAvailability() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 138 | return mValues.getAsInteger(Attendees.AVAILABILITY); |
| 139 | } |
| 140 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 141 | public Integer getCalendarId() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 142 | return mValues.getAsInteger(Attendees.CALENDAR_ID); |
| 143 | } |
| 144 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 145 | public Boolean getCanInviteOthers() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 146 | 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 Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 161 | public Integer getDisplayColor() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 162 | return mValues.getAsInteger(Attendees.DISPLAY_COLOR); |
| 163 | } |
| 164 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 165 | public Long getDtend() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 166 | return mValues.getAsLong(Attendees.DTEND); |
| 167 | } |
| 168 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 169 | public Long getDtstart() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 170 | return mValues.getAsLong(Attendees.DTSTART); |
| 171 | } |
| 172 | |
| 173 | public String getDuration() { |
| 174 | return mValues.getAsString(Attendees.DURATION); |
| 175 | } |
| 176 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 177 | public Integer getEventColor() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 178 | 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 Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 201 | public Boolean getGuestsCanInviteOthers() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 202 | return mValues.getAsBoolean(Attendees.GUESTS_CAN_INVITE_OTHERS); |
| 203 | } |
| 204 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 205 | public Boolean getGuestsCanModify() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 206 | return mValues.getAsBoolean(Attendees.GUESTS_CAN_MODIFY); |
| 207 | } |
| 208 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 209 | public Boolean getGuestsCanSeeGuests() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 210 | return mValues.getAsBoolean(Attendees.GUESTS_CAN_SEE_GUESTS); |
| 211 | } |
| 212 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 213 | public Boolean getHasAlarm() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 214 | return mValues.getAsBoolean(Attendees.HAS_ALARM); |
| 215 | } |
| 216 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 217 | public Boolean getHasAttendeeData() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 218 | return mValues.getAsBoolean(Attendees.HAS_ATTENDEE_DATA); |
| 219 | } |
| 220 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 221 | public Boolean getHasExtendedProperties() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 222 | return mValues.getAsBoolean(Attendees.HAS_EXTENDED_PROPERTIES); |
| 223 | } |
| 224 | |
| 225 | public String getIsOrganizer() { |
| 226 | return mValues.getAsString(Attendees.IS_ORGANIZER); |
| 227 | } |
| 228 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 229 | public Long getLastDate() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 230 | return mValues.getAsLong(Attendees.LAST_DATE); |
| 231 | } |
| 232 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 233 | public Boolean getLastSynced() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 234 | return mValues.getAsBoolean(Attendees.LAST_SYNCED); |
| 235 | } |
| 236 | |
| 237 | public String getOrganizer() { |
| 238 | return mValues.getAsString(Attendees.ORGANIZER); |
| 239 | } |
| 240 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 241 | public Boolean getOriginalAllDay() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 242 | return mValues.getAsBoolean(Attendees.ORIGINAL_ALL_DAY); |
| 243 | } |
| 244 | |
| 245 | public String getOriginalId() { |
| 246 | return mValues.getAsString(Attendees.ORIGINAL_ID); |
| 247 | } |
| 248 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 249 | public Long getOriginalInstanceTime() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 250 | 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 Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 265 | public Integer getSelfAttendeeStatus() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 266 | return mValues.getAsInteger(Attendees.SELF_ATTENDEE_STATUS); |
| 267 | } |
| 268 | |
Paul Soulos | 75d5a91 | 2014-06-24 11:22:37 -0700 | [diff] [blame] | 269 | public Integer getStatus() { |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 270 | 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 Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 280 | |
| 281 | @Override |
Walter Jang | 7ce5352 | 2014-10-29 13:26:43 -0700 | [diff] [blame] | 282 | public Spannable getContentDescription(Context context) { |
Paul Soulos | 23e2836 | 2014-08-29 14:57:08 -0700 | [diff] [blame] | 283 | // The default TalkBack is good |
| 284 | return null; |
| 285 | } |
Paul Soulos | 48290be | 2014-09-08 13:44:51 -0700 | [diff] [blame] | 286 | |
| 287 | @Override |
| 288 | public int getIconResourceId() { |
| 289 | return CALENDAR_ICON_RES; |
| 290 | } |
Paul Soulos | 899aa21 | 2014-06-11 12:04:43 -0700 | [diff] [blame] | 291 | } |