Search in sources :

Example 81 with Spannable

use of android.text.Spannable in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class SuggestionStripLayoutHelper method getStyledSuggestedWord.

private CharSequence getStyledSuggestedWord(final SuggestedWords suggestedWords, final int indexInSuggestedWords) {
    if (indexInSuggestedWords >= suggestedWords.size()) {
        return null;
    }
    final String word = suggestedWords.getLabel(indexInSuggestedWords);
    // TODO: don't use the index to decide whether this is the auto-correction/typed word, as
    // this is brittle
    final boolean isAutoCorrection = suggestedWords.mWillAutoCorrect && indexInSuggestedWords == SuggestedWords.INDEX_OF_AUTO_CORRECTION;
    final boolean isTypedWordValid = suggestedWords.mTypedWordValid && indexInSuggestedWords == SuggestedWords.INDEX_OF_TYPED_WORD;
    if (!isAutoCorrection && !isTypedWordValid) {
        return word;
    }
    final Spannable spannedWord = new SpannableString(word);
    final int options = mSuggestionStripOptions;
    if ((isAutoCorrection && (options & AUTO_CORRECT_BOLD) != 0) || (isTypedWordValid && (options & VALID_TYPED_WORD_BOLD) != 0)) {
        addStyleSpan(spannedWord, BOLD_SPAN);
    }
    if (isAutoCorrection && (options & AUTO_CORRECT_UNDERLINE) != 0) {
        addStyleSpan(spannedWord, UNDERLINE_SPAN);
    }
    return spannedWord;
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) Spannable(android.text.Spannable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 82 with Spannable

use of android.text.Spannable in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class SuggestionSpanUtils method getTextWithAutoCorrectionIndicatorUnderline.

@UsedForTesting
public static CharSequence getTextWithAutoCorrectionIndicatorUnderline(final Context context, final String text, @Nonnull final Locale locale) {
    if (TextUtils.isEmpty(text) || OBJ_FLAG_AUTO_CORRECTION == null) {
        return text;
    }
    final Spannable spannable = new SpannableString(text);
    final SuggestionSpan suggestionSpan = new SuggestionSpan(context, locale, new String[] {}, /* suggestions */
    OBJ_FLAG_AUTO_CORRECTION, null);
    spannable.setSpan(suggestionSpan, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
    return spannable;
}
Also used : SpannableString(android.text.SpannableString) SuggestionSpan(android.text.style.SuggestionSpan) Spannable(android.text.Spannable) UsedForTesting(com.android.inputmethod.annotations.UsedForTesting)

Example 83 with Spannable

use of android.text.Spannable in project AndroidChromium by JackyAndroid.

the class SuggestionView method setAnswer.

/**
     * Sets both lines of the Omnibox suggestion based on an Answers in Suggest result.
     *
     * @param answer The answer to be displayed.
     */
private void setAnswer(SuggestionAnswer answer) {
    float density = getResources().getDisplayMetrics().density;
    SuggestionAnswer.ImageLine firstLine = answer.getFirstLine();
    mContentsView.mTextLine1.setTextSize(AnswerTextBuilder.getMaxTextHeightSp(firstLine));
    Spannable firstLineText = AnswerTextBuilder.buildSpannable(firstLine, mContentsView.mTextLine1.getPaint().getFontMetrics(), density);
    mContentsView.mTextLine1.setText(firstLineText);
    SuggestionAnswer.ImageLine secondLine = answer.getSecondLine();
    mContentsView.mTextLine2.setTextSize(AnswerTextBuilder.getMaxTextHeightSp(secondLine));
    Spannable secondLineText = AnswerTextBuilder.buildSpannable(secondLine, mContentsView.mTextLine2.getPaint().getFontMetrics(), density);
    mContentsView.mTextLine2.setText(secondLineText);
    mNumAnswerLines = parseNumAnswerLines(secondLine.getTextFields());
    if (mNumAnswerLines == -1)
        mNumAnswerLines = 1;
    if (mNumAnswerLines == 1) {
        mContentsView.mTextLine2.setEllipsize(null);
        mContentsView.mTextLine2.setSingleLine();
    } else {
        mContentsView.mTextLine2.setSingleLine(false);
        mContentsView.mTextLine2.setEllipsize(TextUtils.TruncateAt.END);
        mContentsView.mTextLine2.setMaxLines(mNumAnswerLines);
    }
    if (secondLine.hasImage()) {
        mContentsView.mAnswerImage.setVisibility(VISIBLE);
        float textSize = mContentsView.mTextLine2.getTextSize();
        int imageSize = (int) (textSize * ANSWER_IMAGE_SCALING_FACTOR);
        mContentsView.mAnswerImage.getLayoutParams().height = imageSize;
        mContentsView.mAnswerImage.getLayoutParams().width = imageSize;
        mContentsView.mAnswerImageMaxSize = imageSize;
        String url = "https:" + secondLine.getImage().replace("\\/", "/");
        AnswersImage.requestAnswersImage(mLocationBar.getCurrentTab().getProfile(), url, new AnswersImage.AnswersImageObserver() {

            @Override
            public void onAnswersImageChanged(Bitmap bitmap) {
                mContentsView.mAnswerImage.setImageBitmap(bitmap);
            }
        });
    }
}
Also used : Bitmap(android.graphics.Bitmap) SpannableString(android.text.SpannableString) Spannable(android.text.Spannable) SuppressLint(android.annotation.SuppressLint) TextPaint(android.text.TextPaint)

Example 84 with Spannable

use of android.text.Spannable in project AndroidChromium by JackyAndroid.

the class SuggestionView method setUrlText.

/**
     * Sets (and highlights) the URL text of the second line of the omnibox suggestion.
     *
     * @param result The suggestion containing the URL.
     * @return Whether the URL was highlighted based on the user query.
     */
private boolean setUrlText(OmniboxResultItem result) {
    OmniboxSuggestion suggestion = result.getSuggestion();
    Spannable str = SpannableString.valueOf(suggestion.getDisplayText());
    boolean hasMatch = applyHighlightToMatchRegions(str, suggestion.getDisplayTextClassifications());
    showDescriptionLine(str, true);
    return hasMatch;
}
Also used : Spannable(android.text.Spannable)

Example 85 with Spannable

use of android.text.Spannable in project zxing by zxing.

the class SupplementalInfoRetriever method append.

final void append(String itemID, String source, String[] newTexts, String linkURL) {
    StringBuilder newTextCombined = new StringBuilder();
    if (source != null) {
        newTextCombined.append(source).append(' ');
    }
    int linkStart = newTextCombined.length();
    boolean first = true;
    for (String newText : newTexts) {
        if (first) {
            newTextCombined.append(newText);
            first = false;
        } else {
            newTextCombined.append(" [");
            newTextCombined.append(newText);
            newTextCombined.append(']');
        }
    }
    int linkEnd = newTextCombined.length();
    String newText = newTextCombined.toString();
    Spannable content = new SpannableString(newText + "\n\n");
    if (linkURL != null) {
        // Lower-case these as it should always be OK to lower-case these schemes.
        if (linkURL.startsWith("HTTP://")) {
            linkURL = "http" + linkURL.substring(4);
        } else if (linkURL.startsWith("HTTPS://")) {
            linkURL = "https" + linkURL.substring(5);
        }
        content.setSpan(new URLSpan(linkURL), linkStart, linkEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    newContents.add(content);
    newHistories.add(new String[] { itemID, newText });
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan) Spannable(android.text.Spannable)

Aggregations

Spannable (android.text.Spannable)333 Paint (android.graphics.Paint)122 TextPaint (android.text.TextPaint)97 SpannableString (android.text.SpannableString)72 Editable (android.text.Editable)42 InputMethodManager (android.view.inputmethod.InputMethodManager)34 Spanned (android.text.Spanned)32 SuggestionSpan (android.text.style.SuggestionSpan)29 View (android.view.View)28 SpannableStringBuilder (android.text.SpannableStringBuilder)24 ForegroundColorSpan (android.text.style.ForegroundColorSpan)21 TextView (android.widget.TextView)17 ClickableSpan (android.text.style.ClickableSpan)14 StyleSpan (android.text.style.StyleSpan)14 Intent (android.content.Intent)13 KeyEvent (android.view.KeyEvent)13 URLSpan (android.text.style.URLSpan)12 Layout (android.text.Layout)11 Parcelable (android.os.Parcelable)8 SpannedString (android.text.SpannedString)8