List of usage examples for android.text Spannable removeSpan
public void removeSpan(Object what);
From source file:com.discord.chipsview.ChipsView.java
private void addLeadingMarginSpan() { Spannable spannable = mEditText.getText(); if (mCurrentEditTextSpan != null) { spannable.removeSpan(mCurrentEditTextSpan); }/* ww w. j a v a2s . c o m*/ spannable.setSpan(mCurrentEditTextSpan, 0, 0, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); mEditText.setText(spannable); }
From source file:com.discord.chipsview.ChipsView.java
private void addLeadingMarginSpan(int margin) { Spannable spannable = mEditText.getText(); if (mCurrentEditTextSpan != null) { spannable.removeSpan(mCurrentEditTextSpan); }//from ww w .ja v a 2 s . c o m mCurrentEditTextSpan = new android.text.style.LeadingMarginSpan.LeadingMarginSpan2.Standard(margin, 0); spannable.setSpan(mCurrentEditTextSpan, 0, 0, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); mEditText.setText(spannable); }
From source file:com.android.mail.browse.MessageHeaderView.java
private static 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); span = new EmailAddressSpan(account, span.getURL().substring(7)); spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }/*ww w . ja v a 2 s . c o m*/ }
From source file:com.silentcircle.accounts.AccountStep1.java
private void stripUnderlines(TextView textView) { Spannable s = (Spannable) textView.getText(); URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class); for (URLSpan span : spans) { int start = s.getSpanStart(span); int end = s.getSpanEnd(span); s.removeSpan(span); span = new URLSpanNoUnderline(span.getURL()); s.setSpan(span, start, end, 0);// w w w.ja v a 2s. c o m } textView.setText(s); }
From source file:com.microsoft.azure.engagement.ProductDiscountActivity.java
/** * Method that adds or removes a strike from a TextView object * * @param textView The textView to manage *///from w w w. j a v a 2 s. c om private final void addOrRemoveStrikeTextView(TextView textView, boolean toAdd) { textView.setText(textView.getText().toString(), TextView.BufferType.SPANNABLE); final Spannable spannable = (Spannable) textView.getText(); if (toAdd == true) { // Add a StrikethroughSpan style final StrikethroughSpan strikethroughSpan = new StrikethroughSpan(); spannable.setSpan(strikethroughSpan, 0, textView.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { // Remove only StrikethroughSpan style final Object spans[] = spannable.getSpans(0, textView.length(), Object.class); for (final Object span : spans) { if (span instanceof StrikethroughSpan == true) { spannable.removeSpan(span); return; } } } }
From source file:com.taobao.weex.dom.WXTextDomObject.java
/** * Adjust span range after truncate due to the wrong span range during span copy and slicing. * @param beforeTruncate The span before truncate * @param afterTruncate The span after truncate *//*from w w w. j ava 2s .c o m*/ private void adjustSpansRange(@NonNull Spanned beforeTruncate, @NonNull Spannable afterTruncate) { Object[] spans = beforeTruncate.getSpans(0, beforeTruncate.length(), Object.class); for (Object span : spans) { int start = beforeTruncate.getSpanStart(span); int end = beforeTruncate.getSpanEnd(span); if (start == 0 && end == beforeTruncate.length()) { afterTruncate.removeSpan(span); afterTruncate.setSpan(span, 0, afterTruncate.length(), beforeTruncate.getSpanFlags(span)); } } }
From source file:com.juick.android.TagsFragment.java
private void onTagClick(String tagg, int uid) { if (!multi) { parentActivity.onTagClick(tagg, uid); } else {// www . j ava 2 s . c om TextView tv = (TextView) myView.findViewById(R.id.tags); Spannable text = (Spannable) tv.getText(); TagOffsets tagOffsets1 = tagOffsets.get(tagg); if (!selectedTags.remove(tagg)) { if (selectedTags.size() == 5) { Toast.makeText(getActivity(), getString(R.string.TooManyTags), Toast.LENGTH_LONG).show(); return; } else { selectedTags.add(tagg); tagOffsets1.existingSpan = new StyleSpan(Typeface.BOLD); text.setSpan(tagOffsets1.existingSpan, tagOffsets1.offset, tagOffsets1.end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { text.removeSpan(tagOffsets1.existingSpan); tagOffsets1.existingSpan = null; } final TextView selected = (TextView) myView.findViewById(R.id.selected); StringBuilder sb = new StringBuilder(); for (String selectedTag : selectedTags) { sb.append("*"); sb.append(selectedTag); sb.append(" "); } selected.setText(sb.toString().trim()); } }
From source file:com.nearnotes.NoteEdit.java
public void toggleChecklist() { if (mChecklist) { Toast.makeText(getActivity(), "Checklist off", Toast.LENGTH_SHORT).show(); mChecklist = false;/*from ww w .ja va 2 s. com*/ mTblAddLayout.removeAllViews(); mBodyText.removeTextChangedListener(bodyTextWatcher); Spannable spannable = (Spannable) mBodyText.getText(); Object spansToRemove[] = spannable.getSpans(0, spannable.length(), Object.class); for (Object span : spansToRemove) { if (span instanceof CharacterStyle) spannable.removeSpan(span); } } else { Toast.makeText(getActivity(), "Checklist on", Toast.LENGTH_SHORT).show(); mChecklist = true; mBodyText.addTextChangedListener(bodyTextWatcher); String tempBoxes = mBodyText.getText().toString(); if (mBodyText.getLayout() != null) { mRealRow = populateBoxes(tempBoxes); int row = 0; for (NoteRow line : mRealRow) { switch (line.getType()) { case 0: TableRow inflate = (TableRow) View.inflate(getActivity(), R.layout.table_row_invisible, null); mTblAddLayout.addView(inflate); break; case 1: TableRow checkRow = (TableRow) View.inflate(getActivity(), R.layout.table_row, null); CheckBox temp = (CheckBox) checkRow.getChildAt(0); temp.setTag(Integer.valueOf(row)); mTblAddLayout.addView(checkRow); temp.setOnClickListener(checkBoxListener); break; case 2: TableRow checkRow1 = (TableRow) View.inflate(getActivity(), R.layout.table_row, null); CheckBox temp1 = (CheckBox) checkRow1.getChildAt(0); temp1.setTag(Integer.valueOf(row)); temp1.setChecked(true); mTblAddLayout.addView(checkRow1); temp1.setOnClickListener(checkBoxListener); break; } for (int k = 1; line.getSize() > k; k++) { TableRow inflate = (TableRow) View.inflate(getActivity(), R.layout.table_row_invisible, null); mTblAddLayout.addView(inflate); } row++; } } } }
From source file:im.zico.fancy.common.widget.HackyMovementMethod.java
@Override public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { if (mGray == null) { mGray = new BackgroundColorSpan( ContextCompat.getColor(widget.getContext(), R.color.alpha_spannable_pressed)); }/*from ww w . java2 s . c o m*/ mIsLinkHit = false; int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { int x = (int) event.getX(); int y = (int) event.getY(); x -= widget.getTotalPaddingLeft(); y -= widget.getTotalPaddingTop(); x += widget.getScrollX(); y += widget.getScrollY(); int line = widget.getLayout().getLineForVertical(y); int offset = widget.getLayout().getOffsetForHorizontal(line, x); ClickableSpan[] spans = buffer.getSpans(offset, offset, ClickableSpan.class); if (spans.length != 0) { int start = buffer.getSpanStart(spans[0]); int end = buffer.getSpanEnd(spans[0]); mIsLinkHit = true; if (action == MotionEvent.ACTION_DOWN) { buffer.setSpan(mGray, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else if (action == MotionEvent.ACTION_UP) { spans[0].onClick(widget); buffer.removeSpan(mGray); } return true; } } else { buffer.removeSpan(mGray); } return Touch.onTouchEvent(widget, buffer, event); }
From source file:com.nearnotes.NoteEdit.java
/** * Populates the checkboxes on the side by analyzing the current text from * the body of the note./* w w w . j a va 2 s.com*/ * * @param currentString * the current body of the note. * */ public ArrayList<NoteRow> populateBoxes(String currentString) { // Load ArrayList<String> mLines with the current bodytext seperated into seperate lines. mLines = Arrays.asList(currentString.split(System.getProperty("line.separator"))); // row counter to determine what the current line number is for the for loop int row = 0; // realRow counter to determine what line of text in the actual display we are on // used to get the number of characters on each line int realRow = 0; int activeRow = 0; int finishedCount = 0; ArrayList<NoteRow> tempRealRow = new ArrayList<NoteRow>(); for (String line : mLines) { NoteRow temp = new NoteRow(0, 1, row); // Create a note row object with rowType of 0 (invisible), lineSize of 1 and the current row number if (!line.isEmpty()) { activeRow++; temp.setType(1); // Set the NoteRow object to 1 (visible) // Determine how many lines the note takes up int internalCounter = 0; try { float lineLength = (float) line.length(); for (int k = 0; (lineLength / (getFloatLineEnd(realRow + k) - getFloatLineEnd(realRow - 1))) > 1; k++) { internalCounter++; } } catch (NullPointerException e) { e.printStackTrace(); } // Detemine if the note is supposed to be checked and set the NoteRow object to 2 (Checked) if (line.startsWith("[X]")) { finishedCount++; int spanstart = 0; StrikethroughSpan STRIKE_THROUGH_SPAN = new StrikethroughSpan(); Spannable spannable = (Spannable) mBodyText.getText(); // TableRow checkRow1 = (TableRow) View.inflate(getActivity(), R.layout.table_row, null); for (int j = 0; j < row; j++) { spanstart += mLines.get(j).length() + 1; } Object spansToRemove[] = spannable.getSpans(spanstart, spanstart + mLines.get(row).length(), Object.class); for (Object span : spansToRemove) { if (span instanceof CharacterStyle) spannable.removeSpan(span); } spannable.setSpan(STRIKE_THROUGH_SPAN, spanstart, spanstart + mLines.get(row).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); temp.setType(2); } temp.setSize(1 + internalCounter); // Set the amount of rows the note takes up realRow = realRow + internalCounter; // Determine the real line on the display text we are on } tempRealRow.add(temp); // NoteRow object has been finalized - add to the ListArray<NoteRow> realRow++; // Increase the noteRow and the displayRow for the next line row++; } if (finishedCount == activeRow && finishedCount != 0) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); boolean useListPref = sharedPref.getBoolean("pref_key_use_checklist_default", false); String stringlistPref = sharedPref.getString("pref_key_checklist_listPref", "2"); int listPref = Integer.parseInt(stringlistPref); ChecklistDialog newFragment = new ChecklistDialog(); if (mRowId == null) { saveState(); } Bundle args = new Bundle(); args.putLong("_id", mRowId); args.putBoolean("useDefault", useListPref); args.putInt("listPref", listPref); newFragment.setArguments(args); if (listPref == 2 && useListPref) { return tempRealRow; } if (getFragmentManager().findFragmentByTag("MyDialog") == null) { newFragment.show(getFragmentManager(), "MyDialog"); } } return tempRealRow; }