简体   繁体   中英

Google Calendar, Java : Set up google event colour and event date from timestamp

I am working on Google calendar and I would like to set colour for an event and to set event time from java timestamp object I have. Currently I cannot find anywhere which are the possible colors available and the format of colour string.

Below is the code I have with static date and time, and no colour. I tried to use the timestamp, but Google has some weird DateTime object. Also, I am unable to find any default format for colors. THe basic sample which contains date and time setting are static strings. That's so horrible, what kind of developer uses hardcoded date and time values as example to show how their date time api is. I hope I don't have to deal with such messed up API in future. Sorry for ranting, here is code :

  @Override
    public Event setUpEventToSave(GroupNotes groupNotes, Person person) {
        Event event = new Event();
        event.setSummary(groupNotes.getMnotetag());
        event.setDescription(groupNotes.getMnotetext());

        Event.Creator creator = new Event.Creator();
        creator.setDisplayName(person.getFirstName());
        creator.setEmail(person.getUsername());
        event.setCreator(creator);
        event.setDescription(groupNotes.getMnotetext());
// I have color in #colorid in DB, but that didn't work, which is standard
      //  event.setColorId(groupNotes.getMnotecolor());

        event.setSummary(groupNotes.getMnotetext());
        event.setLocation("Hamburg");

// How can i pass java timestamp below with system time zone?
        DateTime startDateTime = new DateTime("2015-08-07T09:00:00-07:00");
        EventDateTime start = new EventDateTime()
                .setDateTime(startDateTime)
                .setTimeZone("America/Los_Angeles");
        event.setStart(start);

        DateTime endDateTime = new DateTime("2015-08-07T17:00:00-07:00");
        EventDateTime end = new EventDateTime()
                .setDateTime(endDateTime)
                .setTimeZone("America/Los_Angeles");
        event.setEnd(end);


   /*     EventAttendee[] attendees = new EventAttendee[] {
                new EventAttendee().setEmail("lpage@example.com"),
                new EventAttendee().setEmail("sbrin@example.com"),
        };
        event.setAttendees(Arrays.asList(attendees));
*/

        EventReminder[] reminderOverrides = new EventReminder[] {
                new EventReminder().setMethod("email").setMinutes(24 * 60),
                new EventReminder().setMethod("popup").setMinutes(10),
        };
        Event.Reminders reminders = new Event.Reminders()
                .setUseDefault(false)
                .setOverrides(Arrays.asList(reminderOverrides));
        event.setReminders(reminders);


        return event;
    }

Any help would be nice. Thanks a lot. :-)

You can check all the possible colors in colors endpoint. Here is the sample response:

"event": {
  "1": {
  "background": "#a4bdfc",
   "foreground": "#1d1d1d"
  },
 "2": {
 "background": "#7ae7bf",
 "foreground": "#1d1d1d"
},
"3": {
 "background": "#dbadff",
 "foreground": "#1d1d1d"
},
"4": {
 "background": "#ff887c",
 "foreground": "#1d1d1d"
},

While inserting event, using event.insert , you can specify colorId. ColorId should be the one which is in colors.get response. You should give value as colorId="1" which takes value as below: "1": { "background": "#a4bdfc", "foreground": "#1d1d1d" },

Let me know if you still have issues. Also, check calendarList.update

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM