Example usage for android.text SpannableStringBuilder SpannableStringBuilder

List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder

Introduction

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

Prototype

public SpannableStringBuilder(CharSequence text) 

Source Link

Document

Create a new SpannableStringBuilder containing a copy of the specified text, including its spans if any.

Usage

From source file:io.github.marktony.espresso.mvp.companydetails.CompanyDetailFragment.java

@Override
public void setCompanyTel(String tel) {
    this.tel = tel;
    String companyTel = getString(R.string.phone_number) + "\n" + tel;
    Spannable spannable = new SpannableStringBuilder(companyTel);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, companyTel.length() - tel.length() - 1,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new URLSpan(tel), companyTel.length() - tel.length(), companyTel.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textViewTel.setText(spannable);/*from w w  w  .  j  av a 2  s  .  c  o  m*/
}

From source file:com.github.michalbednarski.intentslab.providerlab.proxy.LogViewerFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    setListAdapter(new CursorAdapter(getActivity(), data, false) {
        @Override/*from w w w . jav a 2s .c om*/
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            return ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                    .inflate(android.R.layout.simple_list_item_2, parent, false);
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            // First row: method and app name
            final String appName = getActivity().getPackageManager().getNameForUid(cursor.getInt(3));
            final String methodName = methodIdToName(cursor.getInt(1));
            ((TextView) view.findViewById(android.R.id.text1)).setText(methodName + "() by " + appName);

            // Second row: uri and exception
            final String uri = cursor.getString(2);
            String exception = cursor.getString(4);
            SpannableStringBuilder text2 = new SpannableStringBuilder(uri);
            if (exception != null) {
                text2.append("\n");
                final int start = text2.length();
                text2.append(exception);
                final int end = text2.length();
                text2.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                // TODO: result / empty result warning
            }
            ((TextView) view.findViewById(android.R.id.text2)).setText(text2);
        }
    });
}

From source file:com.vuze.android.remote.activity.LoginActivity.java

private void setupGuideText(TextView tvLoginGuide) {
    AndroidUtilsUI.linkify(tvLoginGuide);
    CharSequence text = tvLoginGuide.getText();

    SpannableStringBuilder ss = new SpannableStringBuilder(text);
    String string = text.toString();

    new SpanBubbles().setSpanBubbles(ss, string, "|", tvLoginGuide.getPaint(),
            AndroidUtilsUI.getStyleColor(this, R.attr.login_text_color),
            AndroidUtilsUI.getStyleColor(this, R.attr.login_textbubble_color),
            AndroidUtilsUI.getStyleColor(this, R.attr.login_text_color));

    int indexOf = string.indexOf("@@");
    if (indexOf >= 0) {
        int style = ImageSpan.ALIGN_BASELINE;
        int newHeight = tvLoginGuide.getBaseline();
        if (newHeight <= 0) {
            newHeight = tvLoginGuide.getLineHeight();
            style = ImageSpan.ALIGN_BOTTOM;
            if (newHeight <= 0) {
                newHeight = 20;//from   w ww  .ja va2 s.  com
            }
        }
        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.guide_icon);
        int oldWidth = drawable.getIntrinsicWidth();
        int oldHeight = drawable.getIntrinsicHeight();
        int newWidth = (oldHeight > 0) ? (oldWidth * newHeight) / oldHeight : newHeight;
        drawable.setBounds(0, 0, newWidth, newHeight);

        ImageSpan imageSpan = new ImageSpan(drawable, style);
        ss.setSpan(imageSpan, indexOf, indexOf + 2, 0);
    }

    tvLoginGuide.setText(ss);
}

From source file:com.softminds.matrixcalculator.base_activities.FillingMatrix.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean isDark = preferences.getBoolean("DARK_THEME_KEY", false);
    boolean SmartFit = preferences.getBoolean("SMART_FIT_KEY", false);

    if (isDark)//w w  w.  j a va2s.co m
        setTheme(R.style.AppThemeDark_NoActionBar);
    else
        setTheme(R.style.AppTheme_NoActionBar);
    super.onCreate(savedInstanceState);

    Bundle bundle = getIntent().getExtras();
    if (bundle == null) {
        Log.wtf("FillingMatrix", "How the heck, it got called ??");
        Toast.makeText(getApplication(), R.string.unexpected_error, Toast.LENGTH_SHORT).show();
        finish();
    } else {
        col = bundle.getInt("COL");
        row = bundle.getInt("ROW");
    }
    setContentView(R.layout.filler);
    adCard = findViewById(R.id.AddCardFiller);

    if (!((GlobalValues) getApplication()).DonationKeyFound()) {
        AdView adView = findViewById(R.id.adViewFiller);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.setAdListener(new AdLoadListener(adCard));
        adView.loadAd(adRequest);
        if (getResources()
                .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE)
            adCard.setVisibility(View.INVISIBLE);
        else
            adCard.setVisibility(View.VISIBLE);
    } else
        ((ViewGroup) adCard.getParent()).removeView(adCard);

    Toolbar toolbar = findViewById(R.id.toolbarFill);
    setSupportActionBar(toolbar);

    CardView cardView = findViewById(R.id.DynamicCard);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4");
    String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd");

    cardView.setCardElevation(Integer.parseInt(string));

    CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    GridLayout gridLayout = new GridLayout(getApplicationContext());
    gridLayout.setRowCount(row);
    gridLayout.setColumnCount(col);
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            EditText editText = new EditText(getApplication());
            editText.setBackgroundColor(Color.parseColor(string2));
            editText.setId(i * 10 + j);
            if (isDark)
                editText.setTextColor(ContextCompat.getColor(this, R.color.white));
            editText.setGravity(Gravity.CENTER);
            SpannableStringBuilder stringBuilder = new SpannableStringBuilder(
                    "a" + String.valueOf(i + 1) + String.valueOf(j + 1));
            stringBuilder.setSpan(new SubscriptSpan(), 1, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            stringBuilder.setSpan(new RelativeSizeSpan(0.75f), 1, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            editText.setHint(stringBuilder);
            if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("DECIMAL_USE", true)) {
                editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
            } else {
                editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                        | InputType.TYPE_NUMBER_FLAG_SIGNED);
            }
            editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(getLength()) });
            if (SmartFit) {
                editText.setWidth(ConvertTopx(CalculatedWidth(col)));
                editText.setTextSize(SizeReturner(row, col,
                        PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
                                .getBoolean("EXTRA_SMALL_FONT", false)));
            } else {
                editText.setWidth(ConvertTopx(62));
                editText.setTextSize(SizeReturner(3, 3,
                        PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
                                .getBoolean("EXTRA_SMALL_FONT", false)));
            }
            editText.setSingleLine();
            GridLayout.Spec Row = GridLayout.spec(i, 1);
            GridLayout.Spec Col = GridLayout.spec(j, 1);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col);
            params.leftMargin = params.topMargin = params.bottomMargin = params.rightMargin = getResources()
                    .getDimensionPixelOffset(R.dimen.border_width);
            gridLayout.addView(editText, params);
        }
    }
    gridLayout.setLayoutParams(params1);
    cardView.addView(gridLayout);
    MakeType((Type) (getIntent().getExtras().getSerializable("TYPE")));
    if (GetMaximum() < GetMinimum()) {
        final Snackbar snackbar;
        snackbar = Snackbar.make(findViewById(R.id.filling_matrix), R.string.Warning3,
                Snackbar.LENGTH_INDEFINITE);
        snackbar.show();
        snackbar.setAction(getString(R.string.action_settings), new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                snackbar.dismiss();
                Intent intent = new Intent(getApplicationContext(), SettingsTab.class);
                startActivity(intent);
                finish();
            }
        });
    }

}

From source file:com.yangtsaosoftware.pebblemessenger.activities.SetupFragment.java

private void run_tts_test() {
    SpannableStringBuilder ssb = new SpannableStringBuilder(textInfo.getText());
    ssb.append(_context.getString(R.string.setup_tts_test));
    ssb.append('\n');
    ssb.append(_context.getString(R.string.setup_tts_engine));
    textInfo.setText(ssb);/*from  ww  w.  j  a  va  2s  .com*/
    svMyview.fullScroll(View.FOCUS_DOWN);
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    getActivity().startActivityFromFragment(SetupFragment.this, checkIntent, 3);
}

From source file:com.popdeem.sdk.uikit.adapter.PDUIFeedRecyclerViewAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final PDFeed item = this.mItems.get(position);

    boolean isCheckin = item.getImageUrlString().contains("default");
    if (isCheckin) {
        holder.sharedImageView.setVisibility(View.GONE);
        holder.sharedImageView.setImageDrawable(null);
    } else {/*from  www  .  j  a  v a 2s. c om*/

        holder.sharedImageView.setVisibility(View.VISIBLE);

        Glide.with(context).load(item.getImageUrlString()).error(null).dontAnimate()
                .into(holder.sharedImageView);

    }

    if (item.getUserProfilePicUrlString().isEmpty()) {

        Glide.with(context).load(R.drawable.pduikit_default_user).dontAnimate().dontAnimate().fitCenter()
                .into(holder.profileImageView);
    } else {
        Glide.with(context).load(item.getUserProfilePicUrlString()).placeholder(R.drawable.pduikit_default_user)
                .error(R.drawable.pduikit_default_user).dontAnimate().fitCenter().into(holder.profileImageView);
    }

    //        Spannable actionText = getRedemptionText(holder.context, item.getUserFirstName(), item.getUserLastName(), item.getDescriptionString(), item.getBrandName(), isCheckin);
    holder.userNameTextView.setText(getNameForItem(item.getUserFirstName(), item.getUserLastName()));
    SpannableStringBuilder str = new SpannableStringBuilder(
            getNameForItem(item.getUserFirstName(), item.getUserLastName()) + " " + item.getCaption());
    str.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), 0,
            getNameForItem(item.getUserFirstName(), item.getUserLastName()).length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    holder.userCommentTextView.setText(str);

    holder.timeTextView.setText(item.getTimeAgo());
}

From source file:org.cnc.mombot.utils.ContactsEditText.java

public void setTextFromSpannedString(String spannedString) {
    setText(addPeopleToGroupChat(new SpannableStringBuilder(spannedString)));
}

From source file:io.github.marktony.espresso.mvp.companydetails.CompanyDetailFragment.java

@Override
public void setCompanyWebsite(String website) {
    this.website = website;
    String ws = getString(R.string.official_website) + "\n" + website;
    Spannable spannable = new SpannableStringBuilder(ws);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, ws.length() - website.length() - 1,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannable.setSpan(new URLSpan(website), ws.length() - website.length(), ws.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textViewWebsite.setText(spannable);/*  w w w  .  jav a 2s  .  co  m*/
}

From source file:org.mozilla.gecko.home.ReadingListPanel.java

private void updateUiFromCursor(Cursor c) {
    // We delay setting the empty view until the cursor is actually empty.
    // This avoids image flashing.
    if ((c == null || c.getCount() == 0) && mEmptyView == null) {
        final ViewStub emptyViewStub = (ViewStub) mTopView.findViewById(R.id.home_empty_view_stub);
        mEmptyView = emptyViewStub.inflate();

        final TextView emptyHint = (TextView) mEmptyView.findViewById(R.id.home_empty_hint);
        if (HardwareUtils.isLowMemoryPlatform()) {
            emptyHint.setVisibility(View.GONE);
        } else {//  w  w w . j  a v a2  s  .  c om
            String readingListHint = emptyHint.getText().toString();

            // Use an ImageSpan to include the reader icon in the "Tip".
            int imageSpanIndex = readingListHint.indexOf(MATCH_STRING);
            if (imageSpanIndex != -1) {
                final ImageSpan readingListIcon = new ImageSpan(getActivity(), R.drawable.reader_cropped,
                        ImageSpan.ALIGN_BOTTOM);
                final SpannableStringBuilder hintBuilder = new SpannableStringBuilder(readingListHint);

                // Add additional spacing.
                hintBuilder.insert(imageSpanIndex + MATCH_STRING.length(), " ");
                hintBuilder.insert(imageSpanIndex, " ");

                // Add icon.
                hintBuilder.setSpan(readingListIcon, imageSpanIndex + 1,
                        imageSpanIndex + MATCH_STRING.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

                emptyHint.setText(hintBuilder, TextView.BufferType.SPANNABLE);
            }
        }

        mList.setEmptyView(mEmptyView);
    }
}

From source file:org.kontalk.ui.view.TextContentView.java

private SpannableStringBuilder formatMessage(final Pattern highlight) {
    SpannableStringBuilder buf;//w  w w  .j  a v a  2s  .co m

    String textContent = mComponent.getContent();

    buf = new SpannableStringBuilder(textContent);

    if (highlight != null) {
        Matcher m = highlight.matcher(buf.toString());
        while (m.find())
            buf.setSpan(mHighlightColorSpan, m.start(), m.end(), 0);
    }

    return buf;
}