Java Code Examples for android.text.Spanned

The following examples show how to use android.text.Spanned. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Netease   Source File: NewsDisplayActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void updateViewFromJSON(NewRoot newRoot) {
    NewsID hold = newRoot.getNewsID();
    //设置标题
    title.setText(hold.getTitle());

    //设置作者和时间
    int first = hold.getPtime().indexOf("-");
    int last = hold.getPtime().lastIndexOf(":");
    authorAndTime.setText(hold.getSource() + "    " + hold.getPtime().substring(first + 1, last));

    //设置正文
    String body = hold.getBody();
    for (Img img : hold.getImg()) {
        body = body.replace(img.getRef(), template.replace("LINK", img.getSrc()));
    }

    Log.i("RVA", "设置body: " + body);
    URLImageParser p = new URLImageParser(content, this);
    Spanned htmlSpan = Html.fromHtml(body, p, null);
    content.setText(htmlSpan);
    content.setTextSize(18);


}
 
Example 2
Source Project: NewFastFrame   Source File: ShareShareInfoHolder.java    License: Apache License 2.0 6 votes vote down vote up
private SpannableStringBuilder getSpannerContent(String name, String uid, CharSequence content) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    String str = "@" + name + ":";
    SpannableString spannableString = new SpannableString(str);
    spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#232121")), 0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannableString.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            if (uid != null) {
                UserDetailActivity.start((Activity) widget.getContext(), uid);
            } else {
                ToastUtils.showShortToast("用户数据加载失败");
            }
        }
    }, 0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.append(spannableString).append(content);
    return builder;
}
 
Example 3
Source Project: edslite   Source File: EditableSecureBuffer.java    License: GNU General Public License v2.0 6 votes vote down vote up
private boolean removeSpansForChange(int start, int end, boolean textIsRemoved, int i) {
    if(VERBOSE_LOG) Logger.debug(TAG + ": in removeSpansForChange");
    if ((i & 1) != 0) {
        // internal tree node
        if (resolveGap(mSpanMax[i]) >= start &&
                removeSpansForChange(start, end, textIsRemoved, leftChild(i))) {
            return true;
        }
    }
    if (i < mSpanCount) {
        if ((mSpanFlags[i] & Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) ==
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE &&
                mSpanStarts[i] >= start && mSpanStarts[i] < mGapStart + mGapLength &&
                mSpanEnds[i] >= start && mSpanEnds[i] < mGapStart + mGapLength &&
                // The following condition indicates that the span would become empty
                (textIsRemoved || mSpanStarts[i] > start || mSpanEnds[i] < mGapStart)) {
            mIndexOfSpan.remove(mSpans[i]);
            removeSpan(i);
            return true;
        }
        return resolveGap(mSpanStarts[i]) <= end && (i & 1) != 0 &&
                removeSpansForChange(start, end, textIsRemoved, rightChild(i));
    }
    return false;
}
 
Example 4
Source Project: styT   Source File: HelpsMainAdapter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 替换表情
 *
 * @param str
 * @param context
 * @return
 */
private SpannableString getSpannableString(String str, Context context) {
    SpannableString spannableString = new SpannableString(str);
    String s = "\\[(.+?)\\]";
    Pattern pattern = Pattern.compile(s, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(spannableString);
    while (matcher.find()) {
        String key = matcher.group();
        int id = Expression.getIdAsName(key);
        if (id != 0) {
            Drawable drawable = context.getResources().getDrawable(id);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            ImageSpan imageSpan = new ImageSpan(drawable);
            spannableString.setSpan(imageSpan, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return spannableString;
}
 
Example 5
Source Project: PowerFileExplorer   Source File: Selection.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the selection anchor to <code>start</code> and the selection edge
 * to <code>stop</code>.
 */
public static void setSelection(Spannable text, int start, int stop) {
    // int len = text.length();
    // start = pin(start, 0, len);  XXX remove unless we really need it
    // stop = pin(stop, 0, len);

    int ostart = getSelectionStart(text);
    int oend = getSelectionEnd(text);

    if (ostart != start || oend != stop) {
        text.setSpan(SELECTION_START, start, start,
                     Spanned.SPAN_POINT_POINT|Spanned.SPAN_INTERMEDIATE);
        text.setSpan(SELECTION_END, stop, stop,
                     Spanned.SPAN_POINT_POINT);
    }
}
 
Example 6
Source Project: Spyglass   Source File: WordTokenizer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the index of the end of the last span before the cursor or
 * the start of the current line if there are no spans before the cursor.
 *
 * @param text   the {@link Spanned} to examine
 * @param cursor position of the cursor in text
 *
 * @return the furthest in front of the cursor to search for the current keywords
 */
protected int getSearchStartIndex(final @NonNull Spanned text, int cursor) {
    if (cursor < 0 || cursor > text.length()) {
        cursor = 0;
    }

    // Get index of the end of the last span before the cursor (or 0 if does not exist)
    MentionSpan[] spans = text.getSpans(0, text.length(), MentionSpan.class);
    int closestToCursor = 0;
    for (MentionSpan span : spans) {
        int end = text.getSpanEnd(span);
        if (end > closestToCursor && end <= cursor) {
            closestToCursor = end;
        }
    }

    // Get the index of the start of the line
    String textString = text.toString().substring(0, cursor);
    int lineStartIndex = 0;
    if (textString.contains(mConfig.LINE_SEPARATOR)) {
        lineStartIndex = textString.lastIndexOf(mConfig.LINE_SEPARATOR) + 1;
    }

    // Return whichever is closer before to the cursor
    return Math.max(closestToCursor, lineStartIndex);
}
 
Example 7
Source Project: monolog-android   Source File: SignInActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_in);

    //handler init
    handler=new MyHandler(this);
    mBtnWeixin = (Button) findViewById(R.id.btn_weixin);
    mTvAgreement = (TextView) findViewById(R.id.tv_user_agreement);
    mBtnWeixin.setOnClickListener(this);

    //agreement
    SpannableString agreement = new SpannableString("使用即表示同意用户协议");
    agreement.setSpan(new NoLineClickSpan(), 7, agreement.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    mTvAgreement.setText(agreement);
    mTvAgreement.setMovementMethod(LinkMovementMethod.getInstance());

    //set up umeng
    mLoginController.getConfig().setSsoHandler(new SinaSsoHandler());
    String appId = AppContext.getInstance().getMetaData("WEIXIN_ID");
    String appSecret = AppContext.getInstance().getMetaData("WEIXIN_SECRET");

    // 添加微信平台
    UMWXHandler wxHandler = new UMWXHandler(SignInActivity.this, appId, appSecret);
    wxHandler.addToSocialSDK();
}
 
Example 8
public ConfirmIdentityDialog(Context context,
                             MasterSecret masterSecret,
                             MessageRecord messageRecord,
                             IdentityKeyMismatch mismatch)
{
  super(context);
  Recipient       recipient       = RecipientFactory.getRecipientForId(context, mismatch.getRecipientId(), false);
  String          name            = recipient.toShortString();
  String          introduction    = String.format(context.getString(R.string.ConfirmIdentityDialog_the_signature_on_this_key_exchange_is_different), name, name);
  SpannableString spannableString = new SpannableString(introduction + " " +
                                                        context.getString(R.string.ConfirmIdentityDialog_you_may_wish_to_verify_this_contact));

  spannableString.setSpan(new VerifySpan(context, mismatch),
                          introduction.length()+1, spannableString.length(),
                          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

  setTitle(name);
  setMessage(spannableString);

  setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.ConfirmIdentityDialog_accept), new AcceptListener(masterSecret, messageRecord, mismatch));
  setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(android.R.string.cancel),               new CancelListener());
}
 
Example 9
Source Project: Markwon   Source File: TestSpanMatcher.java    License: Apache License 2.0 6 votes vote down vote up
public static void textMatches(
        @NonNull Spanned spanned,
        int start,
        int end,
        @NonNull TestSpan.Text text) {

    final String expected = text.literal();
    final String actual = spanned.subSequence(start, end).toString();

    if (!expected.equals(actual)) {
        throw new ComparisonFailure(
                String.format(Locale.US, "Text mismatch at {start: %d, end: %d}", start, end),
                expected,
                actual
        );
    }
}
 
Example 10
Source Project: ExoVideoView   Source File: ExoVideoPlaybackControlView.java    License: Apache License 2.0 6 votes vote down vote up
private CharSequence generateFastForwardOrRewindTxt(long changingTime) {

        long duration = player == null ? 0 : player.getDuration();
        String result = Util.getStringForTime(formatBuilder, formatter, changingTime);
        result = result + "/";
        result = result + Util.getStringForTime(formatBuilder, formatter, duration);

        int index = result.indexOf("/");

        SpannableString spannableString = new SpannableString(result);


        TypedValue typedValue = new TypedValue();
        TypedArray a = getContext().obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorAccent});
        int color = a.getColor(0, 0);
        a.recycle();
        spannableString.setSpan(new ForegroundColorSpan(color), 0, index, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        spannableString.setSpan(new ForegroundColorSpan(Color.WHITE), index, result.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }
 
Example 11
Source Project: memoir   Source File: ConverterHtmlToSpanned.java    License: Apache License 2.0 6 votes vote down vote up
private void endHeader() {
    int len = mResult.length();
    Object obj = getLast(Header.class);

    int where = mResult.getSpanStart(obj);

    mResult.removeSpan(obj);

    // Back off not to change only the text, not the blank line.
    while (len > where && mResult.charAt(len - 1) == '\n') {
        len--;
    }

    if (where != len) {
        Header h = (Header) obj;
        mResult.setSpan(new RelativeSizeSpan(HEADER_SIZES[h.mLevel]), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mResult.setSpan(new BoldSpan(), where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 12
Source Project: JotaTextEditor   Source File: DrawableMarginSpan.java    License: Apache License 2.0 6 votes vote down vote up
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir,
                              int top, int baseline, int bottom,
                              CharSequence text, int start, int end,
                              boolean first, Layout layout) {
    int st = ((Spanned) text).getSpanStart(this);
    int ix = (int)x;
    int itop = (int)layout.getLineTop(layout.getLineForOffset(st));

    int dw = mDrawable.getIntrinsicWidth();
    int dh = mDrawable.getIntrinsicHeight();

    if (dir < 0)
        x -= dw;

    // XXX What to do about Paint?
    mDrawable.setBounds(ix, itop, ix+dw, itop+dh);
    mDrawable.draw(c);
}
 
Example 13
Source Project: memoir   Source File: RTLayout.java    License: Apache License 2.0 6 votes vote down vote up
public RTLayout(Spanned spanned) {
    if (spanned != null) {
        String s = spanned.toString();
        int len = s.length();

        // find the line breaks and the according lines / paragraphs
        mNrOfLines = 1;
        Matcher m = LINEBREAK_PATTERN.matcher(s.substring(0, len));
        int groupStart = 0;
        while (m.find()) {
            // the line feeds are part of the paragraph              isFirst          isLast
            Paragraph paragraph = new Paragraph(groupStart, m.end(), mNrOfLines == 1, false);
            mParagraphs.add(paragraph);
            groupStart = m.end();
            mNrOfLines++;
        }

        // even an empty line after the last cr/lf is considered a paragraph
        if (mParagraphs.size() < mNrOfLines) {
            mParagraphs.add(new Paragraph(groupStart, len, mNrOfLines == 1, true));
        }
    }
}
 
Example 14
Source Project: Tehreer-Android   Source File: LinkableLabel.java    License: Apache License 2.0 6 votes vote down vote up
private void refreshActiveLink() {
    Spanned spanned = getSpanned();
    ComposedFrame composedFrame = getComposedFrame();

    if (spanned != null && composedFrame != null && mActiveLinkSpan != null) {
        int spanStart = spanned.getSpanStart(mActiveLinkSpan);
        int spanEnd = spanned.getSpanEnd(mActiveLinkSpan);

        mActiveLinkPath = composedFrame.generateSelectionPath(spanStart, spanEnd);
        mActiveLinkPath.offset(composedFrame.getOriginX(), composedFrame.getOriginY());
    } else {
        mActiveLinkPath = null;
    }

    invalidate();
}
 
Example 15
public SpannableStringBuilder getDescription(Context context) {
    SpannableStringBuilder builder = new SpannableStringBuilder();

    // TODO XXX: i18n (w/ proper pluralisation)

    MiscUtils.appendAndSetSpan(builder, "Block(s): ",
            new StyleSpan(android.graphics.Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.append(MiscUtils.unparseIntRanges(blockNumbers));
    builder.append('\n');

    MiscUtils.appendAndSetSpan(builder, "Key: ",
            new StyleSpan(android.graphics.Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.append(key.toString());
    builder.append('\n');

    MiscUtils.appendAndSetSpan(builder, "Slot(s): ",
            new StyleSpan(android.graphics.Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.append(
            keySlotAttempts == KeySlotAttempts.BOTH ? context.getString(R.string.both) :
            keySlotAttempts.toString());

    return builder;
}
 
Example 16
Source Project: AgentWebX5   Source File: AgentWebX5Utils.java    License: Apache License 2.0 6 votes vote down vote up
public static void show(View parent,
                        CharSequence text,
                        int duration,
                        @ColorInt int textColor,
                        @ColorInt int bgColor,
                        CharSequence actionText,
                        @ColorInt int actionTextColor,
                        View.OnClickListener listener) {
    SpannableString spannableString = new SpannableString(text);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
    spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
    Snackbar snackbar = snackbarWeakReference.get();
    View view = snackbar.getView();
    view.setBackgroundColor(bgColor);
    if (actionText != null && actionText.length() > 0 && listener != null) {
        snackbar.setActionTextColor(actionTextColor);
        snackbar.setAction(actionText, listener);
    }
    snackbar.show();

}
 
Example 17
public void highlight(Editable editable) {
    disableTextChangeListener();
    StyleSpan[] spans = editable.getSpans(0, editable.length(), StyleSpan.class);
    for (StyleSpan span : spans) {
        editable.removeSpan(span);
    }

    String s = editable.toString();
    Matcher matcher = mFunctionPattern.matcher(s);
    while (matcher.find()) {
        StyleSpan styleSpan = new StyleSpan(Typeface.BOLD);
        editable.setSpan(styleSpan, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    enableTextChangeListener();
}
 
Example 18
Source Project: o2oa   Source File: RichEditText.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static Spannable matchMention(Spannable spannable) {
    String text = spannable.toString();

    Pattern pattern = Pattern.compile(MATCH_MENTION);
    Matcher matcher = pattern.matcher(text);

    while (matcher.find()) {
        String str = matcher.group();
        int matcherStart = matcher.start();
        int matcherEnd = matcher.end();
        spannable.setSpan(new TagSpan(str), matcherStart, matcherEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        log("matchMention:" + str + " " + matcherStart + " " + matcherEnd);
    }
    return spannable;
}
 
Example 19
Source Project: TelePlus-Android   Source File: Tx3gDecoder.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("ReferenceEquality")
private static void attachFontFamily(SpannableStringBuilder cueText, String fontFamily,
    String defaultFontFamily, int start, int end, int spanPriority) {
  if (fontFamily != defaultFontFamily) {
    cueText.setSpan(new TypefaceSpan(fontFamily), start, end,
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | spanPriority);
  }
}
 
Example 20
Source Project: ResearchStack   Source File: TextUtils.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
    for (int i = start; i < end; i++) {
        if (!Character.isLetterOrDigit(source.charAt(i))) {
            return "";
        }
    }
    return null;
}
 
Example 21
Source Project: Markwon   Source File: TextLayoutSpan.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see #applyTo(Spannable, Layout)
 */
@Nullable
public static Layout layoutOf(@NonNull CharSequence cs) {
    if (cs instanceof Spanned) {
        return layoutOf((Spanned) cs);
    }
    return null;
}
 
Example 22
Source Project: LinkTextView   Source File: LinkTextView.java    License: MIT License 5 votes vote down vote up
/**
 * Remove link by link ID
 *
 * @param linkID
 */
public void removeLink(int linkID) {
    if (!mLinkIDMap.containsKey(linkID)) {
        return;
    }

    try {
        mLinkIDMap.remove(linkID);
    } catch (Exception e) {
        //TODO: Log...
    }

    //Reset all links
    mSpannableString = new SpannableString(mOriginText);
    for (Integer id : mLinkIDMap.keySet()) {
        final LinkTextHolder linkTextHolder = mLinkIDMap.get(id);
        mSpannableString.setSpan(new TouchableSpan(linkTextHolder) {
            @Override
            public void onClick(View view) {
                if (linkTextHolder.mOnClickInLinkText != null) {
                    linkTextHolder.mOnClickInLinkText.onLinkTextClick(linkTextHolder.mText,
                            linkTextHolder.mLinkID, linkTextHolder.mAttachment);
                }
            }
        }, linkTextHolder.mBeginIndex, linkTextHolder.mEndIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }
    updateLinks();
}
 
Example 23
Source Project: Android-RTEditor   Source File: ConverterHtmlToSpanned.java    License: Apache License 2.0 5 votes vote down vote up
private Object getLast(Spanned text, Class<?> kind) {
    /*
     * This knows that the last returned object from getSpans()
     * will be the most recently added.
     */
    Object[] objs = text.getSpans(0, text.length(), kind);
    return objs.length == 0 ? null : objs[objs.length - 1];
}
 
Example 24
Source Project: AndFChat   Source File: AdEntry.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Spannable createText(Context context) {
    String text = getText(context);
    text = BBCodeReader.modifyUrls(text, "http://");
    //text = BBCodeReader.modifyUrls(text, "https://");

    final Spannable textSpan = SmileyReader.addSmileys(context, BBCodeReader.createSpannableWithBBCode(text, context));

    if (adClickListener != null && !showText) {
        // Create display text
        Spannable displayedSpan = new SpannableString(displayText);

        ClickableSpan clickable = new ClickableSpan() {

            @Override
            public void onClick(View widget) {
            adClickListener.openAd(textSpan);
            }
        };

        displayedSpan.setSpan(clickable, 0, displayedSpan.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

        return displayedSpan;
    }
    else {
        return textSpan;
    }
}
 
Example 25
Source Project: Pugnotification   Source File: Load.java    License: Apache License 2.0 5 votes vote down vote up
public Load message(@NonNull Spanned messageSpanned) {
    if (messageSpanned.length() == 0) {
        throw new IllegalArgumentException("Message Must Not Be Empty!");
    }

    this.messageSpanned = messageSpanned;
    this.builder.setContentText(messageSpanned);
    return this;
}
 
Example 26
Source Project: EdXposedManager   Source File: RepoParser.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static Spanned parseSimpleHtml(final Context c, String source, final TextView textView) {
    source = source.replaceAll("<li>", "\t\u0095 ");
    source = source.replaceAll("</li>", "<br>");
    Spanned html = Html.fromHtml(source, Html.FROM_HTML_MODE_COMPACT, source1 -> {
        LevelListDrawable d = new LevelListDrawable();
        Drawable empty = c.getResources().getDrawable(R.drawable.ic_no_image, null);
        d.addLevel(0, 0, empty);
        assert empty != null;
        d.setBounds(0, 0, empty.getIntrinsicWidth(), empty.getIntrinsicHeight());
        new ImageGetterAsyncTask(c, source1, d).execute(textView);

        return d;
    }, null);

    // trim trailing newlines
    int len = html.length();
    int end = len;
    for (int i = len - 1; i >= 0; i--) {
        if (html.charAt(i) != '\n')
            break;
        end = i;
    }

    if (end == len)
        return html;
    else
        return new SpannableStringBuilder(html, 0, end);
}
 
Example 27
Source Project: sms-ticket   Source File: EulaDialogFragment.java    License: Apache License 2.0 5 votes vote down vote up
private View getCustomView() {
    View customView = LayoutInflater.from(getActivity()).inflate(R.layout.view_eula_dialog, null);
    final TextView txtEulaContent = (TextView)customView.findViewById(R.id.txt_eula_content);
    final ProgressBar progressWheel = (ProgressBar)customView.findViewById(R.id.progress_bar);

    new BaseAsyncTask() {
        String eula;
        Spanned spannedEula;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progressWheel.setVisibility(View.VISIBLE);
        }

        @Override
        public void doInBackground() {
            eula = getStringFromAssets(App.getInstance(), "eula.html");
            spannedEula = Html.fromHtml(eula);
        }

        @Override
        public void onPostExecute() {
            super.onPostExecute();
            progressWheel.setVisibility(View.GONE);
            txtEulaContent.setText(spannedEula);

        }
    }.start();

    return customView;
}
 
Example 28
Source Project: socialview   Source File: SocialViewHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static void spanAll(Spannable spannable, Pattern pattern, Supplier<CharacterStyle> styleSupplier) {
    final Matcher matcher = pattern.matcher(spannable);
    while (matcher.find()) {
        final int start = matcher.start();
        final int end = matcher.end();
        final Object span = styleSupplier.get();
        spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (span instanceof SocialClickableSpan) {
            ((SocialClickableSpan) span).text = spannable.subSequence(start, end);
        }
    }
}
 
Example 29
Source Project: Ruisi   Source File: EmotionInputHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void insertImage(String s, Drawable drawable, int maxWidth) {
    if (drawable != null) {
        s = "[attachimg]" + s + "[/attachimg]";
        AttachImage imageSpan = new AttachImage(s, drawable, maxWidth);
        int start = mEditor.getSelectionStart();
        int end = mEditor.getSelectionEnd();
        Editable editableText = mEditor.getEditableText();
        // Insert the emoticon.
        editableText.replace(start, end, s);
        editableText.setSpan(imageSpan, start, start + s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
Example 30
Source Project: android-discourse   Source File: HtmlTagHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static void end(Editable text, Class<?> kind, Object... replaces) {
    int len = text.length();
    Object obj = getLast(text, kind);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);
    if (where != len) {
        for (Object replace : replaces) {
            text.setSpan(replace, where, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return;
}