Example usage for android.text Spannable setSpan

List of usage examples for android.text Spannable setSpan

Introduction

In this page you can find the example usage for android.text Spannable setSpan.

Prototype

public void setSpan(Object what, int start, int end, int flags);

Source Link

Document

Attach the specified markup object to the range start…end of the text, or move the object to that range if it was already attached elsewhere.

Usage

From source file:hku.fyp14017.blencode.ui.fragment.AddBrickFragment.java

public void onBrickChecked() {
    if (actionMode == null) {
        return;//from   w ww.j a v  a  2  s  .  co  m
    }

    int numberOfSelectedItems = adapter.getAmountOfCheckedItems();

    if (numberOfSelectedItems == 0) {
        actionMode.setTitle(actionModeTitle);
    } else {
        String appendix = multipleItemAppendixActionMode;

        if (numberOfSelectedItems == 1) {
            appendix = singleItemAppendixActionMode;
        }

        String numberOfItems = Integer.toString(numberOfSelectedItems);
        String completeTitle = actionModeTitle + " " + numberOfItems + " " + appendix;

        int titleLength = actionModeTitle.length();

        Spannable completeSpannedTitle = new SpannableString(completeTitle);
        completeSpannedTitle.setSpan(
                new ForegroundColorSpan(
                        getResources().getColor(hku.fyp14017.blencode.R.color.actionbar_title_color)),
                titleLength + 1, titleLength + (1 + numberOfItems.length()),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        actionMode.setTitle(completeSpannedTitle);
    }
}

From source file:hku.fyp14017.blencode.ui.fragment.BackPackSoundFragment.java

private void updateActionModeTitle() {
    int numberOfSelectedItems = adapter.getAmountOfCheckedItems();

    if (numberOfSelectedItems == 0) {
        actionMode.setTitle(actionModeTitle);
    } else {//ww w  . j ava  2s . c o  m
        String appendix = multipleItemAppendixDeleteActionMode;

        if (numberOfSelectedItems == 1) {
            appendix = singleItemAppendixDeleteActionMode;
        }

        String numberOfItems = Integer.toString(numberOfSelectedItems);
        String completeTitle = actionModeTitle + " " + numberOfItems + " " + appendix;

        int titleLength = actionModeTitle.length();

        Spannable completeSpannedTitle = new SpannableString(completeTitle);
        completeSpannedTitle.setSpan(
                new ForegroundColorSpan(
                        getResources().getColor(hku.fyp14017.blencode.R.color.actionbar_title_color)),
                titleLength + 1, titleLength + (1 + numberOfItems.length()),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        actionMode.setTitle(completeSpannedTitle);
    }
}

From source file:com.github.andrewlord1990.snackbarbuilder.SnackbarWrapper.java

/**
 * Append text in the specified color to the Snackbar.
 *
 * @param message The text to append.// w ww.jav  a  2  s.c om
 * @param color   The color to apply to the text.
 * @return This instance.
 */
public SnackbarWrapper appendMessage(CharSequence message, @ColorInt int color) {
    Spannable spannable = new SpannableString(message);
    spannable.setSpan(new ForegroundColorSpan(color), 0, spannable.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    messageView.append(spannable);
    return this;
}

From source file:com.arantius.tivocommander.Explore.java

protected void finishRequest() {
    if (--mRequestCount != 0) {
        return;/*from  w w w.j  a  v a 2  s  . co m*/
    }

    getParent().setProgressBarIndeterminateVisibility(false);

    if (mRecordingId == null) {
        for (JsonNode recording : mContent.path("recordingForContentId")) {
            String state = recording.path("state").asText();
            if ("inProgress".equals(state) || "complete".equals(state) || "scheduled".equals(state)) {
                mRecordingId = recording.path("recordingId").asText();
                mRecordingState = state;
                break;
            }
        }
    }

    // Fill mChoices based on the data we now have.
    if ("scheduled".equals(mRecordingState)) {
        mChoices.add(RecordActions.DONT_RECORD.toString());
    } else if ("inProgress".equals(mRecordingState)) {
        mChoices.add(RecordActions.RECORD_STOP.toString());
    } else if (mOfferId != null) {
        mChoices.add(RecordActions.RECORD.toString());
    }
    if (mSubscriptionId != null) {
        mChoices.add(RecordActions.SP_MODIFY.toString());
        mChoices.add(RecordActions.SP_CANCEL.toString());
    } else if (mCollectionId != null && !"movie".equals(mContent.path("collectionType").asText())
            && !mContent.has("movieYear")) {
        mChoices.add(RecordActions.SP_ADD.toString());
    }

    setContentView(R.layout.explore);

    // Show only appropriate buttons.
    findViewById(R.id.explore_btn_watch).setVisibility(
            "complete".equals(mRecordingState) || "inprogress".equals(mRecordingState) ? View.VISIBLE
                    : View.GONE);
    hideViewIfNull(R.id.explore_btn_upcoming, mCollectionId);
    if (mChoices.size() == 0) {
        findViewById(R.id.explore_btn_record).setVisibility(View.GONE);
    }
    // Delete / undelete buttons visible only if appropriate.
    findViewById(R.id.explore_btn_delete)
            .setVisibility("complete".equals(mRecordingState) ? View.VISIBLE : View.GONE);
    findViewById(R.id.explore_btn_undelete)
            .setVisibility("deleted".equals(mRecordingState) ? View.VISIBLE : View.GONE);

    // Display titles.
    String title = mContent.path("title").asText();
    String subtitle = mContent.path("subtitle").asText();
    ((TextView) findViewById(R.id.content_title)).setText(title);
    TextView subtitleView = ((TextView) findViewById(R.id.content_subtitle));
    if ("".equals(subtitle)) {
        subtitleView.setVisibility(View.GONE);
    } else {
        subtitleView.setText(subtitle);
    }

    // Display (only the proper) badges.
    if (mRecording != null && mRecording.path("episodic").asBoolean()
            && !mRecording.path("repeat").asBoolean()) {
        findViewById(R.id.badge_new).setVisibility(View.VISIBLE);
    }
    if (mRecording != null && mRecording.path("hdtv").asBoolean()) {
        findViewById(R.id.badge_hd).setVisibility(View.VISIBLE);
    }
    ImageView iconSubType = (ImageView) findViewById(R.id.icon_sub_type);
    TextView textSubType = (TextView) findViewById(R.id.text_sub_type);
    // TODO: Downloading state?
    if ("complete".equals(mRecordingState)) {
        iconSubType.setVisibility(View.GONE);
        textSubType.setVisibility(View.GONE);
    } else if ("inProgress".equals(mRecordingState)) {
        iconSubType.setImageResource(R.drawable.recording_recording);
        textSubType.setText(R.string.sub_recording);
    } else if (mSubscriptionType != null) {
        switch (mSubscriptionType) {
        case SEASON_PASS:
            iconSubType.setImageResource(R.drawable.todo_seasonpass);
            textSubType.setText(R.string.sub_season_pass);
            break;
        case SINGLE_OFFER:
            iconSubType.setImageResource(R.drawable.todo_single_offer);
            textSubType.setText(R.string.sub_single_offer);
            break;
        case WISHLIST:
            iconSubType.setImageResource(R.drawable.todo_wishlist);
            textSubType.setText(R.string.sub_wishlist);
            break;
        default:
            iconSubType.setVisibility(View.GONE);
            textSubType.setVisibility(View.GONE);
        }
    } else {
        iconSubType.setVisibility(View.GONE);
        textSubType.setVisibility(View.GONE);
    }

    // Display channel and time.
    if (mRecording != null) {
        String channelStr = "";
        JsonNode channel = mRecording.path("channel");
        if (!channel.isMissingNode()) {
            channelStr = String.format("%s %s, ", channel.path("channelNumber").asText(),
                    channel.path("callSign").asText());
        }

        // Lots of shows seem to be a few seconds short, add padding so that
        // rounding down works as expected. Magic number.
        final int minutes = (30 + mRecording.path("duration").asInt()) / 60;

        String durationStr = minutes >= 60 ? String.format(Locale.US, "%d hr", minutes / 60)
                : String.format(Locale.US, "%d min", minutes);
        if (isRecordingPartial()) {
            durationStr += " (partial)";
        }
        ((TextView) findViewById(R.id.content_chan_len)).setText(channelStr + durationStr);

        String airTime = new SimpleDateFormat("EEE MMM d, hh:mm a", Locale.US)
                .format(Utils.parseDateTimeStr(mRecording.path("actualStartTime").asText()));
        ((TextView) findViewById(R.id.content_air_time)).setText("Air time: " + airTime);
    } else {
        ((TextView) findViewById(R.id.content_chan_len)).setVisibility(View.GONE);
        ((TextView) findViewById(R.id.content_air_time)).setVisibility(View.GONE);
    }

    // Construct and display details.
    ArrayList<String> detailParts = new ArrayList<String>();
    int season = mContent.path("seasonNumber").asInt();
    int epNum = mContent.path("episodeNum").path(0).asInt();
    if (season != 0 && epNum != 0) {
        detailParts.add(String.format("Sea %d Ep %d", season, epNum));
    }
    if (mContent.has("mpaaRating")) {
        detailParts.add(mContent.path("mpaaRating").asText().toUpperCase(Locale.US));
    } else if (mContent.has("tvRating")) {
        detailParts.add("TV-" + mContent.path("tvRating").asText().toUpperCase(Locale.US));
    }
    detailParts.add(mContent.path("category").path(0).path("label").asText());
    int year = mContent.path("originalAirYear").asInt();
    if (year != 0) {
        detailParts.add(Integer.toString(year));
    }

    // Filter empty strings.
    for (int i = detailParts.size() - 1; i >= 0; i--) {
        if ("".equals(detailParts.get(i)) || null == detailParts.get(i)) {
            detailParts.remove(i);
        }
    }
    // Then format the parts into one string.
    String detail1 = "(" + Utils.join(", ", detailParts) + ") ";
    if ("() ".equals(detail1)) {
        detail1 = "";
    }

    String detail2 = mContent.path("description").asText();
    TextView detailView = ((TextView) findViewById(R.id.content_details));
    if (detail2 == null) {
        detailView.setText(detail1);
    } else {
        Spannable details = new SpannableString(detail1 + detail2);
        details.setSpan(new ForegroundColorSpan(Color.WHITE), detail1.length(), details.length(), 0);
        detailView.setText(details);
    }

    // Add credits.
    ArrayList<String> credits = new ArrayList<String>();
    for (JsonNode credit : mContent.path("credit")) {
        String role = credit.path("role").asText();
        if ("actor".equals(role) || "host".equals(role) || "guestStar".equals(role)) {
            credits.add(credit.path("first").asText() + " " + credit.path("last").asText());
        }
    }
    TextView creditsView = (TextView) findViewById(R.id.content_credits);
    creditsView.setText(Utils.join(", ", credits));

    // Find and set the banner image if possible.
    ImageView imageView = (ImageView) findViewById(R.id.content_image);
    View progressView = findViewById(R.id.content_image_progress);
    String imageUrl = Utils.findImageUrl(mContent);
    new DownloadImageTask(this, imageView, progressView).execute(imageUrl);
}

From source file:com.glandorf1.joe.wsprnetviewer.app.WsprFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // This is called when a new Loader needs to be created.  This
    // fragment only uses one loader, so we don't care about checking the id.

    // TODO: Filter the query to only return data from today and the previous N days.
    //        Calendar cal = Calendar.getInstance();
    //        cal.setTime(new Date());
    //        cal.add(Calendar.DATE, -7); // N= 7
    //        Date cutoffDate = cal.getTime();
    //        String startTimestamp = WsprNetContract.getDbTimestampString(cutoffDate);

    // Sort order:  Descending, by timestamp.
    String sortOrder = WsprNetContract.SignalReportEntry.COLUMN_TIMESTAMPTEXT + " DESC";
    String txCall = Utility.getFilterCallsign(getActivity(), true),
            rxCall = Utility.getFilterCallsign(getActivity(), false);
    String txGridsquare = Utility.getFilterGridsquare(getActivity(), true),
            rxGridsquare = Utility.getFilterGridsquare(getActivity(), false);
    txCall = Utility.filterCleanupForSQL(txCall);
    rxCall = Utility.filterCleanupForSQL(rxCall);
    txGridsquare = Utility.filterCleanupForSQL(txGridsquare);
    rxGridsquare = Utility.filterCleanupForSQL(rxGridsquare);
    mSelection = "";
    if (Utility.isFiltered(getActivity())) {
        // When adding filters, be sure to update onResume(), and save the preference value below, too.
        String prefAndOr = Utility.isFilterAnd(getActivity()) ? " and " : " or ";
        String sAndOr = " ";
        if (txCall.length() > 0) {
            sAndOr = (mSelection.length() > 0) ? prefAndOr : "";
            mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_TX_CALLSIGN + " like '"
                    + txCall + "')";
        }/*from  w w w  .  ja  v a 2  s .  c o  m*/
        if (rxCall.length() > 0) {
            sAndOr = (mSelection.length() > 0) ? prefAndOr : "";
            mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_RX_CALLSIGN + " like '"
                    + rxCall + "')";
        }
        if (txGridsquare.length() > 0) {
            sAndOr = (mSelection.length() > 0) ? prefAndOr : "";
            mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_TX_GRIDSQUARE + " like '"
                    + txGridsquare + "')";
        }
        if (rxGridsquare.length() > 0) {
            sAndOr = (mSelection.length() > 0) ? prefAndOr : "";
            mSelection += sAndOr + "(" + WsprNetContract.SignalReportEntry.COLUMN_RX_GRIDSQUARE + " like '"
                    + rxGridsquare + "')";
        }
        // Examples of resulting 'selection' clause:
        //   tx_callsign like 'D%'
        //   (tx_gridsquare like 'D%') and (rx_callsign like 'N%')
        //   (tx_gridsquare like 'D%') or (rx_callsign like 'N%')
        if (mSelection.length() > 0) {
            // Remind user that items are filtered, in case the result is not what they expect.
            Toast.makeText(getActivity(), getActivity().getString(R.string.toast_filter_items),
                    Toast.LENGTH_LONG).show();
        }
    }

    int mainDisplayPreference = Utility.getMainDisplayPreference(getActivity());
    if (mWsprAdapter.mainDisplayFormat != mainDisplayPreference) {
        // Update the gridsquare/callsign heading text based on the display layout.
        switch (mainDisplayPreference) {
        case Utility.MAIN_DISPLAY_CALLSIGN: // fit everything into 2 lines of display
            mTVGridCallHeader.setText(getActivity().getString(R.string.callsign));
            mTVGridCallHeader.setTextColor(getResources().getColor(R.color.wspr_brown));
            break;
        case Utility.MAIN_DISPLAY_GRIDCALL: // fit everything into 4 lines of display
            String g = getActivity().getString(R.string.grid);
            String c = getActivity().getString(R.string.call);
            Spannable s = new SpannableString(g + "/" + c);
            // In "Grid/Call", make "grid" black, "Call" brown, and "/" somewhere between.
            // Release: For "Grid", set the span to be 1 extra character.
            s.setSpan(new ForegroundColorSpan(Color.BLACK), 0, g.length() + 0,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            // Debug: For the "/", set the span to be 2 characters; it will won't display in the color if the span is only 1 character.
            s.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.wspr_brown2)), g.length() + 0,
                    g.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            s.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.wspr_brown)), g.length() + 1,
                    s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            mTVGridCallHeader.setText(s);
            break;
        case Utility.MAIN_DISPLAY_GRIDSQUARE: // fit everything into 2 lines of display
        default:
            mTVGridCallHeader.setText(getActivity().getString(R.string.gridsquare));
            mTVGridCallHeader.setTextColor(Color.BLACK);
        }

    }

    // Save some of the preferences to detect if they've changed in onResume().
    mGridsquare = Utility.getPreferredGridsquare(getActivity());
    mWsprAdapter.mainDisplayFormat = mainDisplayPreference;
    mFilterTxCallsign = Utility.getFilterCallsign(getActivity(), true);
    mFilterRxCallsign = Utility.getFilterCallsign(getActivity(), false);
    mFilterTxGridsquare = Utility.getFilterGridsquare(getActivity(), true);
    mFilterRxGridsquare = Utility.getFilterGridsquare(getActivity(), false);
    mFilterAnd = Utility.isFilterAnd(getActivity());
    mFiltered = Utility.isFiltered(getActivity());
    Uri wsprUri;
    wsprUri = WsprNetContract.SignalReportEntry.buildWspr();

    // Create and return a CursorLoader that will take care of creating a Cursor for the data being displayed.
    return new CursorLoader(getActivity(), // context
            wsprUri, // URI
            WSPR_COLUMNS, // String[] projection
            mSelection, // String selection
            null, // String[] selectionArgs
            sortOrder // String sortOrder
    );
}

From source file:com.money.manager.ex.core.Core.java

/**
 * This method allows to highlight in bold the content of a search string
 * @param search       string/*w  w  w .java 2  s . com*/
 * @param originalText string where to find
 * @return CharSequence modified
 */
public CharSequence highlight(String search, String originalText) {
    if (TextUtils.isEmpty(search))
        return originalText;
    // ignore case and accents
    // the same thing should have been done for the search text
    String normalizedText = Normalizer.normalize(originalText, Normalizer.Form.NFD)
            .replaceAll("\\p{InCombiningDiacriticalMarks}+", "").toLowerCase();

    int start = normalizedText.indexOf(search.toLowerCase());
    if (start < 0) {
        // not found, nothing to to
        return originalText;
    } else {
        // highlight each appearance in the original text
        // while searching in normalized text
        Spannable highlighted = new SpannableString(originalText);
        while (start >= 0) {
            int spanStart = Math.min(start, originalText.length());
            int spanEnd = Math.min(start + search.length(), originalText.length());

            highlighted.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), spanStart, spanEnd,
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            start = normalizedText.indexOf(search, spanEnd);
        }
        return highlighted;
    }
}

From source file:ayushi.view.fragment.ProductDetailsFragment.java

public void fillProductData() {

    if (!isFromCart) {

        //Fetch and display item from Gloabl Data Model

        itemName.setText(GlobaDataHolder.getGlobaDataHolder().getProductMap().get(subcategoryKey)
                .get(productListNumber).getItemName());

        quanitity.setText(GlobaDataHolder.getGlobaDataHolder().getProductMap().get(subcategoryKey)
                .get(productListNumber).getQuantity());

        itemdescription.setText(GlobaDataHolder.getGlobaDataHolder().getProductMap().get(subcategoryKey)
                .get(productListNumber).getItemDetail());

        String sellCostString = Money.rupees(BigDecimal.valueOf(Long.valueOf(GlobaDataHolder
                .getGlobaDataHolder().getProductMap().get(subcategoryKey).get(productListNumber).getSellMRP())))
                .toString() + "  ";

        String buyMRP = Money.rupees(BigDecimal.valueOf(Long.valueOf(GlobaDataHolder.getGlobaDataHolder()
                .getProductMap().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(GlobaDataHolder.getGlobaDataHolder().getProductMap().get(subcategoryKey)
                        .get(productListNumber).getItemName().charAt(0)),
                mColorGenerator.getColor(GlobaDataHolder.getGlobaDataHolder().getProductMap()
                        .get(subcategoryKey).get(productListNumber).getItemName()));

        Picasso.with(getActivity())//from w  w  w . ja va  2 s  .  c om
                .load(GlobaDataHolder.getGlobaDataHolder().getProductMap().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(GlobaDataHolder.getGlobaDataHolder().getProductMap().get(subcategoryKey)
                                        .get(productListNumber).getImageURL())
                                .placeholder(drawable).error(drawable).fit().centerCrop().into(itemImage);
                    }
                });

        LabelView label = new LabelView(getActivity());

        label.setText(GlobaDataHolder.getGlobaDataHolder().getProductMap().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(
                GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(productListNumber).getItemName());

        quanitity.setText(
                GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(productListNumber).getQuantity());

        itemdescription.setText(
                GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(productListNumber).getItemDetail());

        String sellCostString = Money.rupees(BigDecimal.valueOf(Long.valueOf(
                GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(productListNumber).getSellMRP())))
                .toString() + "  ";

        String buyMRP = Money.rupees(BigDecimal.valueOf(Long.valueOf(
                GlobaDataHolder.getGlobaDataHolder().getShoppingList().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(GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(productListNumber)
                        .getItemName().charAt(0)),
                mColorGenerator.getColor(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                        .get(productListNumber).getItemName()));

        Picasso.with(getActivity())
                .load(GlobaDataHolder.getGlobaDataHolder().getShoppingList().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(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                                        .get(productListNumber).getImageURL())
                                .placeholder(drawable).error(drawable).fit().centerCrop().into(itemImage);
                    }
                });

        LabelView label = new LabelView(getActivity());

        label.setText(
                GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(productListNumber).getDiscount());
        label.setBackgroundColor(0xffE91E63);

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

    }
}

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   w  ww  .  j a v  a  2  s  . c o  m
}

From source file:hku.fyp14017.blencode.ui.fragment.ScriptFragment.java

private void updateActionModeTitle() {
    int numberOfSelectedItems = adapter.getAmountOfCheckedItems();

    String completeTitle;/*  www .j a  v a  2s.c  o  m*/
    switch ((Integer) actionMode.getTag()) {
    case ACTION_MODE_COPY:
        completeTitle = getResources().getQuantityString(
                hku.fyp14017.blencode.R.plurals.number_of_bricks_to_copy, numberOfSelectedItems,
                numberOfSelectedItems);
        break;
    case ACTION_MODE_DELETE:
        completeTitle = getResources().getQuantityString(
                hku.fyp14017.blencode.R.plurals.number_of_bricks_to_delete, numberOfSelectedItems,
                numberOfSelectedItems);
        break;
    default:
        throw new IllegalArgumentException("Wrong or unhandled tag in ActionMode.");
    }

    int indexOfNumber = completeTitle.indexOf(' ') + 1;
    Spannable completeSpannedTitle = new SpannableString(completeTitle);
    completeSpannedTitle.setSpan(
            new ForegroundColorSpan(
                    getResources().getColor(hku.fyp14017.blencode.R.color.actionbar_title_color)),
            indexOfNumber, indexOfNumber + String.valueOf(numberOfSelectedItems).length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    actionMode.setTitle(completeSpannedTitle);
}

From source file:com.discord.chipsview.ChipsView.java

private void addLeadingMarginSpan(int margin) {
    Spannable spannable = mEditText.getText();
    if (mCurrentEditTextSpan != null) {
        spannable.removeSpan(mCurrentEditTextSpan);
    }//from   w  w w .  j a  v a 2 s  .c  om
    mCurrentEditTextSpan = new android.text.style.LeadingMarginSpan.LeadingMarginSpan2.Standard(margin, 0);
    spannable.setSpan(mCurrentEditTextSpan, 0, 0, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

    mEditText.setText(spannable);
}