public void performCollapse ( boolean hasFocus ) { internalEditInProgress = true ; if ( ! hasFocus ) { // Display +x thingy/ellipse if appropriate final Editable text = getText ( ) ; if ( text != null && hiddenContent == null && lastLayout != null ) { //Ellipsize copies spans, so we need to stop listening to span changes here text . removeSpan ( spanWatcher ) ; CountSpan temp = preventFreeFormText ? countSpan : null ; Spanned ellipsized = SpanUtils . ellipsizeWithSpans ( prefix , temp , getObjects ( ) . size ( ) , lastLayout . getPaint ( ) , text , maxTextWidth ( ) ) ; if ( ellipsized != null ) { hiddenContent = new SpannableStringBuilder ( text ) ; setText ( ellipsized ) ; TextUtils . copySpansFrom ( ellipsized , 0 , ellipsized . length ( ) , TokenImageSpan . class , getText ( ) , 0 ) ; TextUtils . copySpansFrom ( text , 0 , hiddenContent . length ( ) , TokenImageSpan . class , hiddenContent , 0 ) ; hiddenContent . setSpan ( spanWatcher , 0 , hiddenContent . length ( ) , Spanned . SPAN_INCLUSIVE_INCLUSIVE ) ; } else { getText ( ) . setSpan ( spanWatcher , 0 , getText ( ) . length ( ) , Spanned . SPAN_INCLUSIVE_INCLUSIVE ) ; } } } else { if ( hiddenContent != null ) { setText ( hiddenContent ) ; TextUtils . copySpansFrom ( hiddenContent , 0 , hiddenContent . length ( ) , TokenImageSpan . class , getText ( ) , 0 ) ; hiddenContent = null ; if ( hintVisible ) { setSelection ( prefix . length ( ) ) ; } else { post ( new Runnable ( ) { @ Override public void run ( ) { setSelection ( getText ( ) . length ( ) ) ; } } ) ; } TokenSpanWatcher [ ] watchers = getText ( ) . getSpans ( 0 , getText ( ) . length ( ) , TokenSpanWatcher . class ) ; if ( watchers . length == 0 ) { //Span watchers can get removed in setText getText ( ) . setSpan ( spanWatcher , 0 , getText ( ) . length ( ) , Spanned . SPAN_INCLUSIVE_INCLUSIVE ) ; } } } internalEditInProgress = false ; }
Collapse the view by removing all the tokens not on the first line . Displays a + x token . Restores the hidden tokens when the view gains focus .