android-times-square
android-times-square copied to clipboard
performance in dialogs
When I place times-square into an AlertDialog or DialogFragment, it's performance get worse. When you select a new date the old selection disappears some time after the new appears, which makes the experience in using it fairly bad.
We haven't done any work on using this view in a dialog (and frankly, probably won't invest much in this). Pull requests welcome!
I investigated the issue a little. When the view is in a DialogFragment on each notifyDataSetChanged and also on the first time the view is drawn, getView is called multiple times for each row view.
Here is how the log looks for the first initialization (I added a log for the case that the row view has to be inflated):
DEBUG/TimesSquare(2374): Creating MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Creating MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Creating MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='April 2013', month=3, year=2013} DEBUG/TimesSquare(2374): Creating MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='May 2013', month=4, year=2013}
This is the log for the sample app:
DEBUG/TimesSquare(2374): Creating MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='February 2013', month=1, year=2013} DEBUG/TimesSquare(2374): Creating MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='March 2013', month=2, year=2013} DEBUG/TimesSquare(2374): Creating MonthView for MonthDescriptor{label='April 2013', month=3, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='April 2013', month=3, year=2013} DEBUG/TimesSquare(2374): Initializing MonthView for MonthDescriptor{label='May 2013', month=4, year=2013}
I don't have any idea why this is happening, but will try to find the reason tomorrow.
@gabrielittner I did a little work on this today (#52) and found one slight optimization, but the root cause still eludes me (I'm on a plane and don't have the android src on my new laptop so I can't step through the OS code to figure out what's causing the re-measure). Let me know if you find/found anything out.
I just banged on this again some more: hierarchyviewer shows that some of the parent views in the custom dialog (customPanel/parentPanel in particular) have height = WRAP_CONTENT. I tried overriding that to MATCH_PARENT but that didn't help. Android still really wants to measure and re-measure the child views for some reason. I tried digging around in the android layout code but this time I don't have the right version of the android source on my computer so none of the line numbers match up. Giving up on this for now. @JakeWharton any ideas?
I think this might be related I'm having similar issues in an Activity, I get this log over and over again. I can't highlight a selection range more than two without them all unselecting and performance is very laggy. 05-13 11:11:15.602 4699-4699/com.app W/View﹕ requestLayout() improperly called by com.squareup.timessquare.CalendarCellView{430e0020 V.ED..C. ......ID 0,0-85,85} during layout: running second layout pass