Example usage for android.text SpannableStringBuilder setSpan

List of usage examples for android.text SpannableStringBuilder setSpan

Introduction

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

Prototype

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

Source Link

Document

Mark the specified range of text with the specified object.

Usage

From source file:org.dalmasso.ietfsched.ui.SessionDetailFragment.java

/**
 * Handle {@link SessionsQuery} {@link Cursor}.
 *///from  w  w  w.  j a va  2s  .  c om
private void onSessionQueryComplete(Cursor cursor) {
    try {
        mSessionCursor = true;
        if (!cursor.moveToFirst()) {
            return;
        }

        // Format time block this session occupies
        final long blockStart = cursor.getLong(SessionsQuery.BLOCK_START);
        final long blockEnd = cursor.getLong(SessionsQuery.BLOCK_END);
        final String roomName = cursor.getString(SessionsQuery.ROOM_NAME);
        final String subtitle = UIUtils.formatSessionSubtitle(blockStart, blockEnd, roomName, getActivity());

        mTitleString = cursor.getString(SessionsQuery.TITLE);
        mTitle.setText(mTitleString);
        mSubtitle.setText(subtitle);

        mUrl = cursor.getString(SessionsQuery.URL);
        if (TextUtils.isEmpty(mUrl)) {
            mUrl = "";
        }

        mHashtag = cursor.getString(SessionsQuery.HASHTAG);
        mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button);
        if (!TextUtils.isEmpty(mHashtag)) {
            // Create the button text
            SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append(getString(R.string.tag_stream) + " ");
            int boldStart = sb.length();
            sb.append(getHashtagsString());
            sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            mTagDisplay.setText(sb);

            mTagDisplay.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    /*                        Intent intent = new Intent(getActivity(), TagStreamActivity.class);
                                            intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString());
                                            startActivity(intent);
                    */ Log.d(TAG, "on click mTagDisplay");
                }
            });
        } else {
            mTagDisplay.setVisibility(View.GONE);
        }

        mRoomId = cursor.getString(SessionsQuery.ROOM_ID);

        // Unregister around setting checked state to avoid triggering
        // listener since change isn't user generated.
        mStarred.setOnCheckedChangeListener(null);
        mStarred.setChecked(cursor.getInt(SessionsQuery.STARRED) != 0);
        mStarred.setOnCheckedChangeListener(this);

        final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT);
        if (!TextUtils.isEmpty(sessionAbstract)) {
            UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract);
            mAbstract.setVisibility(View.VISIBLE);
            mHasSummaryContent = true;
        } else {
            mAbstract.setVisibility(View.GONE);
        }

        /*            final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block);
                    final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS);
                    if (!TextUtils.isEmpty(sessionRequirements)) {
        UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements);
        requirementsBlock.setVisibility(View.VISIBLE);
        mHasSummaryContent = true;
                    } else {
        requirementsBlock.setVisibility(View.GONE);
                    }
                      
        */

        // Show empty message when all data is loaded, and nothing to show
        //            if (mSpeakersCursor && !mHasSummaryContent) {
        if (!mHasSummaryContent) {
            mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
        } else {
            mTabHost.setCurrentTabByTag(TAG_SUMMARY);
        }

        //            AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString);

        updateLinksTab(cursor);
        updateNotesTab();

    } finally {
        cursor.close();
    }
}

From source file:com.yahala.ui.GroupCreateActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {

        searching = false;/*from w  w w .j  a v  a  2 s  .c  o  m*/
        searchWas = false;

        fragmentView = inflater.inflate(R.layout.group_create_layout, container, false);

        emptyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
        userSelectEditText = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
        userSelectEditText.setHint(LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
        if (Build.VERSION.SDK_INT >= 11) {
            userSelectEditText.setTextIsSelectable(false);
        }
        userSelectEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
                if (!ignoreChange) {
                    beforeChangeIndex = userSelectEditText.getSelectionStart();
                    changeString = new SpannableString(charSequence);
                }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!ignoreChange) {
                    boolean search = false;
                    int afterChangeIndex = userSelectEditText.getSelectionEnd();
                    if (editable.toString().length() < changeString.toString().length()) {
                        String deletedString = "";
                        try {
                            deletedString = changeString.toString().substring(afterChangeIndex,
                                    beforeChangeIndex);
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        if (deletedString.length() > 0) {
                            if (searching && searchWas) {
                                search = true;
                            }
                            Spannable span = userSelectEditText.getText();
                            for (int a = 0; a < allSpans.size(); a++) {
                                XImageSpan sp = allSpans.get(a);
                                if (span.getSpanStart(sp) == -1) {
                                    allSpans.remove(sp);
                                    selectedContacts.remove(sp.jid);
                                }
                            }
                            if (parentActivity != null) {
                                ActionBar actionBar = parentActivity.getSupportActionBar();
                                actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(),
                                        LocaleController.getString("Members", R.string.Members)));
                            }
                            listView.invalidateViews();
                        } else {
                            search = true;
                        }
                    } else {
                        search = true;
                    }
                    if (search) {
                        String text = userSelectEditText.getText().toString().replace("<", "");
                        if (text.length() != 0) {
                            searchDialogs(text);
                            searching = true;
                            searchWas = true;
                            emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
                            listViewAdapter.notifyDataSetChanged();
                        } else {
                            searchResult = null;
                            searchResultNames = null;
                            searching = false;
                            searchWas = false;
                            emptyTextView
                                    .setText(LocaleController.getString("NoContacts", R.string.NoContacts));
                            listViewAdapter.notifyDataSetChanged();
                        }
                    }
                }
            }
        });

        listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
        listView.setEmptyView(emptyTextView);
        listView.setVerticalScrollBarEnabled(false);

        listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TLRPC.User user;
                int section = listViewAdapter.getSectionForPosition(i);
                int row = listViewAdapter.getPositionInSectionForPosition(i);
                if (searching && searchWas) {
                    user = searchResult.get(row);
                } else {
                    ArrayList<TLRPC.User> arr = com.yahala.xmpp.ContactsController
                            .getInstance().usersSectionsDict.get(
                                    com.yahala.xmpp.ContactsController.getInstance().sortedUsersSectionsArray
                                            .get(section));
                    user = com.yahala.xmpp.ContactsController.getInstance().friendsDict.get(arr.get(row).jid);
                    listView.invalidateViews();
                }
                if (selectedContacts.containsKey(user.jid)) {
                    XImageSpan span = selectedContacts.get(user.jid);
                    selectedContacts.remove(user.jid);
                    SpannableStringBuilder text = new SpannableStringBuilder(userSelectEditText.getText());
                    text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                    allSpans.remove(span);
                    ignoreChange = true;
                    userSelectEditText.setText(text);
                    userSelectEditText.setSelection(text.length());
                    ignoreChange = false;
                } else {
                    if (selectedContacts.size() == 200) {
                        return;
                    }
                    ignoreChange = true;
                    XImageSpan span = createAndPutChipForUser(user);
                    span.jid = user.jid;
                    ignoreChange = false;
                }
                if (parentActivity != null) {
                    ActionBar actionBar = parentActivity.getSupportActionBar();
                    actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(),
                            LocaleController.getString("Members", R.string.Members)));
                }
                if (searching || searchWas) {
                    searching = false;
                    searchWas = false;
                    emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));

                    ignoreChange = true;
                    SpannableStringBuilder ssb = new SpannableStringBuilder("");
                    for (ImageSpan sp : allSpans) {
                        ssb.append("<<");
                        ssb.setSpan(sp, ssb.length() - 2, ssb.length(),
                                SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    userSelectEditText.setText(ssb);
                    userSelectEditText.setSelection(ssb.length());
                    ignoreChange = false;

                    listViewAdapter.notifyDataSetChanged();
                } else {
                    listView.invalidateViews();
                }
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.google.android.apps.iosched2.ui.SessionDetailFragment.java

/**
 * Handle {@link SessionsQuery} {@link Cursor}.
 *//* w w w.java2s  .c  om*/
private void onSessionQueryComplete(Cursor cursor) {
    try {
        mSessionCursor = true;
        if (!cursor.moveToFirst()) {
            return;
        }

        // Format time block this session occupies
        final long blockStart = cursor.getLong(SessionsQuery.BLOCK_START);
        final long blockEnd = cursor.getLong(SessionsQuery.BLOCK_END);
        final String roomName = cursor.getString(SessionsQuery.ROOM_NAME);
        final String subtitle = UIUtils.formatSessionSubtitle(blockStart, blockEnd, roomName, getActivity());

        mTitleString = cursor.getString(SessionsQuery.TITLE);
        mTitle.setText(mTitleString);
        mSubtitle.setText(subtitle);

        mUrl = cursor.getString(SessionsQuery.URL);
        if (TextUtils.isEmpty(mUrl)) {
            mUrl = "";
        }

        mHashtag = cursor.getString(SessionsQuery.HASHTAG);
        mTagDisplay = (TextView) mRootView.findViewById(R.id.session_tags_button);
        if (!TextUtils.isEmpty(mHashtag)) {
            // Create the button text
            SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append(getString(R.string.tag_stream) + " ");
            int boldStart = sb.length();
            sb.append(getHashtagsString());
            sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            mTagDisplay.setText(sb);

            mTagDisplay.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    //Intent intent = new Intent(getActivity(), TagStreamActivity.class);
                    Intent intent = new Intent(getActivity(), Setup.TagStreamActivityClass);

                    intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString());
                    startActivity(intent);
                }
            });
        } else {
            mTagDisplay.setVisibility(View.GONE);
        }

        mRoomId = cursor.getString(SessionsQuery.ROOM_ID);

        // Unregister around setting checked state to avoid triggering
        // listener since change isn't user generated.
        mStarred.setOnCheckedChangeListener(null);
        mStarred.setChecked(cursor.getInt(SessionsQuery.STARRED) != 0);
        mStarred.setOnCheckedChangeListener(this);

        final String sessionAbstract = cursor.getString(SessionsQuery.ABSTRACT);
        if (!TextUtils.isEmpty(sessionAbstract)) {
            UIUtils.setTextMaybeHtml(mAbstract, sessionAbstract);
            mAbstract.setVisibility(View.VISIBLE);
            mHasSummaryContent = true;
        } else {
            mAbstract.setVisibility(View.GONE);
        }

        final View requirementsBlock = mRootView.findViewById(R.id.session_requirements_block);
        final String sessionRequirements = cursor.getString(SessionsQuery.REQUIREMENTS);
        if (!TextUtils.isEmpty(sessionRequirements)) {
            UIUtils.setTextMaybeHtml(mRequirements, sessionRequirements);
            requirementsBlock.setVisibility(View.VISIBLE);
            mHasSummaryContent = true;
        } else {
            requirementsBlock.setVisibility(View.GONE);
        }

        final View levelBlock = mRootView.findViewById(R.id.session_level_block);
        final String sessionLevel = cursor.getString(SessionsQuery.LEVEL);
        if (!TextUtils.isEmpty(sessionLevel)) {
            UIUtils.setTextMaybeHtml(mLevel, sessionLevel);
            levelBlock.setVisibility(View.VISIBLE);
            mHasSummaryContent = true;
        } else {
            levelBlock.setVisibility(View.GONE);
        }

        // Show empty message when all data is loaded, and nothing to show
        if (mSpeakersCursor && !mHasSummaryContent) {
            mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
        }

        AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + mTitleString);

        updateLinksTab(cursor);
        updateNotesTab();

    } finally {
        cursor.close();
    }
}

From source file:com.heath_bar.tvdb.SeriesOverview.java

/** Populate the interface with the data pulled from the webz */
private void PopulateStuff(TvSeries seriesInfo) {

    if (seriesInfo == null) {
        Toast.makeText(getApplicationContext(), "Something bad happened. No data was found.",
                Toast.LENGTH_SHORT).show();
        return;/*w  ww  . j a  v  a2  s.c o m*/
    }

    // Set title
    getSupportActionBar().setTitle(seriesInfo.getName());

    // Hide/Activate the favorites button
    if (seriesInfo.isFavorite(getApplicationContext())) {
        Button b = (Button) findViewById(R.id.btn_add_to_favorites);
        b.setVisibility(View.GONE);
    } else {
        Button b = (Button) findViewById(R.id.btn_add_to_favorites);
        b.setVisibility(View.VISIBLE);
        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Button b = (Button) findViewById(R.id.btn_add_to_favorites);
                b.setVisibility(View.GONE);
                addToFavorites();
            }
        });
    }

    // Set the banner
    ImageView imageView = (ImageView) findViewById(R.id.series_banner);
    imageView.setImageBitmap(seriesInfo.getImage().getBitmap());
    imageView.setVisibility(View.VISIBLE);
    final String seriesName = seriesInfo.getName();

    imageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            shareImage();
        }
    });

    // Set the banner link
    TextView textview = (TextView) findViewById(R.id.banner_listing_link);
    textview.setTextColor(getResources().getColor(R.color.tvdb_green));
    textview.setVisibility(View.VISIBLE);
    textview.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), BannerListing.class);
            i.putExtra("seriesId", seriesId);
            i.putExtra("seriesName", seriesName);
            startActivity(i);
        }
    });

    // Set air info
    textview = (TextView) findViewById(R.id.airs_header);
    textview.setVisibility(View.VISIBLE);
    textview = (TextView) findViewById(R.id.last_episode);
    textview.setVisibility(View.VISIBLE);
    textview = (TextView) findViewById(R.id.next_episode);
    textview.setVisibility(View.VISIBLE);

    textview = (TextView) findViewById(R.id.series_air_info);
    StringBuffer sb = new StringBuffer();
    sb.append(seriesInfo.getAirDay());
    if (!seriesInfo.getAirTime().equals(""))
        sb.append(" at " + seriesInfo.getAirTime());
    if (!seriesInfo.getNetwork().equals(""))
        sb.append(" on " + seriesInfo.getNetwork());
    textview.setText(sb.toString());
    textview.setVisibility(View.VISIBLE);

    // Set actors
    textview = (TextView) findViewById(R.id.starring);
    textview.setVisibility(View.VISIBLE);
    textview = (TextView) findViewById(R.id.series_actors);
    textview.setVisibility(View.VISIBLE);

    SpannableStringBuilder text = tagsBuilder(seriesInfo.getActors(), "|");
    textview.setText(text, BufferType.SPANNABLE);
    textview.setMovementMethod(LinkMovementMethod.getInstance());

    // Set rating
    textview = (TextView) findViewById(R.id.rating_header);
    textview.setVisibility(View.VISIBLE);

    textview = (TextView) findViewById(R.id.rating);
    textview.setText(seriesInfo.getRating() + " / 10");
    textview.setVisibility(View.VISIBLE);

    // Set genre
    textview = (TextView) findViewById(R.id.genre_header);
    textview.setVisibility(View.VISIBLE);

    textview = (TextView) findViewById(R.id.genre);
    textview.setText(StringUtil.commafy(seriesInfo.getGenre()));
    textview.setVisibility(View.VISIBLE);

    // Set runtime
    textview = (TextView) findViewById(R.id.runtime_header);
    textview.setVisibility(View.VISIBLE);

    textview = (TextView) findViewById(R.id.runtime);
    textview.setText(seriesInfo.getRuntime() + " minutes");
    textview.setVisibility(View.VISIBLE);

    // Set overview
    textview = (TextView) findViewById(R.id.overview_header);
    textview.setVisibility(View.VISIBLE);

    textview = (TextView) findViewById(R.id.overview);
    textview.setText(seriesInfo.getOverview());
    textview.setVisibility(View.VISIBLE);

    // Show Seasons header
    textview = (TextView) findViewById(R.id.seasons_header);
    textview.setVisibility(View.VISIBLE);

    // IMDB Link
    textview = (TextView) findViewById(R.id.imdb_link);
    textview.setVisibility(View.VISIBLE);

    final String imdbId = seriesInfo.getIMDB();
    SpannableStringBuilder ssb = new SpannableStringBuilder(getResources().getString(R.string.imdb));
    ssb.setSpan(new NonUnderlinedClickableSpan(getResources().getString(R.string.imdb)) {
        @Override
        public void onClick(View v) {
            Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.imdb.com/title/" + imdbId));
            startActivity(myIntent);
        }
    }, 0, ssb.length(), 0);

    ssb.setSpan(new TextAppearanceSpan(this, R.style.episode_link), 0, ssb.length(), 0); // Set the style of the text
    textview.setText(ssb, BufferType.SPANNABLE);
    textview.setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.heneryh.aquanotes.ui.CtlrStatusFragment.java

/**
 * Handle {@link SessionsQuery} {@link Cursor}.
 *//*from  w w w . j  ava 2 s  .c o m*/
private void updateControllerTabs(Ctlr cntl, Cursor cursor) {
    try {
        mSessionCursor = true;

        // Header Area
        cntl.mTitleString = cursor.getString(ControllersQuery.TITLE);
        cntl.mSubtitle = cursor.getString(ControllersQuery.WAN_URL);
        cntl.mTitleView.setText(cntl.mTitleString);
        cntl.mSubtitleView.setText(cntl.mSubtitle);

        // Probes Tab Area
        cntl.mUrl = "http://test"; //cursor.getString(SessionsQuery.URL);
        if (TextUtils.isEmpty(cntl.mUrl)) {
            cntl.mUrl = "";
        }

        cntl.mHashtag = ""; //cursor.getString(SessionsQuery.HASHTAG);
        if (!TextUtils.isEmpty(cntl.mHashtag)) {
            // Create the button text
            SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append(getString(R.string.tag_stream) + " ");
            int boldStart = sb.length();
            sb.append(getHashtagsString(cntl.mHashtag));
            sb.setSpan(sBoldSpan, boldStart, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

            cntl.mTagDisplayView.setText(sb);

            cntl.mTagDisplayView.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), TagStreamActivity.class);
                    intent.putExtra(TagStreamFragment.EXTRA_QUERY, getHashtagsString("was hash tag"));
                    startActivity(intent);
                }
            });
        } else {
            cntl.mTagDisplayView.setVisibility(View.GONE);
        }

        cntl.mRoomName = "Room";
        cntl.mRoomId = "Rm 202"; //cursor.getString(SessionsQuery.ROOM_ID);

        // Unregister around setting checked state to avoid triggering
        // listener since change isn't user generated.
        //            cntl.mStarred.setOnCheckedChangeListener(null);
        //            cntl.mStarred.setChecked(false);
        //            cntl.mStarred.setOnCheckedChangeListener(this);

        final String sessionAbstract = "I can work on the order these show up, it is just a sort on the query.  Note there is a title above in the header between the l/r icons.  Also a title down in the tab host header.  I will do one or the other not both.  Oh, and you have to swipe l/r once to get that top title to sync."; //cursor.getString(SessionsQuery.ABSTRACT);
        if (!TextUtils.isEmpty(sessionAbstract)) {
            UIUtils.setTextMaybeHtml(cntl.mAbstractView, sessionAbstract);
            cntl.mAbstractView.setVisibility(View.VISIBLE);
            cntl.mHasSummaryContent = true;
        } else {
            cntl.mAbstractView.setVisibility(View.GONE);
        }

        final String sessionRequirements = "How shall I lay out this screen??? Suggestions?"; //cursor.getString(SessionsQuery.REQUIREMENTS);
        if (!TextUtils.isEmpty(sessionRequirements)) {
            UIUtils.setTextMaybeHtml(cntl.mRequirementsView, sessionRequirements);
            cntl.mRequirementsBlockView.setVisibility(View.VISIBLE);
            cntl.mHasSummaryContent = true;
        } else {
            cntl.mRequirementsBlockView.setVisibility(View.GONE);
        }

        // Show empty message when all data is loaded, and nothing to show
        if (mSpeakersCursor && !cntl.mHasSummaryContent) {
            cntl.mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
        }

        AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sessions/" + cntl.mTitleString);

        //            updateLinksTab(cursor);
        //            updateNotesTab();
        updateWorkspaceHeader(cntl.index);

    } finally {
        //            cursor.close();
    }
}

From source file:com.abcvoipsip.ui.messages.MessageAdapter.java

private CharSequence formatMessage(String contact, String body, String contentType) {
    SpannableStringBuilder buf = new SpannableStringBuilder();
    if (!TextUtils.isEmpty(body)) {
        // Converts html to spannable if ContentType is "text/html".
        if (contentType != null && "text/html".equals(contentType)) {
            buf.append("\n");
            buf.append(Html.fromHtml(body));
        } else {//from w  w  w. j a v  a2s.  c o m
            SmileyParser parser = SmileyParser.getInstance();
            buf.append(parser.addSmileySpans(body));
        }
    }

    // We always show two lines because the optional icon bottoms are
    // aligned with the
    // bottom of the text field, assuming there are two lines for the
    // message and the sent time.
    buf.append("\n");
    int startOffset = buf.length();

    startOffset = buf.length();

    buf.setSpan(mTextSmallSpan, startOffset, buf.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return buf;
}

From source file:midian.baselib.widget.PagerSlidingTabStrip.java

private void addRightIcon(TextView tab, int i, boolean isUp) {
    String text = pager.getAdapter().getPageTitle(i).toString() + "    ";
    SpannableStringBuilder str = new SpannableStringBuilder(text + "[icon]");

    // ?Drawable?
    Drawable d = getResources().getDrawable(isUp ? R.drawable.icon_tap_up : R.drawable.icon_tap_down);
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    // ImageSpan//from  w ww. ja v  a2s .  com
    ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
    str.setSpan(span, text.length(), text.length() + "[icon]".length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    tab.setText(str);
}

From source file:com.juick.android.ThreadActivity.java

public void onReplySelected(final JuickMessage msg) {
    selectedReply = msg;/*w  w  w. j  av  a  2  s.  c om*/
    rid = msg.getRID();
    if (rid > 0) {
        SpannableStringBuilder ssb = new SpannableStringBuilder();
        String inreplyto = getResources().getString(R.string.In_reply_to_) + " ";
        ssb.append(inreplyto).append(msg.Text);
        ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, inreplyto.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvReplyTo.setText(ssb);
        setHeight(replyToContainer, ActionBar.LayoutParams.WRAP_CONTENT);
        showThread.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tf.showThread(msg, false);
            }
        });
    } else {
        setHeight(replyToContainer, 0);
    }
}

From source file:com.roamprocess1.roaming4world.ui.messages.ConversationsAdapter.java

private CharSequence formatMessage(Cursor cursor) {
    SpannableStringBuilder buf = new SpannableStringBuilder();
    String remoteContactFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    CallerInfo callerInfo = CallerInfo.getCallerInfoFromSipUri(mContext, remoteContactFull);

    System.out.println("remoteContactFull:" + remoteContactFull);

    if (callerInfo != null && callerInfo.contactExists) {
        buf.append(callerInfo.name);//  w  ww  . j  av a  2s .  c o  m
    } else {
        buf.append(SipUri.getDisplayedSimpleContact(remoteContactFull));
    }

    int counter = cursor.getInt(cursor.getColumnIndex("counter"));

    if (counter > 1) {
        buf.append(" (" + counter + ") ");
    }

    int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ));
    // Unread messages are shown in bold
    if (read == 0) {
        buf.setSpan(STYLE_BOLD, 0, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
    System.out.println("return:" + buf);
    return buf;
}

From source file:com.juick.android.JuickMessagesAdapter.java

private static void setSSBSpan(SpannableStringBuilder ssb, Object span, int start, int end, int flags) {
    if (end > ssb.length()) {
        end = ssb.length();/*w  ww.  j  ava2  s .co m*/
    }
    if (start > ssb.length())
        return;
    if (start >= end)
        return;
    ssb.setSpan(span, start, end, flags);
}