Example usage for android.text Spanned SPAN_INCLUSIVE_EXCLUSIVE

List of usage examples for android.text Spanned SPAN_INCLUSIVE_EXCLUSIVE

Introduction

In this page you can find the example usage for android.text Spanned SPAN_INCLUSIVE_EXCLUSIVE.

Prototype

int SPAN_INCLUSIVE_EXCLUSIVE

To view the source code for android.text Spanned SPAN_INCLUSIVE_EXCLUSIVE.

Click Source Link

Document

Non-0-length spans of type SPAN_INCLUSIVE_EXCLUSIVE expand to include text inserted at their starting point but not at their ending point.

Usage

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 a2 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.discord.chipsview.ChipsView.java

private void addLeadingMarginSpan() {
    Spannable spannable = mEditText.getText();
    if (mCurrentEditTextSpan != null) {
        spannable.removeSpan(mCurrentEditTextSpan);
    }//from   w w w .j  a  v  a  2 s.c o m
    spannable.setSpan(mCurrentEditTextSpan, 0, 0, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    mEditText.setText(spannable);
}

From source file:com.zitech.framework.widget.SlidingTabs.java

/**
 * call this function if you call some setXXX() function
 *///from  w  w  w .j a v a2 s  . c o m
private void updateTabStyles() {
    PagerAdapter adapter = this.pager.getAdapter();
    if (adapter instanceof TabsTitleInterface) {
        for (int i = 0; i < this.tabCount; i++) {
            View v = this.tabsContainer.getChildAt(i);
            v.setBackgroundResource(this.tabBackgroundResId);
            if (v instanceof TextView) {
                TextView tab = (TextView) v;
                SpannableString spannableString = ((TabsTitleInterface) adapter).getTabTitle(i);
                if (i == this.selectedPosition) {
                    spannableString.setSpan(new ForegroundColorSpan(this.selectedTabTextColor), 0,
                            spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                    tab.setText(spannableString);
                } else {
                    spannableString.setSpan(new ForegroundColorSpan(this.tabTextColor), 0,
                            spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                    tab.setText(spannableString);
                }
            }
        }
    } else {
        for (int i = 0; i < this.tabCount; i++) {
            View v = this.tabsContainer.getChildAt(i);
            v.setBackgroundResource(this.tabBackgroundResId);
            if (v instanceof TextView) {
                TextView tab = (TextView) v;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_SP, tabTextSize);
                tab.setTypeface(this.tabTypeface, this.tabTypefaceStyle);
                tab.setTextColor(this.tabTextColor);
                // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
                // pre-ICS-build
                if (textAllCaps) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        tab.setAllCaps(true);
                    } else {
                        tab.setText(tab.getText().toString().toUpperCase(locale));
                    }
                }
                if (i == this.selectedPosition) {
                    tab.setTextColor(this.selectedTabTextColor);
                } else {
                    tab.setTextColor(this.tabTextColor);
                }
            }
        }
    }
}

From source file:uk.co.ashtonbrsc.intentexplode.Explode.java

private void addTextToLayout(String text, int typeface, int paddingLeft, LinearLayout layout) {
    TextView textView = new TextView(this);
    ParagraphStyle style_para = new LeadingMarginSpan.Standard(0,
            (int) (STANDARD_INDENT_SIZE_IN_DIP * density));
    SpannableString styledText = new SpannableString(text);
    styledText.setSpan(style_para, 0, styledText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    textView.setText(styledText);/*from  ww w  .  j a v  a  2s . co  m*/
    textView.setTextAppearance(this, R.style.TextFlags);
    textView.setTypeface(null, typeface);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.setMargins((int) (paddingLeft * density), 0, 0, 0);
    layout.addView(textView, params);
}

From source file:com.taobao.weex.dom.WXTextDomObject.java

/**
 * Update {@link #spanned} according to the give charSequence and styles
 * @param text the give raw text.//  w w w. j  ava2s. c o m
 * @return an Spanned contains text and spans
 */
protected @NonNull Spanned createSpanned(String text) {
    if (!TextUtils.isEmpty(text)) {
        SpannableString spannable = new SpannableString(text);
        updateSpannable(spannable, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannable;
    }
    return new SpannableString("");
}

From source file:com.todoroo.astrid.adapter.TaskAdapter.java

private Function<TagData, SpannableString> tagToString(final float maxLength) {
    return tagData -> {
        String tagName = tagData.getName();
        tagName = tagName.substring(0, Math.min(tagName.length(), (int) maxLength));
        SpannableString string = new SpannableString(SPACE + tagName + SPACE);
        int themeIndex = tagData.getColor();
        ThemeColor color = themeIndex >= 0 ? themeCache.getThemeColor(themeIndex)
                : themeCache.getUntaggedColor();
        string.setSpan(new BackgroundColorSpan(color.getPrimaryColor()), 0, string.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        string.setSpan(new ForegroundColorSpan(color.getActionBarTint()), 0, string.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return string;
    };/*from w ww .  ja v  a2  s  .c o  m*/
}

From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java

private CharSequence generateFastForwardOrRewindTxt(long changingTime) {

    long duration = player == null ? 0 : player.getDuration();
    String result = stringForTime(changingTime) + " / " + stringForTime(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();/*w  w w  .j a v  a 2  s .  c om*/
    spannableString.setSpan(new ForegroundColorSpan(color), 0, index, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    return spannableString;
}

From source file:com.todoroo.astrid.adapter.UpdateAdapter.java

private static CharSequence getLinkSpan(final AstridActivity activity, UserActivity update, String targetName,
        String linkColor, String linkType) {
    if (TASK_LINK_TYPE.equals(linkType)) {
        final String taskId = update.getValue(UserActivity.TARGET_ID);
        if (RemoteModel.isValidUuid(taskId)) {
            SpannableString taskSpan = new SpannableString(targetName);
            taskSpan.setSpan(new ClickableSpan() {
                @Override/*from  w w  w.j  a  va 2s  .  c om*/
                public void onClick(View widget) {
                    if (activity != null) // TODO: This shouldn't happen, but sometimes does
                        activity.onTaskListItemClicked(taskId);
                }

                @Override
                public void updateDrawState(TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setUnderlineText(false);
                }
            }, 0, targetName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            return taskSpan;
        } else {
            return Html.fromHtml(linkify(targetName, linkColor));
        }
    }
    return null;
}

From source file:org.miaowo.miaowo.util.Html.java

private static void startCssStyle(Editable text, Attributes attributes) {
    String style = attributes.getValue("", "style");
    if (style != null) {
        final int len = text.length();
        Matcher m = getForegroundColorPattern().matcher(style);
        if (m.find()) {
            int c = Color.parseColor(m.group(1));
            if (c != -1) {
                text.setSpan(new Foreground(c | 0xFF000000), len, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            }// ww w .j a  v a2  s.  co  m
        }

        m = getBackgroundColorPattern().matcher(style);
        if (m.find()) {
            int c = Color.parseColor(m.group(1));
            if (c != -1) {
                text.setSpan(new Background(c | 0xFF000000), len, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            }
        }

        m = getTextDecorationPattern().matcher(style);
        if (m.find()) {
            String textDecoration = m.group(1);
            if (textDecoration.equalsIgnoreCase("line-through")) {
                text.setSpan(new Strikethrough(), len, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            }
        }
    }
}