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:com.vuze.android.remote.AndroidUtilsUI.java

public static void linkify(TextView tv) {
    tv.setMovementMethod(LinkMovementMethod.getInstance());
    CharSequence t = tv.getText();
    if (!(t instanceof SpannableString)) {
        return;//from  www.java  2  s . co m
    }
    SpannableString text = (SpannableString) t;

    int len = text.length();

    int next;
    for (int i = 0; i < text.length(); i = next) {
        next = text.nextSpanTransition(i, len, URLSpan.class);
        URLSpan[] old = text.getSpans(i, next, URLSpan.class);
        for (int j = old.length - 1; j >= 0; j--) {
            text.removeSpan(old[j]);

            UrlSpan2 span2 = new UrlSpan2(old[j].getURL());
            text.setSpan(span2, i, next, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }

}

From source file:com.hitesh_sahu.retailapp.view.fragment.ProductDetailsFragment.java

public void fillProductData() {

    if (!isFromCart) {

        //Fetch and display item from Gloabl Data Model

        itemName.setText(CenterRepository.getCenterRepository().getMapOfProductsInCategory().get(subcategoryKey)
                .get(productListNumber).getItemName());

        quanitity.setText(CenterRepository.getCenterRepository().getMapOfProductsInCategory()
                .get(subcategoryKey).get(productListNumber).getQuantity());

        itemdescription.setText(CenterRepository.getCenterRepository().getMapOfProductsInCategory()
                .get(subcategoryKey).get(productListNumber).getItemDetail());

        String sellCostString = Money
                .rupees(BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository()
                        .getMapOfProductsInCategory().get(subcategoryKey).get(productListNumber).getSellMRP())))
                .toString() + "  ";

        String buyMRP = Money//from   w  w w  .j a v a 2 s  .c  o m
                .rupees(BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository()
                        .getMapOfProductsInCategory().get(subcategoryKey).get(productListNumber).getMRP())))
                .toString();

        String costString = sellCostString + buyMRP;

        itemSellPrice.setText(costString, BufferType.SPANNABLE);

        Spannable spannable = (Spannable) itemSellPrice.getText();

        spannable.setSpan(new StrikethroughSpan(), sellCostString.length(), costString.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        mDrawableBuilder = TextDrawable.builder().beginConfig().withBorder(4).endConfig().roundRect(10);

        drawable = mDrawableBuilder.build(
                String.valueOf(CenterRepository.getCenterRepository().getMapOfProductsInCategory()
                        .get(subcategoryKey).get(productListNumber).getItemName().charAt(0)),
                mColorGenerator.getColor(CenterRepository.getCenterRepository().getMapOfProductsInCategory()
                        .get(subcategoryKey).get(productListNumber).getItemName()));

        Picasso.with(getActivity())
                .load(CenterRepository.getCenterRepository().getMapOfProductsInCategory().get(subcategoryKey)
                        .get(productListNumber).getImageURL())
                .placeholder(drawable).error(drawable).fit().centerCrop().networkPolicy(NetworkPolicy.OFFLINE)
                .into(itemImage, new Callback() {
                    @Override
                    public void onSuccess() {

                    }

                    @Override
                    public void onError() {
                        // Try again online if cache failed

                        Picasso.with(getActivity())
                                .load(CenterRepository.getCenterRepository().getMapOfProductsInCategory()
                                        .get(subcategoryKey).get(productListNumber).getImageURL())
                                .placeholder(drawable).error(drawable).fit().centerCrop().into(itemImage);
                    }
                });

        LabelView label = new LabelView(getActivity());

        label.setText(CenterRepository.getCenterRepository().getMapOfProductsInCategory().get(subcategoryKey)
                .get(productListNumber).getDiscount());
        label.setBackgroundColor(0xffE91E63);

        label.setTargetView(itemImage, 10, LabelView.Gravity.RIGHT_TOP);
    } else {

        //Fetch and display products from Shopping list

        itemName.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                .get(productListNumber).getItemName());

        quanitity.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                .get(productListNumber).getQuantity());

        itemdescription.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                .get(productListNumber).getItemDetail());

        String sellCostString = Money
                .rupees(BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository()
                        .getListOfProductsInShoppingList().get(productListNumber).getSellMRP())))
                .toString() + "  ";

        String buyMRP = Money.rupees(BigDecimal.valueOf(Long.valueOf(CenterRepository.getCenterRepository()
                .getListOfProductsInShoppingList().get(productListNumber).getMRP()))).toString();

        String costString = sellCostString + buyMRP;

        itemSellPrice.setText(costString, BufferType.SPANNABLE);

        Spannable spannable = (Spannable) itemSellPrice.getText();

        spannable.setSpan(new StrikethroughSpan(), sellCostString.length(), costString.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        mDrawableBuilder = TextDrawable.builder().beginConfig().withBorder(4).endConfig().roundRect(10);

        drawable = mDrawableBuilder.build(
                String.valueOf(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                        .get(productListNumber).getItemName().charAt(0)),
                mColorGenerator.getColor(CenterRepository.getCenterRepository()
                        .getListOfProductsInShoppingList().get(productListNumber).getItemName()));

        Picasso.with(getActivity())
                .load(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                        .get(productListNumber).getImageURL())
                .placeholder(drawable).error(drawable).fit().centerCrop().networkPolicy(NetworkPolicy.OFFLINE)
                .into(itemImage, new Callback() {
                    @Override
                    public void onSuccess() {

                    }

                    @Override
                    public void onError() {
                        // Try again online if cache failed

                        Picasso.with(getActivity())
                                .load(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                                        .get(productListNumber).getImageURL())
                                .placeholder(drawable).error(drawable).fit().centerCrop().into(itemImage);
                    }
                });

        LabelView label = new LabelView(getActivity());

        label.setText(CenterRepository.getCenterRepository().getListOfProductsInShoppingList()
                .get(productListNumber).getDiscount());
        label.setBackgroundColor(0xffE91E63);

        label.setTargetView(itemImage, 10, LabelView.Gravity.RIGHT_TOP);

    }
}

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

private void processNoIntralineDataA(DiffContentInfo diff, DiffInfoModel m, String line, int color) {
    final Spannable.Factory spannableFactory = Spannable.Factory.getInstance();
    if (diff.a != null && diff.b != null && diff.a.length == 1 && diff.b.length == 1) {
        Spannable span = spannableFactory.newSpannable(prepareTabs(line));
        int z = diff.a[0].indexOf(diff.b[0]);
        if (z != -1) {
            if (z > 0) {
                span.setSpan(new BackgroundColorSpan(color), 0, z, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }/*from ww w.ja  v  a  2  s  .  c om*/
            if (z + diff.b[0].length() < diff.a[0].length()) {
                z = z + diff.b[0].length();
                span.setSpan(new BackgroundColorSpan(color), z, diff.a[0].length(),
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        m.lineA = span;
    } else {
        m.lineA = prepareTabs(line);
    }
}

From source file:org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder.java

private Spanned getTitleStringByFriends(int stringRes, int stringResMulti, ParcelableUser[] sources,
        Object[] targets) {//from  ww  w  . j a  v a  2  s.com
    if (sources == null || sources.length == 0)
        return null;
    final Context context = adapter.getContext();
    final Resources resources = context.getResources();
    final Configuration configuration = resources.getConfiguration();
    final UserColorNameManager manager = adapter.getUserColorNameManager();
    final boolean nameFirst = adapter.isNameFirst();
    final SpannableString firstSourceName = new SpannableString(
            manager.getDisplayName(sources[0], nameFirst, false));
    firstSourceName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstSourceName.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    final String displayName;
    final Object target = targets[0];
    if (target instanceof ParcelableUser) {
        displayName = manager.getDisplayName((ParcelableUser) target, nameFirst, false);
    } else if (target instanceof ParcelableStatus) {
        displayName = manager.getDisplayName((ParcelableStatus) target, nameFirst, false);
    } else {
        throw new IllegalArgumentException();
    }
    final SpannableString firstTargetName = new SpannableString(displayName);
    firstTargetName.setSpan(new StyleSpan(Typeface.BOLD), 0, firstTargetName.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (sources.length == 1) {
        final String format = context.getString(stringRes);
        return SpanFormatter.format(configuration.locale, format, firstSourceName, firstTargetName);
    } else if (sources.length == 2) {
        final String format = context.getString(stringResMulti);
        final SpannableString secondSourceName = new SpannableString(
                manager.getDisplayName(sources[1], nameFirst, false));
        secondSourceName.setSpan(new StyleSpan(Typeface.BOLD), 0, secondSourceName.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return SpanFormatter.format(configuration.locale, format, firstSourceName, secondSourceName,
                firstTargetName);
    } else {
        final int othersCount = sources.length - 1;
        final SpannableString nOthers = new SpannableString(
                resources.getQuantityString(R.plurals.N_others, othersCount, othersCount));
        nOthers.setSpan(new StyleSpan(Typeface.BOLD), 0, nOthers.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        final String format = context.getString(stringResMulti);
        return SpanFormatter.format(configuration.locale, format, firstSourceName, nOthers, firstTargetName);
    }
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyKeybaseFragment.java

@Override
public void onCryptoOperationError(KeybaseVerificationResult result) {

    result.createNotify(getActivity()).show();

    SpannableStringBuilder ssb = new SpannableStringBuilder();

    ssb.append(getString(R.string.keybase_proof_failure));
    String msg = getString(result.getLog().getLast().mType.mMsgId);
    if (msg == null) {
        msg = getString(R.string.keybase_unknown_proof_failure);
    }/* ww w  .  j a v a 2s. c om*/
    StyleSpan bold = new StyleSpan(Typeface.BOLD);
    ssb.setSpan(bold, 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append("\n\n").append(msg);

    displaySpannableResult(ssb);
}

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

public void setTags(Tag[] tags) {
    // Delete any existent data
    try {/*  w w w . j a  v a  2 s. c om*/
        mTagEdit.getEditableText().clearSpans();
    } catch (Exception ex) {
        // Ignore
    }
    int count = mTagList.size() - 1;
    for (int i = count; i >= 0; i--) {
        onTagRemoveClick(mTagList.get(i));
    }
    mTagEdit.setText("");

    if (tags == null) {
        return;
    }

    // Filter invalid tags
    for (Tag tag : tags) {
        Matcher hashTagMatcher = HASH_TAG_PATTERN.matcher(tag.mTag);
        Matcher userTagMatcher = USER_TAG_PATTERN.matcher(tag.mTag);
        if (hashTagMatcher.matches() || (mSupportsUserTags && userTagMatcher.matches())) {
            mTagList.add(tag);
        }
    }

    // Build the spans
    SpannableStringBuilder builder;
    if (tags.length > 0) {
        final String text = String.format("%" + tags.length + "s", CHIP_SEPARATOR_CHAR)
                .replaceAll(CHIP_SEPARATOR_CHAR, CHIP_REPLACEMENT_CHAR);
        builder = new SpannableStringBuilder(text);
    } else {
        builder = new SpannableStringBuilder("");
    }

    int pos = 0;
    for (final Tag tag : mTagList) {
        Bitmap b = createTagChip(tag);
        tag.w = b.getWidth();
        tag.h = b.getHeight();
        ImageSpan span = new ImageSpan(getContext(), b, ImageSpan.ALIGN_BOTTOM);
        builder.setSpan(span, pos, pos + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        pos++;

        notifyTagCreated(tag);
    }
    mTagEdit.setText(builder);
    mTagEdit.setSelection(mTagEdit.getText().length());
}

From source file:net.maa123.tatuky.MainActivity.java

private void setupSearchView() {
    searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());

    // Setup content descriptions for the different elements in the search view.
    final View leftAction = searchView.findViewById(R.id.left_action);
    leftAction.setContentDescription(getString(R.string.action_open_drawer));
    searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
        @Override//from  w ww  . j  a  v a  2 s.  c  o m
        public void onFocus() {
            leftAction.setContentDescription(getString(R.string.action_close));
        }

        @Override
        public void onFocusCleared() {
            leftAction.setContentDescription(getString(R.string.action_open_drawer));
        }
    });
    View clearButton = searchView.findViewById(R.id.clear_btn);
    clearButton.setContentDescription(getString(R.string.action_clear));

    searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
        @Override
        public void onSearchTextChanged(String oldQuery, String newQuery) {
            if (!oldQuery.equals("") && newQuery.equals("")) {
                searchView.clearSuggestions();
                return;
            }

            if (newQuery.length() < 3) {
                return;
            }

            searchView.showProgress();

            mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() {
                @Override
                public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
                    if (response.isSuccessful()) {
                        searchView.swapSuggestions(response.body());
                        searchView.hideProgress();
                    } else {
                        searchView.hideProgress();
                    }
                }

                @Override
                public void onFailure(Call<List<Account>> call, Throwable t) {
                    searchView.hideProgress();
                }
            });
        }
    });

    searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
        @Override
        public void onSuggestionClicked(SearchSuggestion searchSuggestion) {
            Account accountSuggestion = (Account) searchSuggestion;
            Intent intent = new Intent(MainActivity.this, AccountActivity.class);
            intent.putExtra("id", accountSuggestion.id);
            startActivity(intent);
        }

        @Override
        public void onSearchAction(String currentQuery) {
        }
    });

    searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
        @Override
        public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView,
                SearchSuggestion item, int itemPosition) {
            Account accountSuggestion = ((Account) item);

            Picasso.with(MainActivity.this).load(accountSuggestion.avatar)
                    .placeholder(R.drawable.avatar_default).into(leftIcon);

            String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username;
            final SpannableStringBuilder str = new SpannableStringBuilder(searchStr);

            str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            textView.setText(str);
            textView.setMaxLines(1);
            textView.setEllipsize(TextUtils.TruncateAt.END);
        }
    });
}

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

private void processNoIntralineDataB(DiffContentInfo diff, DiffInfoModel m, String line, int color) {
    final Spannable.Factory spannableFactory = Spannable.Factory.getInstance();
    if (diff.a != null && diff.b != null && diff.a.length == 1 && diff.b.length == 1) {
        Spannable span = spannableFactory.newSpannable(prepareTabs(line));
        int z = diff.b[0].indexOf(diff.a[0]);
        if (z != -1) {
            if (z > 0) {
                span.setSpan(new BackgroundColorSpan(color), 0, z, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }/* w  ww  .  j  av  a  2s  .c  o  m*/
            if (z + diff.a[0].length() < diff.b[0].length()) {
                z = z + diff.a[0].length();
                span.setSpan(new BackgroundColorSpan(color), z, diff.b[0].length(),
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        m.lineB = span;
    } else {
        m.lineB = prepareTabs(line);
    }
}

From source file:org.thoughtcrime.securesms.ConversationItem.java

private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) {
    boolean hasLinks = Linkify.addLinks(messageBody, shouldLinkifyAllLinks ? Linkify.ALL : 0);

    if (hasLinks) {
        URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
        for (URLSpan urlSpan : urlSpans) {
            int start = messageBody.getSpanStart(urlSpan);
            int end = messageBody.getSpanEnd(urlSpan);
            messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }/*from www.  j av  a  2 s.  c o  m*/
    }
    return messageBody;
}

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.setTextWithNiceLinks(storyComment,
                markdown.markdownToSpannable(story.comment, storyComment, new Bypass.LoadImageCallback() {
                    @Override/* w w w  . jav a2s .  c om*/
                    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 = (Button) 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();
        }
    });

    Button share = (Button) header.findViewById(R.id.story_share_action);
    share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            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);
    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 : "";
    CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(story.created_at.getTime(),
            System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
    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);
    }
}