Issues with appearance, month-year and year, for date questions

I noticed with my clean Google Play version of ODK Collect (1.4.7, 1053), running on Android 5.1.1, that setting appearance::month-year or appearance::year in XLSForm for a date question does not do what it is supposed to. In both cases the app shows working month, date, and year spinners. I found this old issue https://code.google.com/p/opendatakit/issues/detail?id=873, issue 873, and it seems like this issue was supposed to have been fixed. Is there anything I am missing?

Here is my XML on dropbox https://www.dropbox.com/s/tw0d2df4cwi56iq/dateTimeChooser.xml?dl=0

James,

Confirmed as a problem and filed at
https://github.com/opendatakit/opendatakit/issues/1169. Code
contributions welcome.

Yaw

··· -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.

On Fri, Sep 11, 2015 at 2:43 PM, jameskpringle@gmail.com wrote:

I noticed with my clean Google Play version of ODK Collect (1.4.7, 1053), running on Android 5.1.1, that setting appearance::month-year or appearance::year in XLSForm for a date question does not do what it is supposed to. In both cases the app shows working month, date, and year spinners. I found this old issue https://code.google.com/p/opendatakit/issues/detail?id=873, issue 873, and it seems like this issue was supposed to have been fixed. Is there anything I am missing?

Here is my XML on dropbox https://www.dropbox.com/s/tw0d2df4cwi56iq/dateTimeChooser.xml?dl=0

--
You received this message because you are subscribed to the Google Groups "ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I will be happy to contribute if only I can find a solution. Here is what I did:

From the current Collect code, I noticed the month and/or day visibility is set by this chunk in DateWidget.java:

This looks a lot like a hack because it is bypassing an API and going after the internals of the java class, i.e. if someone on Android decides to refactor the code and rename the class member something other than mDaySpinner then Collect's code will no longer work. In fact, it looks like something similar happened.

I am not too certain how to find the real Android source code, but googling led me to this http://grepcode.com/file_/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-1/android/widget/DatePicker.java/?v=source. I noticed that the Collect code above only sees mDelegate, LOG_TAG, MODE_CALENDAR, and MODE_SPINNER in the enhanced for loop. What it needs to do is loop through the member fields of mDelegate (according to the Android code I found).

This is where I am getting beyond the bounds of my knowledge and experience. I tried looping through the fields of mDelegate. I can get a field that is mDaySpinner. However, Field.get(Object) gives my an IllegalArgumentException:

java.lang.IllegalArgumentException: Expected receiver of type android.widget.DatePicker$DatePickerSpinnerDelegate, but got java.lang.Class<android.widget.DatePicker$DatePickerSpinnerDelegate>

See

It seems like android.widget.DatePicker$DatePickerSpinnerDelegate is not visible to Collect, so I think I am at a dead end. But I am also not very savvy with this reflect package.

Any help on how to move forward would be appreciated.

··· #########################

Obviously this is a very small piece of ODK Collect, so maybe it is not worth it to try to fix. There are ways around it for survey creators, like single select and integer entry to take place of month and date entry. However, if it is worth it to fix it, then maybe there should be a better solution than using reflect. Perhaps Collect should use a custom set of spinners for year and month or just year. It seems like digging around Android source code with reflect is not the way to go. Perhaps Dr. Sundt has some thoughts as he was the person to contribute the current code for DateWidget.java?

Sounds like reasonable progress, James. Mitch is on vacation but this
issue has been filed so hopefully he can take a look soon.

And yeah, there are good workarounds, so I'd use those until this gets fixed.

Yaw

··· -- Need ODK services? http://nafundi.com provides form design, server setup, professional support, and software development for ODK.

On Mon, Sep 14, 2015 at 11:40 AM, jameskpringle@gmail.com wrote:

I will be happy to contribute if only I can find a solution. Here is what I did:

From the current Collect code, I noticed the month and/or day visibility is set by this chunk in DateWidget.java:

https://github.com/opendatakit/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L168-L196

This looks a lot like a hack because it is bypassing an API and going after the internals of the java class, i.e. if someone on Android decides to refactor the code and rename the class member something other than mDaySpinner then Collect's code will no longer work. In fact, it looks like something similar happened.

I am not too certain how to find the real Android source code, but googling led me to this http://grepcode.com/file_/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-1/android/widget/DatePicker.java/?v=source. I noticed that the Collect code above only sees mDelegate, LOG_TAG, MODE_CALENDAR, and MODE_SPINNER in the enhanced for loop. What it needs to do is loop through the member fields of mDelegate (according to the Android code I found).

This is where I am getting beyond the bounds of my knowledge and experience. I tried looping through the fields of mDelegate. I can get a field that is mDaySpinner. However, Field.get(Object) gives my an IllegalArgumentException:

java.lang.IllegalArgumentException: Expected receiver of type android.widget.DatePicker$DatePickerSpinnerDelegate, but got java.lang.Class<android.widget.DatePicker$DatePickerSpinnerDelegate>

See
https://github.com/jkpr/collect-fixed/blob/dateFix/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L184-L185

It seems like android.widget.DatePicker$DatePickerSpinnerDelegate is not visible to Collect, so I think I am at a dead end. But I am also not very savvy with this reflect package.

Any help on how to move forward would be appreciated.

#########################

Obviously this is a very small piece of ODK Collect, so maybe it is not worth it to try to fix. There are ways around it for survey creators, like single select and integer entry to take place of month and date entry. However, if it is worth it to fix it, then maybe there should be a better solution than using reflect. Perhaps Collect should use a custom set of spinners for year and month or just year. It seems like digging around Android source code with reflect is not the way to go. Perhaps Dr. Sundt has some thoughts as he was the person to contribute the current code for DateWidget.java?

--
You received this message because you are subscribed to the Google Groups "ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yes, this is entirely a (necessary) hack.
If there is a new public API to manage what is displayed, you can do
something like:

int version = android.os.Build.VERSION.SDK_INT; if ( version < ??? ) { //
existing hack } else { // perhaps use a public API to alter what is
displayed? } This would allow the code to adjust at runtime based upon the
Android OS version. From the description, it sounds like the newer Android
OS and/or SDK has changed this widget and the reflection hack no longer
works. I would search first for whether there was a way to avoid that via a
public API before continuing to add layers to this hack.

··· On Tue, Sep 15, 2015 at 8:26 AM, Yaw Anokwa wrote:

Sounds like reasonable progress, James. Mitch is on vacation but this
issue has been filed so hopefully he can take a look soon.

And yeah, there are good workarounds, so I'd use those until this gets
fixed.

Yaw

Need ODK services? http://nafundi.com provides form design, server
setup, professional support, and software development for ODK.

On Mon, Sep 14, 2015 at 11:40 AM, jameskpringle@gmail.com wrote:

I will be happy to contribute if only I can find a solution. Here is
what I did:

From the current Collect code, I noticed the month and/or day visibility
is set by this chunk in DateWidget.java:

https://github.com/opendatakit/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L168-L196

This looks a lot like a hack because it is bypassing an API and going
after the internals of the java class, i.e. if someone on Android decides
to refactor the code and rename the class member something other than
mDaySpinner then Collect's code will no longer work. In fact, it looks
like something similar happened.

I am not too certain how to find the real Android source code, but
googling led me to this
http://grepcode.com/file_/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-1/android/widget/DatePicker.java/?v=source.
I noticed that the Collect code above only sees mDelegate, LOG_TAG,
MODE_CALENDAR, and MODE_SPINNER in the enhanced for loop. What it
needs to do is loop through the member fields of mDelegate (according to
the Android code I found).

This is where I am getting beyond the bounds of my knowledge and
experience. I tried looping through the fields of mDelegate. I can get a
field that is mDaySpinner. However, Field.get(Object) gives my an
IllegalArgumentException:

java.lang.IllegalArgumentException: Expected receiver of type
android.widget.DatePicker$DatePickerSpinnerDelegate, but got
java.lang.Class<android.widget.DatePicker$DatePickerSpinnerDelegate>

See

https://github.com/jkpr/collect-fixed/blob/dateFix/collect_app/src/main/java/org/odk/collect/android/widgets/DateWidget.java#L184-L185

It seems like android.widget.DatePicker$DatePickerSpinnerDelegate is not
visible to Collect, so I think I am at a dead end. But I am also not very
savvy with this reflect package.

Any help on how to move forward would be appreciated.

#########################

Obviously this is a very small piece of ODK Collect, so maybe it is not
worth it to try to fix. There are ways around it for survey creators, like
single select and integer entry to take place of month and date entry.
However, if it is worth it to fix it, then maybe there should be a better
solution than using reflect. Perhaps Collect should use a custom set of
spinners for year and month or just year. It seems like digging around
Android source code with reflect is not the way to go. Perhaps Dr. Sundt
has some thoughts as he was the person to contribute the current code for
DateWidget.java?

--
You received this message because you are subscribed to the Google
Groups "ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

A post was split to a new topic: Click to select specific year