private static GEvent newGEvent(Event event, GCalendar calendar) {
    DateTime start = event.getStart().getDateTime();
    DateTime end = event.getEnd().getDateTime();
    if (start == null) {
      // All-day events don't have start times, so just use
      // the start date.
      start = event.getStart().getDate();
    }
    if (end == null) {
      end = event.getEnd().getDate();
    }
    Calendar startEvent = new GregorianCalendar();
    Calendar endEvent = new GregorianCalendar();
    startEvent.setTime(new Date(start.getValue()));
    endEvent.setTime(new Date(end.getValue()));

    //        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd H:m:s");
    //        Log.d("gevent", "start = " + format1.format(startEvent.getTime()) + ", end = " +
    // format1.format(endEvent.getTime()));

    GEvent nEvent = new GEvent(event.getSummary(), startEvent, endEvent);
    nEvent.SetBackgroundColor(calendar.backgroundColor);
    nEvent.SetForegroundColor(calendar.foregroundColor);

    return nEvent;
  }
  public static dix.walton.moore.model.Event convertToOurEvent(Event googleEvent) {

    dix.walton.moore.model.Event internalEvent = new dix.walton.moore.model.Event();

    DateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM");
    DateFormat timeFormat = new SimpleDateFormat("HH:mm");
    String startString;
    try {
      startString = googleEvent.getStart().getDateTime().toString();
      int T = startString.indexOf('T');
      internalEvent.setEventDate(startString.substring(0, T));
      internalEvent.setStartTime(startString.substring(T + 1, T + 6));

      if (googleEvent.getEnd() != null) {
        String endString = googleEvent.getEnd().getDateTime().toString();
        T = endString.indexOf('T');
        internalEvent.setEndTime(endString.substring(T + 1, T + 6));
      }
    } catch (Exception e) {
      System.out.println("Exception thrown");
    }

    internalEvent.setId(googleEvent.getId());
    internalEvent.setLocation(googleEvent.getLocation());
    internalEvent.setTitle(googleEvent.getSummary());
    return internalEvent;
  }
  public void listAllEvents() throws IOException, ParseException {
    List<String[]> myList = new ArrayList<String[]>();

    eventsList = new ArrayList<Object[]>();

    com.google.api.services.calendar.Calendar service = getCalendarService();

    // List the next 10 events from the primary calendar.
    DateTime now = new DateTime(System.currentTimeMillis());
    Events events =
        service
            .events()
            .list("primary")
            .setMaxResults(20)
            .setTimeMin(now)
            .setOrderBy("startTime")
            .setSingleEvents(true)
            .execute();
    List<Event> items = events.getItems();
    for (Event e : items) {
      System.out.println(e.getSummary() + " , " + e.getStart());
    }
    if (items.size() == 0) {
      System.out.println("No upcoming events found.");
    } else {
      System.out.println("Upcoming events");
      for (Event event : items) {
        DateTime start = event.getStart().getDateTime();
        if (start == null) {
          start = event.getStart().getDate();
        }
        String today = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
        String startString =
            new SimpleDateFormat("MM/dd/yyyy")
                .format(
                    new SimpleDateFormat("yyyy-MM-dd").parse(start.toString().substring(0, 10)));
        Object[] eventArray = new Object[2];
        eventArray[0] = event.getSummary();
        eventArray[1] = start.toString().equals(today) ? "Today" : startString;
        eventsList.add(eventArray);
      }
    }
  }
 private void createOrUpdateEvent(
     final UpdateInfo updateInfo, final CalendarListEntry calendarEntry, final Event event)
     throws Exception {
   if (event.getStatus().equalsIgnoreCase("cancelled")) {
     System.out.println(
         "event " + event.getSummary() + "/" + event.getDescription() + " was canceled");
     final int deleted =
         jpaDaoService.execute(
             String.format(
                 "DELETE FROM Facet_GoogleCalendarEvent facet WHERE "
                     + "facet.apiKeyId=%s AND facet.googleId='%s'",
                 updateInfo.apiKey.getId(), event.getId()));
     System.out.println("deleted " + deleted + " calendar entry");
     return;
   }
   final String googleIdHash = hash(event.getId());
   final String calendarIdHash = hash(calendarEntry.getId());
   final ApiDataService.FacetQuery facetQuery =
       new ApiDataService.FacetQuery(
           "e.apiKeyId=? AND (e.googleId=? OR e.googleId=?) AND (e.calendarId=? OR e.calendarId=?)",
           updateInfo.apiKey.getId(),
           event.getId(),
           googleIdHash,
           calendarEntry.getId(),
           calendarIdHash);
   final ApiDataService.FacetModifier<GoogleCalendarEventFacet> facetModifier =
       new ApiDataService.FacetModifier<GoogleCalendarEventFacet>() {
         @Override
         public GoogleCalendarEventFacet createOrModify(
             GoogleCalendarEventFacet facet, final Long apiKeyId) {
           if (facet == null) {
             facet = new GoogleCalendarEventFacet(updateInfo.apiKey.getId());
             facet.googleId = event.getId().length() > 250 ? googleIdHash : event.getId();
             facet.guestId = updateInfo.apiKey.getGuestId();
             facet.api = updateInfo.apiKey.getConnector().value();
             facet.calendarId =
                 calendarEntry.getId().length() > 250 ? calendarIdHash : calendarEntry.getId();
           }
           facet.summary = event.getSummary();
           facet.setCreated(event.getCreated());
           facet.setAttendees(event.getAttendees());
           facet.etag = event.getEtag();
           facet.setStart(event.getStart());
           facet.endTimeUnspecified = event.getEndTimeUnspecified();
           facet.setEnd(event.getEnd());
           facet.colorId = event.getColorId();
           facet.setCreator(event.getCreator());
           facet.description = event.getDescription();
           facet.guestsCanSeeOtherGuests = event.getGuestsCanSeeOtherGuests();
           facet.hangoutLink = event.getHangoutLink();
           facet.htmlLink = event.getHtmlLink();
           facet.iCalUID = event.getICalUID();
           facet.kind = event.getKind();
           facet.location = event.getLocation();
           facet.locked = event.getLocked();
           facet.setOrganizer(event.getOrganizer());
           facet.setOriginalStartTime(event.getOriginalStartTime());
           facet.status = event.getStatus();
           facet.timeUpdated = System.currentTimeMillis();
           facet.transparency = event.getTransparency();
           facet.visibility = event.getVisibility();
           facet.setRecurrence(event.getRecurrence());
           if (event.getRecurringEventId() != null) {
             final String recurringEventIdHash = hash(event.getRecurringEventId());
             facet.recurringEventId =
                 event.getRecurringEventId().length() > 250
                     ? recurringEventIdHash
                     : event.getRecurringEventId();
           }
           facet.sequence = event.getSequence();
           facet.setUpdated(event.getUpdated());
           return facet;
         }
       };
   // we could use the resulting value (facet) from this call if we needed to do further processing
   // on it (e.g. passing it on to the datastore)
   apiDataService.createOrReadModifyWrite(
       GoogleCalendarEventFacet.class, facetQuery, facetModifier, updateInfo.apiKey.getId());
 }
Ejemplo n.º 5
0
  public Event(com.google.api.services.calendar.model.Event current, int $colorNumber) {
    name = current.getSummary();
    summary = current.getDescription();
    Calendar calS = Calendar.getInstance();
    Calendar calE = Calendar.getInstance();
    colorNumber = $colorNumber;
    // cal.setTimeInMillis(current.getStart().getDateTime().getValue());
    // startDate = cal;
    if (current.getStart().getDate() != null) {
      String[] date = current.getStart().getDate().toString().split("-");
      calS.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
      date = current.getEnd().getDate().toString().split("-");
      calE.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2]));
      startDate = calS;
      endDate = calE;
    } else {
      String date = current.getStart().getDateTime().toString();

      int dateCutoff = date.indexOf("T");
      int timeCutoff = date.indexOf("."); // to remove nanoseconds
      if (timeCutoff == -1) // if nanoseconds not set remove timezone shift
      timeCutoff = date.indexOf("-");
      if (timeCutoff == -1) // if timezone shift not set isolate time only
      timeCutoff = date.indexOf("Z");

      String time = date.substring(dateCutoff + 1, timeCutoff);
      String[] timeC = time.split(":");

      date = date.substring(0, dateCutoff);
      String[] dateC = date.split("-");

      calS.set(
          Integer.parseInt(dateC[0]),
          Integer.parseInt(dateC[1]) - 1,
          Integer.parseInt(dateC[2]),
          Integer.parseInt(timeC[0]),
          Integer.parseInt(timeC[1]),
          Integer.parseInt(timeC[2]));

      date = current.getEnd().getDateTime().toString();
      timeCutoff = date.indexOf(".");
      dateCutoff = date.indexOf("T");

      // to remove nanoseconds
      if (timeCutoff == -1) // if nanoseconds not set remove timezone shift
      timeCutoff = date.indexOf("-");
      if (timeCutoff == -1) // if timezone shift not set isolate time only
      timeCutoff = date.indexOf("Z");

      time = date.substring(dateCutoff + 1, timeCutoff);
      String[] timeE = time.split(":");

      date = date.substring(0, dateCutoff);
      dateC = date.split("-");
      calE.set(
          Integer.parseInt(dateC[0]),
          Integer.parseInt(dateC[1]) - 1,
          Integer.parseInt(dateC[2]),
          Integer.parseInt(timeE[0]),
          Integer.parseInt(timeE[1]),
          Integer.parseInt(timeE[2]));

      startDate = calS;
      endDate = calE;
    }

    id = current.getId();
    calendarName = current.getOrganizer().getDisplayName();
    // cal.setTimeInMillis(current.getEnd().getDateTime().getValue());
    // endDate = cal;
  }
 public String getSummary() {
   return event.getSummary();
 }