コード例 #1
0
 private static ContentProviderOperation updateEvent(
     long calendar_id, Account account, Event event, long raw_id) {
   ContentProviderOperation.Builder builder;
   if (raw_id != -1) {
     builder =
         ContentProviderOperation.newUpdate(
             Events.CONTENT_URI
                 .buildUpon()
                 .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                 .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                 .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                 .build());
     builder.withSelection(Events._ID + " = '" + raw_id + "'", null);
   } else {
     builder =
         ContentProviderOperation.newInsert(
             Events.CONTENT_URI
                 .buildUpon()
                 .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                 .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                 .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                 .build());
   }
   long dtstart = event.getStartDate().getTime();
   long dtend = dtstart + (1000 * 60 * 60);
   if (event.getEndDate() != null) dtend = event.getEndDate().getTime();
   builder.withValue(Events.CALENDAR_ID, calendar_id);
   builder.withValue(Events.DTSTART, dtstart);
   builder.withValue(Events.DTEND, dtend);
   builder.withValue(Events.TITLE, event.getTitle());
   builder.withValue(
       Events.EVENT_LOCATION,
       event.getVenue().getName()
           + "\n"
           + event.getVenue().getLocation().getCity()
           + "\n"
           + event.getVenue().getLocation().getCountry());
   if (Integer.valueOf(event.getStatus()) == 1)
     builder.withValue(Events.STATUS, Events.STATUS_TENTATIVE);
   else builder.withValue(Events.STATUS, Events.STATUS_CONFIRMED);
   builder.withValue(Events._SYNC_ID, Long.valueOf(event.getId()));
   return builder.build();
 }
コード例 #2
0
  private static ContentProviderOperation updateEvent(
      long calendar_id, Account account, Event event, long raw_id) {
    ContentProviderOperation.Builder builder;
    if (raw_id != -1) {
      builder =
          ContentProviderOperation.newUpdate(
              Events.CONTENT_URI
                  .buildUpon()
                  .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                  .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                  .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                  .build());
      builder.withSelection(Events._ID + " = '" + raw_id + "'", null);
    } else {
      builder =
          ContentProviderOperation.newInsert(
              Events.CONTENT_URI
                  .buildUpon()
                  .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                  .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                  .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                  .build());
    }
    long dtstart = event.getStartDate().getTime();
    long dtend = dtstart + (1000 * 60 * 60);
    if (event.getEndDate() != null) dtend = event.getEndDate().getTime();
    builder.withValue(Events.CALENDAR_ID, calendar_id);
    builder.withValue(Events.DTSTART, dtstart);
    builder.withValue(Events.DTEND, dtend);
    builder.withValue(Events.TITLE, event.getTitle());

    String location = "";
    if (event.getVenue().getName().length() > 0) location += event.getVenue().getName() + "\n";
    if (event.getVenue().getLocation().getCity().length() > 0)
      location += event.getVenue().getLocation().getCity() + "\n";
    if (event.getVenue().getLocation().getCountry().length() > 0)
      location += event.getVenue().getLocation().getCountry() + "\n";

    builder.withValue(Events.EVENT_LOCATION, location);

    String description = "http://www.last.fm/event/" + event.getId() + "\n\n";

    if (event.getArtists().length > 0) {
      description += "LINEUP\n";
      for (String artist : event.getArtists()) {
        description += artist + "\n";
      }
      description += "\n";
    }

    if (event.getDescription() != null && event.getDescription().length() > 0) {
      description += "MORE DETAILS\n";
      description += event.getDescription();
    }

    builder.withValue(Events.DESCRIPTION, description);

    if (Integer.valueOf(event.getStatus()) == 1)
      builder.withValue(Events.STATUS, Events.STATUS_TENTATIVE);
    else builder.withValue(Events.STATUS, Events.STATUS_CONFIRMED);
    builder.withValue(Events._SYNC_ID, Long.valueOf(event.getId()));
    return builder.build();
  }