MraidNativeCommandHandler { void createCalendarEvent(final Context context, final Map<String, String> params) throws MraidCommandException { if (isCalendarAvailable(context)) { try { Map<String, Object> calendarParams = translateJSParamsToAndroidCalendarEventMapping(params); Intent intent = new Intent(Intent.ACTION_INSERT).setType(ANDROID_CALENDAR_CONTENT_TYPE); for (String key : calendarParams.keySet()) { Object value = calendarParams.get(key); if (value instanceof Long) { intent.putExtra(key, ((Long) value).longValue()); } else if (value instanceof Integer) { intent.putExtra(key, ((Integer) value).intValue()); } else { intent.putExtra(key, (String) value); } } intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } catch (ActivityNotFoundException e) { MoPubLog.d("no calendar app installed"); throw new MraidCommandException( "Action is unsupported on this device - no calendar app installed"); } catch (IllegalArgumentException e) { MoPubLog.d("create calendar: invalid parameters " + e.getMessage()); throw new MraidCommandException(e); } catch (Exception e) { MoPubLog.d("could not create calendar event"); throw new MraidCommandException(e); } } else { MoPubLog.d("unsupported action createCalendarEvent for devices pre-ICS"); throw new MraidCommandException("Action is " + "unsupported on this device (need Android version Ice Cream Sandwich or " + "above)"); } }  boolean isStorePictureSupported(Context context); static final String ANDROID_CALENDAR_CONTENT_TYPE; }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withMinimumValidParams_atLeastICS_shouldCreateEventIntent() throws Exception { setupCalendarParams(); subject.createCalendarEvent(context, params); verify(mraidCommandFailureListener, never()).onFailure(any(MraidCommandException.class)); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getType()).isEqualTo(ANDROID_CALENDAR_CONTENT_TYPE); assertThat(intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0); assertThat(intent.getStringExtra(CalendarContract.Events.TITLE)).isNotNull(); assertThat(intent.getLongExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, -1)).isNotEqualTo(-1); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withoutSecondsOnStartDate_atLeastICS_shouldCreateEventIntent() throws Exception { setupCalendarParams(); params.put("start", "2012-12-21T00:00-0500"); subject.createCalendarEvent(context, params); verify(mraidCommandFailureListener, never()).onFailure(any(MraidCommandException.class)); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getType()).isEqualTo(ANDROID_CALENDAR_CONTENT_TYPE); assertThat(intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0); assertThat(intent.getStringExtra(CalendarContract.Events.TITLE)).isNotNull(); assertThat(intent.getLongExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, -1)).isNotEqualTo(-1); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withDailyRecurrence_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "daily"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getType()).isEqualTo(ANDROID_CALENDAR_CONTENT_TYPE); assertThat(intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=DAILY;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withDailyRecurrence_withInterval_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "daily"); params.put("interval", "2"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=DAILY;INTERVAL=2;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withWeeklyRecurrence_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "weekly"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=WEEKLY;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withWeeklyRecurrence_withInterval_withOutWeekday_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "weekly"); params.put("interval", "7"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=WEEKLY;INTERVAL=7;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withWeeklyRecurrence_onAllWeekDays_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "weekly"); params.put("daysInWeek", "0,1,2,3,4,5,6"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=WEEKLY;BYDAY=SU,MO,TU,WE,TH,FR,SA;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withWeeklyRecurrence_onDuplicateWeekDays_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "weekly"); params.put("daysInWeek", "3,2,3,3,7,0"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=WEEKLY;BYDAY=WE,TU,SU;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withWeeklyRecurrence_withInterval_withWeekDay_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "weekly"); params.put("interval", "1"); params.put("daysInWeek", "1"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=WEEKLY;INTERVAL=1;BYDAY=MO;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withDailyRecurrence_withWeeklyRecurrence_withMonthlyOccurence_shouldCreateDailyCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "daily"); params.put("frequency", "daily"); params.put("frequency", "daily"); params.put("interval", "2"); params.put("daysInWeek", "1"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=DAILY;INTERVAL=2;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withMonthlyRecurrence_withOutInterval_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "monthly"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=MONTHLY;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withMonthlyRecurrence_withInterval_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "monthly"); params.put("interval", "2"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=MONTHLY;INTERVAL=2;"); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withMonthlyRecurrence_withOutInterval_withDaysOfMonth_shouldCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "monthly"); params.put("daysInMonth", "2,-15"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getStringExtra(CalendarContract.Events.RRULE)).isEqualTo("FREQ=MONTHLY;BYMONTHDAY=2,-15;"); }
@Ignore("Mraid 2.0") @Test public void createCalendarEvent_withMonthlyRecurrence_withInvalidDaysOfMonth_shouldNotCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "monthly"); params.put("daysInMonth", "55"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent).isNull(); assertThat(ShadowLog.getLogs().size()).isEqualTo(1); }
@Ignore("Mraid 2.0") @Test public void createCalendarEvent_withWeeklyRecurrence_withInvalidDaysOfWeek_shouldNotCreateCalendarIntent() throws Exception { setupCalendarParams(); params.put("frequency", "weekly"); params.put("daysInWeek", "-1,20"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent).isNull(); assertThat(ShadowLog.getLogs().size()).isEqualTo(1); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.HONEYCOMB_MR2) @Test public void createCalendarEvent_beforeIcs_shouldFireErrorEvent() throws Exception { subject.createCalendarEvent(context, params); verify(mraidCommandFailureListener).onFailure(any(MraidCommandException.class)); }
@Ignore("Mraid 2.0") @Test public void createCalendarEvent_withInvalidDate_shouldFireErrorEvent() throws Exception { params.put("start", "2013-08-14T09:00.-08:00"); params.put("description", "Some Event"); subject.createCalendarEvent(context, params); verify(mraidCommandFailureListener).onFailure(any(MraidCommandException.class)); }
@Ignore("Mraid 2.0") @Test public void createCalendarEvent_withMissingParameters_shouldFireErrorEvent() throws Exception { params.put("description", "Some Event"); subject.createCalendarEvent(context, params); verify(mraidCommandFailureListener).onFailure(any(MraidCommandException.class)); }
@Ignore("Mraid 2.0") @Test public void createCalendarEvent_withNullDate_shouldFireErrorEvent() throws Exception { params.put("start", null); params.put("description", "Some Event"); subject.createCalendarEvent(context, params); verify(mraidCommandFailureListener).onFailure(any(MraidCommandException.class)); }
@Ignore("Mraid 2.0") @Config(reportSdk = Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Test public void createCalendarEvent_withValidParamsAllExceptRecurrence_atLeastICS_shouldCreateEventIntent() throws Exception { setupCalendarParams(); params.put("location", "my house"); params.put("end", "2013-08-14T22:01:01-0000"); params.put("summary", "some description actually"); params.put("transparency", "transparent"); subject.createCalendarEvent(context, params); Intent intent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(intent.getType()).isEqualTo(ANDROID_CALENDAR_CONTENT_TYPE); assertThat(intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0); assertThat(intent.getStringExtra(CalendarContract.Events.TITLE)).isNotNull(); assertThat(intent.getStringExtra(CalendarContract.Events.DESCRIPTION)).isNotNull(); assertThat(intent.getStringExtra(CalendarContract.Events.EVENT_LOCATION)).isNotNull(); assertThat(intent.getLongExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, -1)).isNotEqualTo(-1); assertThat(intent.getLongExtra(CalendarContract.EXTRA_EVENT_END_TIME, -1)).isNotEqualTo(-1); assertThat(intent.getIntExtra(CalendarContract.Events.AVAILABILITY, -1)).isEqualTo(CalendarContract.Events.AVAILABILITY_FREE); }