Search in sources :

Example 1 with DateWidget

use of org.odk.collect.android.widgets.DateWidget in project collect by opendatakit.

the class DaylightSavingTest method prepareDateTimeWidget.

private DateTimeWidget prepareDateTimeWidget(int year, int month, int day, int hour, int minute) {
    QuestionDef questionDefStub = mock(QuestionDef.class);
    IFormElement iformElementStub = mock(IFormElement.class);
    FormEntryPrompt formEntryPromptStub = mock(FormEntryPrompt.class);
    when(iformElementStub.getAdditionalAttribute(anyString(), anyString())).thenReturn(null);
    when(formEntryPromptStub.getQuestion()).thenReturn(questionDefStub);
    when(formEntryPromptStub.getFormElement()).thenReturn(iformElementStub);
    when(formEntryPromptStub.getQuestion().getAppearanceAttr()).thenReturn("no-calendar");
    DateWidget dateWidget = mock(DateWidget.class);
    when(dateWidget.getDate()).thenReturn(new LocalDateTime().withYear(year).withMonthOfYear(month).withDayOfMonth(day));
    TimeWidget timeWidget = mock(TimeWidget.class);
    when(timeWidget.getHour()).thenReturn(hour);
    when(timeWidget.getMinute()).thenReturn(minute);
    DateTimeWidget dateTimeWidget = new DateTimeWidget(RuntimeEnvironment.application, formEntryPromptStub);
    dateTimeWidget.setDateWidget(dateWidget);
    dateTimeWidget.setTimeWidget(timeWidget);
    return dateTimeWidget;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) IFormElement(org.javarosa.core.model.IFormElement) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DateWidget(org.odk.collect.android.widgets.DateWidget) DateTimeWidget(org.odk.collect.android.widgets.DateTimeWidget) QuestionDef(org.javarosa.core.model.QuestionDef) TimeWidget(org.odk.collect.android.widgets.TimeWidget) DateTimeWidget(org.odk.collect.android.widgets.DateTimeWidget)

Example 2 with DateWidget

use of org.odk.collect.android.widgets.DateWidget in project collect by opendatakit.

the class DaylightSavingTest method testEATTimezoneWithDateWidget.

@Test
public // 1 Jan 1960 at 00:00:00 clocks were turned forward to 00:15:00
void testEATTimezoneWithDateWidget() {
    TimeZone.setDefault(TimeZone.getTimeZone(EAT_IME_ZONE));
    DateWidget dateWidget = prepareDateWidget(1960, 0, 1);
    /*
         * We would get crash in this place using old approach {@link org.joda.time.DateTime} instead of
         * {@link org.joda.time.LocalDateTime}
         */
    dateWidget.getAnswer();
}
Also used : DateWidget(org.odk.collect.android.widgets.DateWidget) Test(org.junit.Test)

Example 3 with DateWidget

use of org.odk.collect.android.widgets.DateWidget in project collect by opendatakit.

the class DaylightSavingTest method prepareDateWidget.

private DateWidget prepareDateWidget(int year, int month, int day) {
    QuestionDef questionDefStub = mock(QuestionDef.class);
    IFormElement iformElementStub = mock(IFormElement.class);
    FormEntryPrompt formEntryPromptStub = mock(FormEntryPrompt.class);
    when(iformElementStub.getAdditionalAttribute(anyString(), anyString())).thenReturn(null);
    when(formEntryPromptStub.getQuestion()).thenReturn(questionDefStub);
    when(formEntryPromptStub.getFormElement()).thenReturn(iformElementStub);
    when(formEntryPromptStub.getQuestion().getAppearanceAttr()).thenReturn("no-calendar");
    DatePickerDialog datePickerDialog = mock(DatePickerDialog.class);
    DatePicker datePicker = mock(DatePicker.class);
    when(datePickerDialog.getDatePicker()).thenReturn(datePicker);
    when(datePickerDialog.getDatePicker().getYear()).thenReturn(year);
    when(datePickerDialog.getDatePicker().getMonth()).thenReturn(month);
    when(datePickerDialog.getDatePicker().getDayOfMonth()).thenReturn(day);
    DateWidget dateWidget = new DateWidget(RuntimeEnvironment.application, formEntryPromptStub);
    dateWidget.setDatePickerDialog(datePickerDialog);
    return dateWidget;
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DatePickerDialog(android.app.DatePickerDialog) DateWidget(org.odk.collect.android.widgets.DateWidget) DatePicker(android.widget.DatePicker) QuestionDef(org.javarosa.core.model.QuestionDef)

Aggregations

DateWidget (org.odk.collect.android.widgets.DateWidget)3 IFormElement (org.javarosa.core.model.IFormElement)2 QuestionDef (org.javarosa.core.model.QuestionDef)2 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 DatePickerDialog (android.app.DatePickerDialog)1 DatePicker (android.widget.DatePicker)1 LocalDateTime (org.joda.time.LocalDateTime)1 Test (org.junit.Test)1 DateTimeWidget (org.odk.collect.android.widgets.DateTimeWidget)1 TimeWidget (org.odk.collect.android.widgets.TimeWidget)1