Home | History | Annotate | Download | only in interactions
      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;
     14 import android.text.Spannable;
     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 
     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 
     75         String displayedDatetime = CalendarInteractionUtils.getDisplayedDatetime(
     76                 dateStart, dateEnd, System.currentTimeMillis(), localTimezone,
     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 
    113     public Integer getAttendeeRelationship() {
    114         return mValues.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP);
    115     }
    116 
    117     public Integer getAttendeeStatus() {
    118         return mValues.getAsInteger(Attendees.ATTENDEE_STATUS);
    119     }
    120 
    121     public Integer getAttendeeType() {
    122         return mValues.getAsInteger(Attendees.ATTENDEE_TYPE);
    123     }
    124 
    125     public Integer getEventId() {
    126         return mValues.getAsInteger(Attendees.EVENT_ID);
    127     }
    128 
    129     public Integer getAccessLevel() {
    130         return mValues.getAsInteger(Attendees.ACCESS_LEVEL);
    131     }
    132 
    133     public Boolean getAllDay() {
    134         return mValues.getAsInteger(Attendees.ALL_DAY) == 1 ? true : false;
    135     }
    136 
    137     public Integer getAvailability() {
    138         return mValues.getAsInteger(Attendees.AVAILABILITY);
    139     }
    140 
    141     public Integer getCalendarId() {
    142         return mValues.getAsInteger(Attendees.CALENDAR_ID);
    143     }
    144 
    145     public Boolean getCanInviteOthers() {
    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 
    161     public Integer getDisplayColor() {
    162         return mValues.getAsInteger(Attendees.DISPLAY_COLOR);
    163     }
    164 
    165     public Long getDtend() {
    166         return mValues.getAsLong(Attendees.DTEND);
    167     }
    168 
    169     public Long getDtstart() {
    170         return mValues.getAsLong(Attendees.DTSTART);
    171     }
    172 
    173     public String getDuration() {
    174         return mValues.getAsString(Attendees.DURATION);
    175     }
    176 
    177     public Integer getEventColor() {
    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 
    201     public Boolean getGuestsCanInviteOthers() {
    202         return mValues.getAsBoolean(Attendees.GUESTS_CAN_INVITE_OTHERS);
    203     }
    204 
    205     public Boolean getGuestsCanModify() {
    206         return mValues.getAsBoolean(Attendees.GUESTS_CAN_MODIFY);
    207     }
    208 
    209     public Boolean getGuestsCanSeeGuests() {
    210         return mValues.getAsBoolean(Attendees.GUESTS_CAN_SEE_GUESTS);
    211     }
    212 
    213     public Boolean getHasAlarm() {
    214         return mValues.getAsBoolean(Attendees.HAS_ALARM);
    215     }
    216 
    217     public Boolean getHasAttendeeData() {
    218         return mValues.getAsBoolean(Attendees.HAS_ATTENDEE_DATA);
    219     }
    220 
    221     public Boolean getHasExtendedProperties() {
    222         return mValues.getAsBoolean(Attendees.HAS_EXTENDED_PROPERTIES);
    223     }
    224 
    225     public String getIsOrganizer() {
    226         return mValues.getAsString(Attendees.IS_ORGANIZER);
    227     }
    228 
    229     public Long getLastDate() {
    230         return mValues.getAsLong(Attendees.LAST_DATE);
    231     }
    232 
    233     public Boolean getLastSynced() {
    234         return mValues.getAsBoolean(Attendees.LAST_SYNCED);
    235     }
    236 
    237     public String getOrganizer() {
    238         return mValues.getAsString(Attendees.ORGANIZER);
    239     }
    240 
    241     public Boolean getOriginalAllDay() {
    242         return mValues.getAsBoolean(Attendees.ORIGINAL_ALL_DAY);
    243     }
    244 
    245     public String getOriginalId() {
    246         return mValues.getAsString(Attendees.ORIGINAL_ID);
    247     }
    248 
    249     public Long getOriginalInstanceTime() {
    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 
    265     public Integer getSelfAttendeeStatus() {
    266         return mValues.getAsInteger(Attendees.SELF_ATTENDEE_STATUS);
    267     }
    268 
    269     public Integer getStatus() {
    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     }
    280 
    281     @Override
    282     public Spannable getContentDescription(Context context) {
    283         // The default TalkBack is good
    284         return null;
    285     }
    286 
    287     @Override
    288     public int getIconResourceId() {
    289         return CALENDAR_ICON_RES;
    290     }
    291 }
    292