@Override boolean resurrectSelection(){
  final int childCount=getChildCount();
  if (childCount <= 0) {
    return false;
  }
  int selectedTop=0;
  int selectedPos;
  int childrenTop=mListPadding.top;
  int childrenBottom=getBottom() - getTop() - mListPadding.bottom;
  final int firstPosition=mFirstPosition;
  final int toPosition=mResurrectToPosition;
  boolean down=true;
  if (toPosition >= firstPosition && toPosition < firstPosition + childCount) {
    selectedPos=toPosition;
    final View selected=getChildAt(selectedPos - mFirstPosition);
    selectedTop=selected.getTop();
    int selectedBottom=selected.getBottom();
    if (selectedTop < childrenTop) {
      selectedTop=childrenTop + getVerticalFadingEdgeLength();
    }
 else     if (selectedBottom > childrenBottom) {
      selectedTop=childrenBottom - selected.getMeasuredHeight() - getVerticalFadingEdgeLength();
    }
  }
 else {
    if (toPosition < firstPosition) {
      selectedPos=firstPosition;
      for (int i=0; i < childCount; i++) {
        final View v=getChildAt(i);
        final int top=v.getTop();
        if (i == 0) {
          selectedTop=top;
          if (firstPosition > 0 || top < childrenTop) {
            childrenTop+=getVerticalFadingEdgeLength();
          }
        }
        if (top >= childrenTop) {
          selectedPos=firstPosition + i;
          selectedTop=top;
          break;
        }
      }
    }
 else {
      final int itemCount=mItemCount;
      down=false;
      selectedPos=firstPosition + childCount - 1;
      for (int i=childCount - 1; i >= 0; i--) {
        final View v=getChildAt(i);
        final int top=v.getTop();
        final int bottom=v.getBottom();
        if (i == childCount - 1) {
          selectedTop=top;
          if (firstPosition + childCount < itemCount || bottom > childrenBottom) {
            childrenBottom-=getVerticalFadingEdgeLength();
          }
        }
        if (bottom <= childrenBottom) {
          selectedPos=firstPosition + i;
          selectedTop=top;
          break;
        }
      }
    }
  }
  mResurrectToPosition=INVALID_POSITION;
  removeCallbacks(mFlingRunnable);
  mTouchMode=TOUCH_MODE_REST;
  clearScrollingCache();
  mSpecificTop=selectedTop;
  selectedPos=lookForSelectablePosition(selectedPos,down);
  if (selectedPos >= firstPosition && selectedPos <= getLastVisiblePosition()) {
    mLayoutMode=LAYOUT_SPECIFIC;
    setSelectionInt(selectedPos);
    invokeOnItemScrollListener();
  }
 else {
    selectedPos=INVALID_POSITION;
  }
  reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
  return selectedPos >= 0;
}

@ Override boolean resurrectSelection ( ) { final int childCount = getChildCount ( ) ; if ( childCount <= 0 ) { return false ; } int selectedTop = 0 ; int selectedPos ; int childrenTop = mListPadding . top ; int childrenBottom = getBottom ( ) - getTop ( ) - mListPadding . bottom ; final int firstPosition = mFirstPosition ; final int toPosition = mResurrectToPosition ; boolean down = true ; if ( toPosition >= firstPosition && toPosition < firstPosition + childCount ) { selectedPos = toPosition ; final View selected = getChildAt ( selectedPos - mFirstPosition ) ; selectedTop = selected . getTop ( ) ; int selectedBottom = selected . getBottom ( ) ; if ( selectedTop < childrenTop ) { selectedTop = childrenTop + getVerticalFadingEdgeLength ( ) ; } else if ( selectedBottom > childrenBottom ) { selectedTop = childrenBottom - selected . getMeasuredHeight ( ) - getVerticalFadingEdgeLength ( ) ; } } else { if ( toPosition < firstPosition ) { selectedPos = firstPosition ; for ( int i = 0 ; i < childCount ; i ++ ) { final View v = getChildAt ( i ) ; final int top = v . getTop ( ) ; if ( i == 0 ) { selectedTop = top ; if ( firstPosition > 0 || top < childrenTop ) { childrenTop += getVerticalFadingEdgeLength ( ) ; } } if ( top >= childrenTop ) { selectedPos = firstPosition + i ; selectedTop = top ; break ; } } } else { final int itemCount = mItemCount ; down = false ; selectedPos = firstPosition + childCount - 1 ; for ( int i = childCount - 1 ; i >= 0 ; i -- ) { final View v = getChildAt ( i ) ; final int top = v . getTop ( ) ; final int bottom = v . getBottom ( ) ; if ( i == childCount - 1 ) { selectedTop = top ; if ( firstPosition + childCount < itemCount || bottom > childrenBottom ) { childrenBottom -= getVerticalFadingEdgeLength ( ) ; } } if ( bottom <= childrenBottom ) { selectedPos = firstPosition + i ; selectedTop = top ; break ; } } } } mResurrectToPosition = INVALID_POSITION ; removeCallbacks ( mFlingRunnable ) ; mTouchMode = TOUCH_MODE_REST ; clearScrollingCache ( ) ; mSpecificTop = selectedTop ; selectedPos = lookForSelectablePosition ( selectedPos , down ) ; if ( selectedPos >= firstPosition && selectedPos <= getLastVisiblePosition ( ) ) { mLayoutMode = LAYOUT_SPECIFIC ; setSelectionInt ( selectedPos ) ; invokeOnItemScrollListener ( ) ; } else { selectedPos = INVALID_POSITION ; } reportScrollStateChange ( OnScrollListener . SCROLL_STATE_IDLE ) ; return selectedPos >= 0 ; }
attempt to bring the selection back if the user is switching from touch to trackball mode
