Example usage for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE

List of usage examples for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE

Introduction

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

Prototype

int SPAN_EXCLUSIVE_EXCLUSIVE

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

Click Source Link

Document

Spans of type SPAN_EXCLUSIVE_EXCLUSIVE do not expand to include text inserted at either their starting or ending point.

Usage

From source file:in.shick.diode.threads.ThreadsListActivity.java

public static void fillThreadsListItemView(int position, View view, ThingInfo item, ListActivity activity,
        HttpClient client, RedditSettings settings,
        ThumbnailOnClickListenerFactory thumbnailOnClickListenerFactory) {

    Resources res = activity.getResources();
    ViewHolder vh;//from www. j  a va2 s  . com
    if (view.getTag() == null) {
        vh = new ViewHolder();
        vh.titleView = (TextView) view.findViewById(R.id.title);
        vh.votesView = (TextView) view.findViewById(R.id.votes);
        vh.numCommentsSubredditView = (TextView) view.findViewById(R.id.numCommentsSubreddit);
        vh.nsfwView = (TextView) view.findViewById(R.id.nsfw);
        vh.voteUpView = (ImageView) view.findViewById(R.id.vote_up_image);
        vh.voteDownView = (ImageView) view.findViewById(R.id.vote_down_image);
        vh.thumbnailContainer = view.findViewById(R.id.thumbnail_view);
        vh.thumbnailFrame = (FrameLayout) view.findViewById(R.id.thumbnail_frame);
        vh.thumbnailImageView = (ImageView) view.findViewById(R.id.thumbnail);
        vh.indeterminateProgressBar = (ProgressBar) view.findViewById(R.id.indeterminate_progress);
        view.setTag(vh);
    } else {
        vh = (ViewHolder) view.getTag();
    }

    // Need to store the Thing's id in the thumbnail image so that the thumbnail loader task
    // knows that the row is still displaying the requested thumbnail.
    vh.thumbnailImageView.setTag(item.getId());
    // Set the title and domain using a SpannableStringBuilder
    SpannableStringBuilder builder = new SpannableStringBuilder();
    String title = item.getTitle();
    if (title == null)
        title = "";
    SpannableString titleSS = new SpannableString(title);
    int titleLen = title.length();
    titleSS.setSpan(
            new TextAppearanceSpan(activity,
                    Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Large)),
            0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    String domain = item.getDomain();
    if (domain == null)
        domain = "";
    String flair = item.getLink_flair_text();
    if (flair == null) {
        flair = "";
    } else {
        flair = "[" + flair + "] ";
    }
    int domainLen = domain.length() + flair.length();
    SpannableString domainSS = new SpannableString(flair + "(" + item.getDomain() + ")");
    domainSS.setSpan(
            new TextAppearanceSpan(activity,
                    Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Small)),
            0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (Util.isLightTheme(settings.getTheme())) {
        if (item.isClicked()) {
            ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.purple));
            titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.blue));
            titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_50)), 0, domainLen + 2,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        if (item.isClicked()) {
            ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.gray_50));
            titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_75)), 0, domainLen + 2,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    builder.append(titleSS).append(" ").append(domainSS);
    vh.titleView.setText(builder);

    vh.votesView.setText(String.format(Locale.US, "%d", item.getScore()));
    // Lock icon emoji
    String preText = item.isLocked() ? "\uD83D\uDD12 " : "";
    vh.numCommentsSubredditView
            .setText(preText + Util.showNumComments(item.getNum_comments()) + "  " + item.getSubreddit());

    vh.nsfwView.setVisibility(item.isOver_18() ? View.VISIBLE : View.GONE);

    // Set the up and down arrow colors based on whether user likes
    if (settings.isLoggedIn()) {
        if (item.getLikes() == null) {
            vh.voteUpView.setImageResource(R.drawable.vote_up_gray);
            vh.voteDownView.setImageResource(R.drawable.vote_down_gray);
            vh.votesView.setTextColor(res.getColor(R.color.gray_75));
        } else if (item.getLikes()) {
            vh.voteUpView.setImageResource(R.drawable.vote_up_red);
            vh.voteDownView.setImageResource(R.drawable.vote_down_gray);
            vh.votesView.setTextColor(res.getColor(R.color.arrow_red));
        } else {
            vh.voteUpView.setImageResource(R.drawable.vote_up_gray);
            vh.voteDownView.setImageResource(R.drawable.vote_down_blue);
            vh.votesView.setTextColor(res.getColor(R.color.arrow_blue));
        }
    } else {
        vh.voteUpView.setImageResource(R.drawable.vote_up_gray);
        vh.voteDownView.setImageResource(R.drawable.vote_down_gray);
        vh.votesView.setTextColor(res.getColor(R.color.gray_75));
    }

    // Thumbnails open links
    if (vh.thumbnailContainer != null) {
        if (Common.shouldLoadThumbnails(activity, settings)) {
            vh.thumbnailContainer.setVisibility(View.VISIBLE);

            if (item.getUrl() != null) {
                OnClickListener thumbnailOnClickListener = thumbnailOnClickListenerFactory
                        .getThumbnailOnClickListener(item, activity);
                if (thumbnailOnClickListener != null) {
                    vh.thumbnailFrame.setOnClickListener(thumbnailOnClickListener);
                }
            }

            // Show thumbnail based on ThingInfo
            if (Constants.NSFW_STRING.equalsIgnoreCase(item.getThumbnail())
                    || Constants.DEFAULT_STRING.equals(item.getThumbnail())
                    || Constants.SUBMIT_KIND_SELF.equals(item.getThumbnail())
                    || StringUtils.isEmpty(item.getThumbnail())) {
                vh.indeterminateProgressBar.setVisibility(View.GONE);
                vh.thumbnailImageView.setVisibility(View.VISIBLE);
                vh.thumbnailImageView.setImageResource(R.drawable.go_arrow);
            } else {
                if (item.getThumbnailBitmap() != null) {
                    vh.indeterminateProgressBar.setVisibility(View.GONE);
                    vh.thumbnailImageView.setVisibility(View.VISIBLE);
                    vh.thumbnailImageView.setImageBitmap(item.getThumbnailBitmap());
                } else {
                    vh.indeterminateProgressBar.setVisibility(View.VISIBLE);
                    vh.thumbnailImageView.setVisibility(View.GONE);
                    vh.thumbnailImageView.setImageBitmap(null);
                    new ShowThumbnailsTask(activity, client, R.drawable.go_arrow)
                            .execute(new ThumbnailLoadAction(item, vh.thumbnailImageView, position,
                                    vh.indeterminateProgressBar));
                }
            }

            // Set thumbnail background based on current theme
            if (Util.isLightTheme(settings.getTheme()))
                vh.thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_light);
            else
                vh.thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_dark);
        } else {
            // if thumbnails disabled, hide thumbnail icon
            vh.thumbnailContainer.setVisibility(View.GONE);
        }
    }
}

From source file:com.googlecode.eyesfree.brailleback.BrailleIME.java

private void addMarkingSpan(Spannable spannable, MarkingSpan span, int position) {
    if (position < spannable.length()) {
        spannable.setSpan(span, position, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }//from  ww  w .j a  va 2s  .  c o m
}

From source file:io.plaidapp.ui.DesignerNewsStory.java

private void bindDescription() {
    final TextView storyComment = (TextView) header.findViewById(R.id.story_comment);
    if (!TextUtils.isEmpty(story.comment)) {
        HtmlUtils.parseMarkdownAndSetText(storyComment, story.comment, markdown,
                new Bypass.LoadImageCallback() {
                    @Override/*from w w  w.  j a  va 2s  . c o  m*/
                    public void loadImage(String src, ImageLoadingSpan loadingSpan) {
                        Glide.with(DesignerNewsStory.this).load(src).asBitmap()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .into(new ImageSpanTarget(storyComment, loadingSpan));
                    }
                });
    } else {
        storyComment.setVisibility(View.GONE);
    }

    upvoteStory = (TextView) header.findViewById(R.id.story_vote_action);
    upvoteStory.setText(getResources().getQuantityString(R.plurals.upvotes, story.vote_count,
            NumberFormat.getInstance().format(story.vote_count)));
    upvoteStory.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            upvoteStory();
        }
    });

    final TextView share = (TextView) header.findViewById(R.id.story_share_action);
    share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start();
            startActivity(ShareCompat.IntentBuilder.from(DesignerNewsStory.this).setText(story.url)
                    .setType("text/plain").setSubject(story.title).getIntent());
        }
    });

    TextView storyPosterTime = (TextView) header.findViewById(R.id.story_poster_time);
    SpannableString poster = new SpannableString(story.user_display_name.toLowerCase());
    poster.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_CommentAuthor), 0, poster.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    CharSequence job = !TextUtils.isEmpty(story.user_job) ? "\n" + story.user_job.toLowerCase() : "";
    CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(story.created_at.getTime(),
            System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase();
    storyPosterTime.setText(TextUtils.concat(poster, job, "\n", timeAgo));
    ImageView avatar = (ImageView) header.findViewById(R.id.story_poster_avatar);
    if (!TextUtils.isEmpty(story.user_portrait_url)) {
        Glide.with(this).load(story.user_portrait_url).placeholder(R.drawable.avatar_placeholder)
                .transform(circleTransform).into(avatar);
    } else {
        avatar.setVisibility(View.GONE);
    }
}

From source file:com.ruesga.rview.tasks.AsyncTextDiffProcessor.java

private CharSequence processHighlightTabs(CharSequence text) {
    if (!mHighlightTabs || !text.toString().contains(StringHelper.NON_PRINTABLE_CHAR)) {
        return text;
    }/*from   w  ww .  jav a  2s  .  com*/

    int color = ContextCompat.getColor(mContext, R.color.diffHighlightColor);
    SpannableStringBuilder ssb = new SpannableStringBuilder(text);
    String line = text.toString();
    int index = line.length();
    while ((index = line.lastIndexOf(StringHelper.NON_PRINTABLE_CHAR, index)) != -1) {
        ssb.replace(index, index + 1, "\u00BB    ");
        ssb.setSpan(new ForegroundColorSpan(color), index, index + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ssb.setSpan(new StyleSpan(Typeface.BOLD), index, index + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        index--;
    }
    return ssb;
}

From source file:io.plaidapp.designernews.ui.story.StoryActivity.java

private CharSequence getStoryPosterTimeText(String userDisplayName, String userJob, Date createdAt) {
    SpannableString poster = new SpannableString(userDisplayName.toLowerCase());
    poster.setSpan(new TextAppearanceSpan(this, io.plaidapp.R.style.TextAppearance_CommentAuthor), 0,
            poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    CharSequence job = !TextUtils.isEmpty(userJob) ? "\n" + userJob.toLowerCase() : "";
    CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(createdAt.getTime(), System.currentTimeMillis(),
            DateUtils.SECOND_IN_MILLIS).toString().toLowerCase();

    return TextUtils.concat(poster, job, "\n", timeAgo);
}

From source file:com.waz.zclient.controllers.notifications.NotificationsController.java

@TargetApi(21)
private SpannableString getMessageSpannable(String header, String body) {
    SpannableString messageSpannable = new SpannableString(header + body);
    final int textAppearance;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        textAppearance = android.R.style.TextAppearance_Material_Notification_Title;
    } else {//from w ww.  j  av  a2 s  .  co  m
        textAppearance = android.R.style.TextAppearance_StatusBar_EventContent_Title;
    }
    final TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(context, textAppearance);
    messageSpannable.setSpan(new ForegroundColorSpan(textAppearanceSpan.getTextColor().getDefaultColor()), 0,
            header.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return messageSpannable;
}

From source file:com.ruesga.rview.tasks.AsyncTextDiffProcessor.java

private CharSequence processHighlightTrailingSpaces(CharSequence text) {
    if (!mHighlightTrailingWhitespaces) {
        return text;
    }//from   w w  w .ja  v a2  s . com

    int color = ContextCompat.getColor(mContext, R.color.diffHighlightColor);
    final Spannable.Factory spannableFactory = Spannable.Factory.getInstance();
    String line = text.toString();
    final Matcher matcher = HIGHLIGHT_TRAIL_SPACES_PATTERN.matcher(line);
    if (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();
        Spannable span = spannableFactory.newSpannable(text);
        span.setSpan(new BackgroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return span;
    }
    return text;
}

From source file:com.ruesga.rview.widget.TagEditTextView.java

private void createChip(Editable s, boolean nextIsTag) {
    int start = mTagList.size();
    int end = s.length() + (nextIsTag ? -1 : 0);
    String tagText = s.subSequence(start, end).toString().trim();
    tagText = NON_UNICODE_CHAR_PATTERN.matcher(tagText).replaceAll("");
    if (tagText.isEmpty() || tagText.length() <= 1) {
        // User is still writing
        return;// w  w w. j  a  va  2  s.  c  o  m
    }
    String charText = tagText.substring(0, 1);
    if (!VALID_TAGS.contains(charText) || (charText.charAt(0) == VALID_TAGS.charAt(1) && !mSupportsUserTags)) {
        char tag = mDefaultTagMode == TAG_MODE.HASH ? VALID_TAGS.charAt(0) : VALID_TAGS.charAt(1);
        tagText = tag + tagText;
    }

    // Replace the new tag
    s.replace(start, end, CHIP_REPLACEMENT_CHAR);

    // Create the tag and its spannable
    final Tag tag = new Tag();
    tag.mTag = NON_UNICODE_CHAR_PATTERN.matcher(tagText).replaceAll("");
    Bitmap b = createTagChip(tag);
    ImageSpan span = new ImageSpan(getContext(), b);
    s.setSpan(span, start, start + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tag.w = b.getWidth();
    tag.h = b.getHeight();
    mTagList.add(tag);

    notifyTagCreated(tag);
}

From source file:com.android.calculator2.Calculator.java

void redisplayFormula() {
    SpannableStringBuilder formula = mEvaluator.getExpr().toSpannableStringBuilder(this);
    if (mUnprocessedChars != null) {
        // Add and highlight characters we couldn't process.
        formula.append(mUnprocessedChars, mUnprocessedColorSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }/*w ww .  j ava  2s . com*/
    mFormulaText.changeTextTo(formula);
}