Example usage for android.content Entity addSubValue

List of usage examples for android.content Entity addSubValue

Introduction

In this page you can find the example usage for android.content Entity addSubValue.

Prototype

public void addSubValue(Uri uri, ContentValues values) 

Source Link

Usage

From source file:com.android.exchange.EasSyncService.java

/**
 * Send an email responding to a Message that has been marked as a meeting request.  The message
 * will consist a little bit of event information and an iCalendar attachment
 * @param msg the meeting request email/*from  www  .  jav  a 2 s .  c  o m*/
 */
private void sendMeetingResponseMail(Message msg, int response) {
    // Get the meeting information; we'd better have some...
    PackedString meetingInfo = new PackedString(msg.mMeetingInfo);
    if (meetingInfo == null)
        return;

    // This will come as "First Last" <box@server.blah>, so we use Address to
    // parse it into parts; we only need the email address part for the ics file
    Address[] addrs = Address.parse(meetingInfo.get(MeetingInfo.MEETING_ORGANIZER_EMAIL));
    // It shouldn't be possible, but handle it anyway
    if (addrs.length != 1)
        return;
    String organizerEmail = addrs[0].getAddress();

    String dtStamp = meetingInfo.get(MeetingInfo.MEETING_DTSTAMP);
    String dtStart = meetingInfo.get(MeetingInfo.MEETING_DTSTART);
    String dtEnd = meetingInfo.get(MeetingInfo.MEETING_DTEND);

    // What we're doing here is to create an Entity that looks like an Event as it would be
    // stored by CalendarProvider
    ContentValues entityValues = new ContentValues();
    Entity entity = new Entity(entityValues);

    // Fill in times, location, title, and organizer
    entityValues.put("DTSTAMP", CalendarUtilities.convertEmailDateTimeToCalendarDateTime(dtStamp));
    entityValues.put(Events.DTSTART, Utility.parseEmailDateTimeToMillis(dtStart));
    entityValues.put(Events.DTEND, Utility.parseEmailDateTimeToMillis(dtEnd));
    entityValues.put(Events.EVENT_LOCATION, meetingInfo.get(MeetingInfo.MEETING_LOCATION));
    entityValues.put(Events.TITLE, meetingInfo.get(MeetingInfo.MEETING_TITLE));
    entityValues.put(Events.ORGANIZER, organizerEmail);

    // Add ourselves as an attendee, using our account email address
    ContentValues attendeeValues = new ContentValues();
    attendeeValues.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ATTENDEE);
    attendeeValues.put(Attendees.ATTENDEE_EMAIL, mAccount.mEmailAddress);
    entity.addSubValue(Attendees.CONTENT_URI, attendeeValues);

    // Add the organizer
    ContentValues organizerValues = new ContentValues();
    organizerValues.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ORGANIZER);
    organizerValues.put(Attendees.ATTENDEE_EMAIL, organizerEmail);
    entity.addSubValue(Attendees.CONTENT_URI, organizerValues);

    // Create a message from the Entity we've built.  The message will have fields like
    // to, subject, date, and text filled in.  There will also be an "inline" attachment
    // which is in iCalendar format
    int flag;
    switch (response) {
    case EmailServiceConstants.MEETING_REQUEST_ACCEPTED:
        flag = Message.FLAG_OUTGOING_MEETING_ACCEPT;
        break;
    case EmailServiceConstants.MEETING_REQUEST_DECLINED:
        flag = Message.FLAG_OUTGOING_MEETING_DECLINE;
        break;
    case EmailServiceConstants.MEETING_REQUEST_TENTATIVE:
    default:
        flag = Message.FLAG_OUTGOING_MEETING_TENTATIVE;
        break;
    }
    Message outgoingMsg = CalendarUtilities.createMessageForEntity(mContext, entity, flag,
            meetingInfo.get(MeetingInfo.MEETING_UID), mAccount);
    // Assuming we got a message back (we might not if the event has been deleted), send it
    if (outgoingMsg != null) {
        EasOutboxService.sendMessage(mContext, mAccount.mId, outgoingMsg);
    }
}