public Calendar updateCalendar(Calendar calendar) throws IOException { View.header("Update Calendar"); Calendar entry = new Calendar(); entry.setSummary("Updated Calendar for Testing"); Calendar result = client.calendars().patch(calendar.getId(), entry).execute(); View.display(result); return result; }
public Calendar addCalendar() throws IOException { View.header("Add Calendar"); Calendar entry = new Calendar(); entry.setSummary("My agenda"); Calendar result = client.calendars().insert(entry).execute(); View.display(result); return result; }
private String getOrCreateCalendar() throws IOException { LOG.debug("Searching for calendar {}.", CalendarConstants.CALENDAR_ID_ACHIEVO); Calendars calendars = googleCalendarService.calendars(); String calendarId = findAchievoCalendarId(); if (calendarId == null) { Calendar calendar = new Calendar(); calendar.setSummary(CalendarConstants.CALENDAR_ID_ACHIEVO); LOG.debug( "Calendar {} not found creating new: {}", CalendarConstants.CALENDAR_ID_ACHIEVO, calendar); Calendar result = calendars.insert(calendar).execute(); calendarId = result.getId(); LOG.trace("Request:\n{}", calendar); LOG.trace("Response:\n{}", result); } return calendarId; }
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int calendarIndex = (int) info.id; if (calendarIndex < adapter.getCount()) { final CalendarInfo calendarInfo = adapter.getItem(calendarIndex); switch (item.getItemId()) { case CONTEXT_EDIT: startAddOrEditCalendarActivity(calendarInfo); return true; case CONTEXT_DELETE: new AlertDialog.Builder(this) .setTitle(R.string.delete_title) .setMessage(calendarInfo.summary) .setCancelable(false) .setPositiveButton( R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new AsyncDeleteCalendar(CalendarSampleActivity.this, calendarInfo).execute(); } }) .setNegativeButton(R.string.no, null) .create() .show(); return true; case CONTEXT_BATCH_ADD: List<Calendar> calendars = new ArrayList<Calendar>(); for (int i = 0; i < 3; i++) { Calendar cal = new Calendar(); cal.setSummary(calendarInfo.summary + " [" + (i + 1) + "]"); calendars.add(cal); } new AsyncBatchInsertCalendars(this, calendars).execute(); return true; } } return super.onContextItemSelected(item); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQUEST_AUTHORIZATION: if (resultCode == Activity.RESULT_OK) { AsyncLoadCalendars.run(this); } else { chooseAccount(); } break; case REQUEST_ACCOUNT_PICKER: if (resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) { String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { credential.setAccountName(accountName); SharedPreferences settings = getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putString(PREF_ACCOUNT_NAME, accountName); editor.commit(); AsyncLoadCalendars.run(this); } } break; case ADD_OR_EDIT_CALENDAR_REQUEST: if (resultCode == Activity.RESULT_OK) { Calendar calendar = new Calendar(); calendar.setSummary(data.getStringExtra("summary")); String id = data.getStringExtra("id"); if (id == null) { new AsyncInsertCalendar(this, calendar).execute(); } else { calendar.setId(id); new AsyncUpdateCalendar(this, id, calendar).execute(); } } break; } }
public void deleteCalendarsUsingBatch() throws IOException { View.header("Delete Calendars Using Batch"); BatchRequest batch = client.batch(); for (Calendar calendar : addedCalendarsUsingBatch) { client .calendars() .delete(calendar.getId()) .queue( batch, new JsonBatchCallback<Void>() { public void onSuccess(Void content, GoogleHeaders responseHeaders) { System.out.println("Delete is successful!"); } @Override public void onFailure(GoogleJsonError e, GoogleHeaders responseHeaders) { System.out.println("Error Message: " + e.getMessage()); } }); } batch.execute(); }
public void deleteCalendar(Calendar calendar) throws IOException { View.header("Delete Calendar"); client.calendars().delete(calendar.getId()).execute(); }
public void showEvents(Calendar calendar) throws IOException { View.header("Show Events"); Events feed = client.events().list(calendar.getId()).execute(); View.display(feed); }
public void addEvent(Calendar calendar, Event event) throws IOException { View.header("Add Event"); Event result = client.events().insert(calendar.getId(), event).execute(); View.display(result); }
void update(Calendar calendar) { id = calendar.getId(); summary = calendar.getSummary(); }