/** {@inheritDoc} */ public void displaySuggestions(boolean display) { // If nothing to change, return early if (display == isDisplayingSuggestions() || mMentionsEditText == null) { return; } // Change view depending on whether suggestions are being shown or not if (display) { disableSpellingSuggestions(true); mTextCounterView.setVisibility(View.GONE); mSuggestionsList.setVisibility(View.VISIBLE); mPrevEditTextParams = mMentionsEditText.getLayoutParams(); mPrevEditTextBottomPadding = mMentionsEditText.getPaddingBottom(); mMentionsEditText.setPadding( mMentionsEditText.getPaddingLeft(), mMentionsEditText.getPaddingTop(), mMentionsEditText.getPaddingRight(), mMentionsEditText.getPaddingTop()); int height = mMentionsEditText.getPaddingTop() + mMentionsEditText.getLineHeight() + mMentionsEditText.getPaddingBottom(); mMentionsEditText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height)); mMentionsEditText.setVerticalScrollBarEnabled(false); int cursorLine = getCurrentCursorLine(); Layout layout = mMentionsEditText.getLayout(); if (layout != null) { int lineTop = layout.getLineTop(cursorLine); mMentionsEditText.scrollTo(0, lineTop); } // Notify action listener that list was shown if (mActionListener != null) { mActionListener.onSuggestionsDisplayed(); } } else { disableSpellingSuggestions(false); mTextCounterView.setVisibility(View.VISIBLE); mSuggestionsList.setVisibility(View.GONE); mMentionsEditText.setPadding( mMentionsEditText.getPaddingLeft(), mMentionsEditText.getPaddingTop(), mMentionsEditText.getPaddingRight(), mPrevEditTextBottomPadding); if (mPrevEditTextParams == null) { mPrevEditTextParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); } mMentionsEditText.setLayoutParams(mPrevEditTextParams); mMentionsEditText.setVerticalScrollBarEnabled(true); // Notify action listener that list was hidden if (mActionListener != null) { mActionListener.onSuggestionsHidden(); } } requestLayout(); invalidate(); }
@Override public void draw(Canvas canvas) { Layout layout = getLayout(); RectF rectf = mrectf; int left = getCompoundPaddingLeft(); int top = getExtendedPaddingTop(); rectf.set( left + layout.getLineLeft(0) - mPaddingH, top + layout.getLineTop(0) - mPaddingV, Math.min( left + layout.getLineRight(0), getScrollX() + getWidth() - getCompoundPaddingRight()), top + layout.getLineBottom(0) + mPaddingV); canvas.drawRoundRect(rectf, mCornerRadius, mCornerRadius, mpaint); super.draw(canvas); }