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;
}
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;
}
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);
}
});
}
}
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;
}
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 });
}
Aggregations