当前位置: 首页>>代码示例>>Java>>正文


Java Calendar类代码示例

本文整理汇总了Java中com.google.api.services.calendar.Calendar的典型用法代码示例。如果您正苦于以下问题:Java Calendar类的具体用法?Java Calendar怎么用?Java Calendar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Calendar类属于com.google.api.services.calendar包,在下文中一共展示了Calendar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkValidAddress

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
/**
 * verifies that an address url is a valid Calendar address Saber can
 * sync with
 * @param address (String) google calendar address
 * @param service connected calendar service with user credentials
 * @return (boolean) true if valid
 */
public boolean checkValidAddress(String address, Calendar service)
{
    try
    {
        service.events().list(address)
                .setTimeMin(new DateTime(ZonedDateTime.now().format(EventRecurrence.RFC3339_FORMATTER)))
                .setTimeMax(new DateTime(ZonedDateTime.now().plusDays(7).format(EventRecurrence.RFC3339_FORMATTER)))
                .setOrderBy("startTime")
                .setSingleEvents(true)
                .setMaxResults(Main.getBotSettingsManager().getMaxEntries())
                .execute();

        return true;
    }
    catch(Exception e)
    {
        return false;
    }

}
 
开发者ID:notem,项目名称:Saber-Bot,代码行数:28,代码来源:CalendarConverter.java

示例2: eventExists

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
public static boolean eventExists(GuildSettings settings, String eventId) {
	//TODO: Support multiple calendars...
	String calendarId = DatabaseManager.getManager().getMainCalendar(settings.getGuildID()).getCalendarAddress();
	try {
		Calendar service;
		if (settings.useExternalCalendar()) {
			service = CalendarAuth.getCalendarService(settings);
		} else {
			service = CalendarAuth.getCalendarService();
		}
		return service.events().get(calendarId, eventId).execute() != null;
	} catch (Exception e) {
		//Failed to check event, probably doesn't exist, safely ignore.
	}
	return false;
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:17,代码来源:EventUtils.java

示例3: deleteCalendar

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
/**
 * Deletes a calendar from Google Calendar and the Db
 *
 * @param data The BotData of the Guild whose deleting their calendar.
 * @return <code>true</code> if successful, else <code>false</code>.
 */
public static Boolean deleteCalendar(CalendarData data, GuildSettings settings) {
	try {
		//Only delete if the calendar is stored on DisCal's account.
		if (!data.getCalendarAddress().equalsIgnoreCase("primary") && !settings.useExternalCalendar()) {
			Calendar service = CalendarAuth.getCalendarService();
			service.calendars().delete(data.getCalendarAddress()).execute();
		}
	} catch (IOException e) {
		//Fail silently.
		ExceptionHandler.sendException(null, "Failed to delete calendar", e, CalendarUtils.class);
		return false;
	}
	if (settings.useExternalCalendar()) {
		//Update settings.
		settings.setUseExternalCalendar(false);
		settings.setEncryptedAccessToken("N/a");
		settings.setEncryptedRefreshToken("N/a");
		DatabaseManager.getManager().updateSettings(settings);
	}

	//Delete everything that is specific to the calendar...
	DatabaseManager.getManager().deleteCalendar(data);
	DatabaseManager.getManager().deleteAllEventData(data.getGuildId());
	DatabaseManager.getManager().deleteAllRSVPData(data.getGuildId());
	DatabaseManager.getManager().deleteAllAnnouncementData(data.getGuildId());

	return true;
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:35,代码来源:CalendarUtils.java

示例4: getCalendars

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
/**
 * Gets the list of all calendars available in the account.
 *
 * @return A non-null list of all calendars.
 * @throws IOException For unexpected errors.
 */
public List<GoogleCalendar> getCalendars() throws IOException {
    List<CalendarListEntry> calendarListEntries = dao.calendarList().list().execute().getItems();
    List<GoogleCalendar> calendars = new ArrayList<>();

    if (calendarListEntries != null && !calendarListEntries.isEmpty()) {
        for (int i = 0; i < calendarListEntries.size(); i++) {
            CalendarListEntry calendarListEntry = calendarListEntries.get(i);
            GoogleCalendar calendar = converter.convert(calendarListEntry, GoogleCalendar.class);
            calendar.setStyle(com.calendarfx.model.Calendar.Style.getStyle(i));
            calendars.add(calendar);
        }
    }

    return calendars;
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:22,代码来源:GoogleCalendarService.java

示例5: makeClient

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
@Override
public Calendar makeClient(String clientId, String clientSecret,
                           Collection<String> scopes, String applicationName, String refreshToken,
                           String accessToken, String emailAddress, String p12FileName, String user) {

    Credential credential;
    try {
        // if emailAddress and p12FileName values are present, assume Google Service Account
        if (null != emailAddress && !"".equals(emailAddress) && null != p12FileName && !"".equals(p12FileName)) {
            credential = authorizeServiceAccount(emailAddress, p12FileName, scopes, user);
        } else {
            credential = authorize(clientId, clientSecret, scopes);
            if (refreshToken != null && !"".equals(refreshToken)) {
                credential.setRefreshToken(refreshToken);
            }
            if (accessToken != null && !"".equals(accessToken)) {
                credential.setAccessToken(accessToken);
            }
        }
        return new Calendar.Builder(transport, jsonFactory, credential).setApplicationName(applicationName).build();
    } catch (Exception e) {
        LOG.error("Could not create Google Drive client.", e);
    }
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:BatchGoogleCalendarClientFactory.java

示例6: run

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
/**
 * Creates a test event, pauses while the user modifies the event in the Calendar UI, and then
 * checks if the event has been modified.
 */
private static void run() throws IOException {
  // Create a test event.
  Event event = Utils.createTestEvent(client, "Test Event");
  System.out.println(String.format("Event created: %s", event.getHtmlLink()));

  // Pause while the user modifies the event in the Calendar UI.
  System.out.println("Modify the event's description and hit enter to continue.");
  System.in.read();

  // Fetch the event again if it's been modified.
  Calendar.Events.Get getRequest = client.events().get("primary", event.getId());
  getRequest.setRequestHeaders(new HttpHeaders().setIfNoneMatch(event.getEtag()));
  try {
    event = getRequest.execute();
    System.out.println("The event was modified, retrieved latest version.");
  } catch (GoogleJsonResponseException e) {
    if (e.getStatusCode() == 304) {
      // A 304 status code, "Not modified", indicates that the etags match, and the event has
      // not been modified since we last retrieved it.
      System.out.println("The event was not modified, using local version.");
    } else {
      throw e;
    }
  }
}
 
开发者ID:googlesamples,项目名称:calendar-sync,代码行数:30,代码来源:ConditionalRetrievalSample.java

示例7: execute

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    logger.trace("going to upload {} calendar entries to Google now ...", entries.size());
    Calendar calendarClient = null;
    if (entries.size() > 0) {
        Credential credential = GCalGoogleOAuth.getCredential(false);
        if (credential == null) {
            logger.error(
                    "Please configure gcal:client_id/gcal:client_secret in openhab.cfg. Refer to wiki how to create client_id/client_secret pair");
        } else {
            // set up global Calendar instance
            calendarClient = new com.google.api.services.calendar.Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY,
                    credential).setApplicationName("openHABpersistence").build();
        }
    }
    for (Event entry : entries) {
        upload(calendarClient, entry);
        entries.remove(entry);
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:21,代码来源:GCalPersistenceService.java

示例8: createCalendarEvent

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
/**
 * Creates a new calendar entry.
 *
 * @param event the event to create in the remote calendar identified by the
 *            full calendar feed configured in </code>openhab.cfg</code>
 * @return the newly created entry
 * @throws IOException
 */
private Event createCalendarEvent(Calendar calendarClient, Event event) throws IOException {

    if (calendarClient == null) {
        logger.error(
                "Please configure gcal:client_id/gcal:client_secret in openhab.cfg. Refer to wiki how to create client_id/client_secret pair");
    } else {
        // set up global Calendar instance
        CalendarListEntry calendarID = GCalGoogleOAuth.getCalendarId(calendar_name);
        if (calendarID != null) {
            return calendarClient.events().insert(calendarID.getId(), event).execute();
        }

    }

    return null;

}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:26,代码来源:GCalPersistenceService.java

示例9: getCalendarEventCount

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
private Integer getCalendarEventCount() throws GeneralSecurityException, IOException {
    NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

    TokenResponse tokenResponse = new TokenResponse();
    tokenResponse.setRefreshToken(REFRESH_TOKEN);
    Credential credential = createCredentialWithRefreshToken(httpTransport, jsonFactory, tokenResponse);

    Calendar calendar = new com.google.api.services.calendar.Calendar.Builder(
            httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build();

    Calendar.Events.List events = calendar.events().list(CALENDAR_ID);

    return events.execute().getItems().size();
}
 
开发者ID:synyx,项目名称:urlaubsverwaltung,代码行数:16,代码来源:GoogleCalendarSyncProviderServiceTest.java

示例10: getService

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
private Calendar getService(GuildSettings gs) throws Exception {
	if (gs.useExternalCalendar()) {
		if (!customServices.containsKey(gs.getGuildID())) {
			customServices.put(gs.getGuildID(), CalendarAuth.getCalendarService(gs));
		}
		return customServices.get(gs.getGuildID());
	}
	return discalService;
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:10,代码来源:AnnouncementTask.java

示例11: init

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
public PreEvent init(MessageReceivedEvent e, String eventId, GuildSettings settings, boolean handleMessage) {
	if (!hasPreEvent(e.getGuild().getLongID())) {
		//TODO: Handle multiple calendars...
		try {
			String calId = DatabaseManager.getManager().getMainCalendar(e.getGuild().getLongID()).getCalendarAddress();
			Calendar service;
			if (settings.useExternalCalendar()) {
				service = CalendarAuth.getCalendarService(settings);
			} else {
				service = CalendarAuth.getCalendarService();
			}
			Event calEvent = service.events().get(calId, eventId).execute();

			PreEvent event = EventUtils.copyEvent(e.getGuild().getLongID(), calEvent);

			try {
				event.setTimeZone(service.calendars().get(calId).execute().getTimeZone());
			} catch (IOException e1) {
				//Failed to get tz, ignore safely.
			}

			if (handleMessage) {
				if (PermissionChecker.botHasMessageManagePerms(e)) {
					IMessage message = Message.sendMessage(EventMessageFormatter.getPreEventEmbed(event, settings), MessageManager.getMessage("Creator.Event.Copy.Init", settings), e);
					event.setCreatorMessage(message);
					Message.deleteMessage(e);
				} else {
					Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
				}
			}

			events.add(event);
			return event;
		} catch (Exception exc) {
			//Something failed...
		}
		return null;
	}
	return getPreEvent(e.getGuild().getLongID());
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:41,代码来源:EventCreator.java

示例12: insertCalendar

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
/**
 * Inserts a calendar into the google calendar.
 *
 * @param calendar The calendar to be inserted.
 * @throws IOException For unexpected errors.
 */
public void insertCalendar(GoogleCalendar calendar) throws IOException {
    com.google.api.services.calendar.model.Calendar cal;
    cal = converter.convert(calendar, com.google.api.services.calendar.model.Calendar.class);
    cal = dao.calendars().insert(cal).execute();
    calendar.setId(cal.getId());
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:13,代码来源:GoogleCalendarService.java

示例13: CalendarRequestTask

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
public CalendarRequestTask(GoogleAccountCredential credential) {
    mCredential = credential;
    HttpTransport transport = AndroidHttp.newCompatibleTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    mService = new com.google.api.services.calendar.Calendar.Builder(
            transport, jsonFactory, credential)
            .setApplicationName("Family Calendar")
            .build();
}
 
开发者ID:ITVlab,项目名称:Family-Calendar,代码行数:10,代码来源:CalendarRequestTask.java

示例14: GoogleCalendar

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
GoogleCalendar(CredentialConfig config) throws Exception {
	this.GOOGLE_CREDENTIAL = authenticate(config);

	this.CALENDAR = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, GOOGLE_CREDENTIAL)
	.setApplicationName("GGsync")
	.build();

	this.RECURRENCE_SDF.setTimeZone(TimeZone.getTimeZone("UTC"));
}
 
开发者ID:cybozu,项目名称:garoon-google,代码行数:10,代码来源:GoogleCalendar.java

示例15: MakeRequestTask

import com.google.api.services.calendar.Calendar; //导入依赖的package包/类
public MakeRequestTask(GoogleAccountCredential credential) {
    HttpTransport transport = AndroidHttp.newCompatibleTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    mService = new com.google.api.services.calendar.Calendar.Builder(
            transport, jsonFactory, credential)
            .setApplicationName("Coordinatr")
            .build();
}
 
开发者ID:ThisChessPlayer,项目名称:GroupScheduleCoordinator,代码行数:9,代码来源:MainActivity.java


注:本文中的com.google.api.services.calendar.Calendar类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。