List of usage examples for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE
int SPAN_EXCLUSIVE_EXCLUSIVE
To view the source code for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE.
Click Source Link
From source file:com.ruesga.timelinechart.TimelineChartView.java
private DynamicSpannableString createSpannableTick(int tickFormat, CharSequence text) { DynamicSpannableString spannable = new DynamicSpannableString(text); mTickTextSpannables[tickFormat].put(text.length(), spannable); if (tickFormat == (mTickFormats.length - 1)) { spannable.setSpan(new AbsoluteSizeSpan((int) (mSize20 * mTextSizeFactor)), 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (tickFormat == 1) { spannable.setSpan(new AbsoluteSizeSpan((int) (mSize12 * mTextSizeFactor)), 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }//from ww w . j av a 2s .com return spannable; }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Handles the manual selection of suggestions from the suggestion bar * @param index the position of the suggestion in the suggestion list *///from w w w. j a va 2 s . com public void pickSuggestionManually(int index) { if (mCompletionOn && mCompletions != null && index >= 0 && index < mCompletions.length) { CompletionInfo ci = mCompletions[index]; ic.commitCompletion(ci); if (mCandidateView != null) { mCandidateView.clear(); } updateShiftKeyState(getCurrentInputEditorInfo()); } else if (mComposing.length() >= 0) { String picked; if (!replacemode) picked = suggestions.get(index) + " "; else picked = suggestions.get(index); //Log.i("Suggestion picked 2", picked); //ic.commitText(picked, picked.length()); getCurrentInputEditorInfo(); //colour the text according to user preferences SpannableString text = new SpannableString(picked); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (sharedPrefs.getBoolean("suggestion_highlight", false)) text.setSpan(new BackgroundColorSpan(suggestion), 0, picked.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); currentSession.nSuggestionsPicked++; if (replacemode) { replacemode = false; //remove from list of autocorrected words. //Log.i("PickSuggestion", "Removed "+autocorrected_words.remove(text.toString())); //find the current word extr = ic.getExtractedText(new ExtractedTextRequest(), 0); WordDetails w = findWord(extr.selectionStart, extr.text); //Log.i("FindWord", w.word+", "+w.wordStart+" - "+w.wordEnd); ic.setComposingRegion(w.wordStart, w.wordEnd); text.setSpan(null, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); /* //clear any spans BackgroundColorSpan[] spans=(new SpannableString(extr.text.toString())).getSpans(w.wordStart, w.wordEnd, BackgroundColorSpan.class); for(int i=0; i<spans.length; i++){ text.removeSpan(spans[i]); }*/ //commit the update ic.commitText(text, 1); } else ic.commitText(text, picked.length()); coreEngine.resetCoreString(); coreEngine.insertText(picked); mComposing.setLength(0); updateCandidates(); } }
From source file:org.kontalk.ui.ComposeMessageFragment.java
private void showIdentityDialog(boolean informationOnly, int titleId) { String fingerprint;/*ww w.j ava 2s.c o m*/ String uid; PGPPublicKeyRing publicKey = UsersProvider.getPublicKey(getActivity(), mUserJID, false); if (publicKey != null) { PGPPublicKey pk = PGP.getMasterKey(publicKey); fingerprint = PGP.formatFingerprint(PGP.getFingerprint(pk)); uid = PGP.getUserId(pk, null); // TODO server!!! } else { // FIXME using another string fingerprint = uid = getString(R.string.peer_unknown); } SpannableStringBuilder text = new SpannableStringBuilder(); text.append(getString(R.string.text_invitation1)).append('\n'); Contact c = mConversation.getContact(); if (c != null) { text.append(c.getName()).append(" <").append(c.getNumber()).append('>'); } else { int start = text.length() - 1; text.append(uid); text.setSpan(MessageUtils.STYLE_BOLD, start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } text.append('\n').append(getString(R.string.text_invitation2)).append('\n'); int start = text.length() - 1; text.append(fingerprint); text.setSpan(MessageUtils.STYLE_BOLD, start, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(getActivity()).setMessage(text); if (informationOnly) { builder.setTitle(titleId); } else { DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // hide warning bar hideWarning(); switch (which) { case DialogInterface.BUTTON_POSITIVE: // trust new key trustKeyChange(); break; case DialogInterface.BUTTON_NEGATIVE: // block user immediately setPrivacy(PRIVACY_BLOCK); break; } } }; builder.setTitle(titleId).setPositiveButton(R.string.button_accept, listener) .setNegativeButton(R.string.button_block, listener); } builder.show(); }
From source file:com.android.ex.chips.RecipientEditTextView.java
void createMoreChipPlainText() { // Take the first <= CHIP_LIMIT addresses and get to the end of the second one. final Editable text = getText(); int start = 0; int end = start; for (int i = 0; i < CHIP_LIMIT; i++) { end = movePastTerminators(mTokenizer.findTokenEnd(text, start)); start = end; // move to the next token and get its end. }//from w w w.j a v a 2 s .c o m // Now, count total addresses. start = 0; final int tokenCount = countTokens(text); final MoreImageSpan moreSpan = createMoreSpan(tokenCount - CHIP_LIMIT); final SpannableString chipText = new SpannableString(text.subSequence(end, text.length())); chipText.setSpan(moreSpan, 0, chipText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); text.replace(end, text.length(), chipText); mMoreChip = moreSpan; }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** * Create the more chip. The more chip is text that replaces any chips that do not fit in the pre-defined available * space when the RecipientEditTextView loses focus. *//* w ww.j ava2s . com*/ // Visible for testing. /* package */void createMoreChip() { if (mNoChips) { createMoreChipPlainText(); return; } if (!mShouldShrink) return; final ImageSpan[] tempMore = getSpannable().getSpans(0, getText().length(), MoreImageSpan.class); if (tempMore.length > 0) getSpannable().removeSpan(tempMore[0]); final DrawableRecipientChip[] recipients = getSortedRecipients(); if (recipients == null || recipients.length <= CHIP_LIMIT) { mMoreChip = null; return; } final Spannable spannable = getSpannable(); final int numRecipients = recipients.length; final int overage = numRecipients - CHIP_LIMIT; final MoreImageSpan moreSpan = createMoreSpan(overage); mRemovedSpans = new ArrayList<DrawableRecipientChip>(); int totalReplaceStart = 0; int totalReplaceEnd = 0; final Editable text = getText(); for (int i = numRecipients - overage; i < recipients.length; i++) { mRemovedSpans.add(recipients[i]); if (i == numRecipients - overage) totalReplaceStart = spannable.getSpanStart(recipients[i]); if (i == recipients.length - 1) totalReplaceEnd = spannable.getSpanEnd(recipients[i]); if (mTemporaryRecipients == null || !mTemporaryRecipients.contains(recipients[i])) { final int spanStart = spannable.getSpanStart(recipients[i]); final int spanEnd = spannable.getSpanEnd(recipients[i]); recipients[i].setOriginalText(text.toString().substring(spanStart, spanEnd)); } spannable.removeSpan(recipients[i]); } if (totalReplaceEnd < text.length()) totalReplaceEnd = text.length(); final int end = Math.max(totalReplaceStart, totalReplaceEnd); final int start = Math.min(totalReplaceStart, totalReplaceEnd); final SpannableString chipText = new SpannableString(text.subSequence(start, end)); chipText.setSpan(moreSpan, 0, chipText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); text.replace(start, end, chipText); mMoreChip = moreSpan; // If adding the +more chip goes over the limit, resize accordingly. if (!isPhoneQuery() && getLineCount() > mMaxLines) setMaxLines(getLineCount()); }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** * Replace the more chip, if it exists, with all of the recipient chips it had replaced when the * RecipientEditTextView gains focus./*from www . ja v a 2 s .c o m*/ */ // Visible for testing. /* package */void removeMoreChip() { if (mMoreChip != null) { final Spannable span = getSpannable(); span.removeSpan(mMoreChip); mMoreChip = null; // Re-add the spans that were removed. if (mRemovedSpans != null && mRemovedSpans.size() > 0) { // Recreate each removed span. final DrawableRecipientChip[] recipients = getSortedRecipients(); // Start the search for tokens after the last currently visible // chip. if (recipients == null || recipients.length == 0) return; int end = span.getSpanEnd(recipients[recipients.length - 1]); final Editable editable = getText(); for (final DrawableRecipientChip chip : mRemovedSpans) { int chipStart; int chipEnd; String token; // Need to find the location of the chip, again. token = (String) chip.getOriginalText(); // As we find the matching recipient for the remove spans, // reduce the size of the string we need to search. // That way, if there are duplicates, we always find the correct // recipient. chipStart = editable.toString().indexOf(token, end); end = chipEnd = Math.min(editable.length(), chipStart + token.length()); // Only set the span if we found a matching token. if (chipStart != -1) editable.setSpan(chip, chipStart, chipEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } mRemovedSpans.clear(); } } }
From source file:cgeo.geocaching.CacheDetailActivity.java
private void addWarning(final UnknownTagsHandler unknownTagsHandler, final Editable description) { if (unknownTagsHandler.isProblematicDetected()) { final int startPos = description.length(); final IConnector connector = ConnectorFactory.getConnector(cache); if (StringUtils.isNotEmpty(cache.getUrl())) { final Spanned tableNote = Html.fromHtml(res.getString(R.string.cache_description_table_note, "<a href=\"" + cache.getUrl() + "\">" + connector.getName() + "</a>")); description.append("\n\n").append(tableNote); description.setSpan(new StyleSpan(Typeface.ITALIC), startPos, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }//from ww w . j a va 2 s .c o m } }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * handle the receipt of suggestions from the spell checker * colour the text in the editor as required * pass information to the keyboard view so it can draw the colour bar * initiate audio and haptic feedback as required *//*from ww w . java2 s . c o m*/ @Override public void onGetSuggestions(SuggestionsInfo[] results) { // TODO Auto-generated method stub int colortype = -1; final StringBuilder sb = new StringBuilder(); if (updateSuggestionList) { updateSuggestionList = false; ArrayList<String> s = new ArrayList<String>(); for (int i = 0; i < results.length; ++i) { final int length = results[i].getSuggestionsCount(); for (int j = 0; j < length; ++j) { s.add(results[i].getSuggestionAt(j)); } } updateSuggestionListWithSpellChecker(s); } else { for (int i = 0; i < results.length; ++i) { // Returned suggestions are contained in SuggestionsInfo final int len = results[i].getSuggestionsCount(); sb.append("Suggestion Attribs: " + results[i].getSuggestionsAttributes()); if ((results[i].getSuggestionsAttributes() & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) == SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) { sb.append("The word was found in the dictionary\n"); mInputView.wordcompletedtype = 3; } else { if ((results[i].getSuggestionsAttributes() & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) == SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) { if ((results[i].getSuggestionsAttributes() & SuggestionsInfo.RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS) == SuggestionsInfo.RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS) { colortype = 1; //yellow mInputView.wordcompletedtype = 1; sb.append("There are strong candidates for this word\n"); currentSession.nLowErrors++; } else { colortype = 2; //red mInputView.wordcompletedtype = 2; sb.append("The word looks like a typo\n"); currentSession.nHighErrors++; } } } sb.append("\n--These are the suggestions--\n"); for (int j = 0; j < len; ++j) { sb.append("," + results[i].getSuggestionAt(j)); } sb.append(" (" + len + ")"); } //Log.i("Spelling suggestions", sb.toString()); //this comes after a word separator, hence just add 1 to the cursor SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SpannableString text = new SpannableString(mComposingTemp); if (sharedPrefs.getBoolean("highlightwords", true)) { switch (colortype) { case 1: text.setSpan(new BackgroundColorSpan(small_err), 0, mComposingTemp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; case 2: text.setSpan(new BackgroundColorSpan(big_err), 0, mComposingTemp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; default: break; } } if (sharedPrefs.getBoolean("autocorrect", true) && mInputView.wordcompletedtype == 1) //handle autocorrection { SpannableString autoc = autocorrect(results); autocorrected_words.put(autoc.toString(), text.toString()); //autocorrected word, original input //Log.i("Autocorrecting","Key= "+autoc.toString()+", Value= "+text.toString()); text = autoc; if (sharedPrefs.getBoolean("highlightwords", true)) text.setSpan(new BackgroundColorSpan(autocorrect), 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mInputView.wordcompletedtype = 4; } else //autocorrection is turned off { if (!sharedPrefs.getBoolean("autocorrect", true) && colortype >= 1) //a mistake word { //Log.i("OnGetSentenceSuggestions","Key= "+text.toString()+", Value= "+text.toString()); //no autocorrects, just put the word in and itself as the replacement autocorrected_words.put(text.toString(), text.toString()); } } if (sharedPrefs.getBoolean("vibrator", false)) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); final int on_time = Integer.parseInt(sharedPrefs.getString("shortvibe", "35")); switch (mInputView.wordcompletedtype) { case 1: //small err // Vibrate for 300 milliseconds v.vibrate(on_time); break; case 2: //big err //v.vibrate(Integer.parseInt(sharedPrefs.getString("longvibe", "300"))); v.vibrate(new long[] { 0, on_time, 200, on_time }, -1); break; case 4: //autocorr v.vibrate(on_time); break; default: break; } } if (sharedPrefs.getBoolean("audio", false)) { final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); switch (mInputView.wordcompletedtype) { case 1: //small err tg.startTone(ToneGenerator.TONE_PROP_BEEP); break; case 2: //big err tg.startTone(ToneGenerator.TONE_PROP_BEEP2); break; case 4: //autocorr tg.startTone(ToneGenerator.TONE_PROP_BEEP); break; default: break; } } mInputView.invalidateAllKeys(); ic.commitText(text, 1); sendKey(wordSeparatorKeyCode); coreEngine.resetCoreString(); updateCandidates(); } }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** * Show specified chip as selected. If the RecipientChip is just an email address, selecting the chip will take the * contents of the chip and place it at the end of the RecipientEditTextView for inline editing. If the * RecipientChip is a complete contact, then selecting the chip will change the background color of the chip, show * the delete icon, and a popup window with the address in use highlighted and any other alternate addresses for the * contact.// w ww. ja v a 2 s. com * * @param currentChip * Chip to select. * @return A RecipientChip in the selected state or null if the chip just contained an email address. */ private DrawableRecipientChip selectChip(final DrawableRecipientChip currentChip) { if (shouldShowEditableText(currentChip)) { final CharSequence text = currentChip.getValue(); final Editable editable = getText(); final Spannable spannable = getSpannable(); final int spanStart = spannable.getSpanStart(currentChip); final int spanEnd = spannable.getSpanEnd(currentChip); spannable.removeSpan(currentChip); editable.delete(spanStart, spanEnd); setCursorVisible(true); setSelection(editable.length()); editable.append(text); return constructChipSpan(RecipientEntry.constructFakeEntry((String) text, isValid(text.toString())), true, false); } else if (currentChip.getContactId() == RecipientEntry.GENERATED_CONTACT || currentChip.isGalContact()) { final int start = getChipStart(currentChip); final int end = getChipEnd(currentChip); getSpannable().removeSpan(currentChip); DrawableRecipientChip newChip; try { if (mNoChips) return null; newChip = constructChipSpan(currentChip.getEntry(), true, false); } catch (final NullPointerException e) { Log.e(TAG, e.getMessage(), e); return null; } final Editable editable = getText(); QwertyKeyListener.markAsReplaced(editable, start, end, ""); if (start == -1 || end == -1) Log.d(TAG, "The chip being selected no longer exists but should."); else editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); newChip.setSelected(true); if (shouldShowEditableText(newChip)) scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip))); //showAddress(newChip,mAddressPopup,getWidth()); setCursorVisible(false); return newChip; } else { final int start = getChipStart(currentChip); final int end = getChipEnd(currentChip); getSpannable().removeSpan(currentChip); DrawableRecipientChip newChip; try { newChip = constructChipSpan(currentChip.getEntry(), true, false); } catch (final NullPointerException e) { Log.e(TAG, e.getMessage(), e); return null; } final Editable editable = getText(); QwertyKeyListener.markAsReplaced(editable, start, end, ""); if (start == -1 || end == -1) Log.d(TAG, "The chip being selected no longer exists but should."); else editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); newChip.setSelected(true); if (shouldShowEditableText(newChip)) scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip))); //showAlternates(newChip,mAlternatesPopup,getWidth()); setCursorVisible(false); return newChip; } }
From source file:com.tct.mail.browse.MessageHeaderView.java
private void stripUnderlines(TextView textView, Account account) { final Spannable spannable = (Spannable) textView.getText(); final URLSpan[] urls = textView.getUrls(); for (URLSpan span : urls) { final int start = spannable.getSpanStart(span); final int end = spannable.getSpanEnd(span); spannable.removeSpan(span);//w ww.j ava 2s . c o m //TS: rong-tang 2016-04-19 EMAIL BUGFIX-1951808 MOD_S span = new EmailAddressSpan(getContext(), account, span.getURL().substring(7), mContactInfoSource); ((EmailAddressSpan) span).setFragmentManager(mFragmentManager); //TS: rong-tang 2016-04-19 EMAIL BUGFIX-1951808 MOD_E spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } }