question: public int findEventPositionNearestTime ( Time time , long id ) { if ( mRowInfo == null ) { return 0 ; } long millis = time . toMillis ( false ) ; long minDistance = Integer . MAX_VALUE ; long idFoundMinDistance = Integer . MAX_VALUE ; int minIndex = 0 ; int idFoundMinIndex = 0 ; int eventInTimeIndex = - 1 ; int allDayEventInTimeIndex = - 1 ; int allDayEventDay = 0 ; int minDay = 0 ; boolean idFound = false ; int len = mRowInfo . size ( ) ; for ( int index = 0 ; index < len ; index ++ ) { RowInfo row = mRowInfo . get ( index ) ; if ( row . mType == TYPE_DAY ) { continue ; } if ( row . mEventId == id ) { if ( row . mEventStartTimeMilli == millis ) { return index ; } long distance = Math . abs ( millis - row . mEventStartTimeMilli ) ; if ( distance < idFoundMinDistance ) { idFoundMinDistance = distance ; idFoundMinIndex = index ; } idFound = true ; } if ( ! idFound ) { if ( millis >= row . mEventStartTimeMilli && millis <= row . mEventEndTimeMilli ) { if ( row . mAllDay ) { if ( allDayEventInTimeIndex == - 1 ) { allDayEventInTimeIndex = index ; allDayEventDay = row . mDay ; } } else if ( eventInTimeIndex == - 1 ) { eventInTimeIndex = index ; } } else if ( eventInTimeIndex == - 1 ) { long distance = Math . abs ( millis - row . mEventStartTimeMilli ) ; if ( distance < minDistance ) { minDistance = distance ; minIndex = index ; minDay = row . mDay ; } } } } if ( idFound ) { return idFoundMinIndex ; } if ( eventInTimeIndex != - 1 ) { return eventInTimeIndex ; } else if ( allDayEventInTimeIndex != - 1 && minDay != allDayEventDay ) { return allDayEventInTimeIndex ; } return minIndex ; }
target:  Finds the position in the cursor of the event that best matches the time and Id. It will try to find the event that has the specified id and start time, if such event doesn't exist, it will return the event with a matching id that is closest to the start time. If the id doesn't exist, it will return the event with start time closest to the specified time.