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:me.drakeet.library.ui.CrashListAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    String crash = mData[position];
    holder.log = crash;/*from ww  w . java  2s  .  co  m*/
    if (crash != null) {
        setSpaceState(holder, /*show = */ crash.startsWith("at "));

        if (crash.startsWith("Caused by")) {
            holder.title.setTypeface(null, Typeface.BOLD);
            holder.title.setTextColor(0xdeffffff);
        } else {
            holder.title.setTypeface(null, Typeface.NORMAL);
            holder.title.setTextColor(0xffef4545);
        }

        if (mPackageName != null && crash.contains(mPackageName)) {
            holder.itemView.setSelected(true);
            int indexOfC = crash.indexOf("(");
            if (indexOfC >= 0) {
                String atPackage = crash.substring(0, indexOfC);
                SpannableStringBuilder builder = new SpannableStringBuilder(atPackage)
                        .append(StringStyleUtils.format(holder.title.getContext(),
                                " " + crash.substring(indexOfC), R.style.LineTextAppearance));
                CharSequence title = builder.subSequence(0, builder.length());
                holder.title.setText(title);
            } else {
                holder.title.setText(crash);
            }
        } else {
            holder.itemView.setSelected(false);
            holder.title.setText(crash);
        }
    }
}

From source file:com.supermario.kanjilookandlearn.view.ScreenSlidePageFragment.java

private void initView() {
    initId();//from  w  ww. j  a v  a  2  s.  c om

    rootLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onCardClick(v);
        }
    });
    imageView.setImageDrawable(Utils.getDrawableFromAssets(getActivity(), kanjiItem.image));
    kanjiFaceTextView.setText(kanjiItem.kanji);

    // a SpannableStringBuilder containing text to display
    SpannableStringBuilder sb = new SpannableStringBuilder(kanjiItem.remember);

    // create a bold StyleSpan to be used on the SpannableStringBuilder
    StyleSpan b = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text bold

    int index = kanjiItem.remember.indexOf(kanjiItem.meanVietnamese);
    if (index >= 0) {
        // set only the name part of the SpannableStringBuilder to be bold --> 16, 16 + name.length()
        sb.setSpan(b, index, index + kanjiItem.meanVietnamese.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    }

    kunyomiTextView.setText(kanjiItem.kunyomi);
    onyomiTextView.setText(kanjiItem.onyomi);

    rememberTextView.setText(sb);

    //        try {
    //            strokeWebView.loadDataWithBaseURL(null,Utils.getStringFromInputStream(Utils.getInputStreamFromAssets(getActivity(), "04e00")), "text/html", "UTF-8", null);
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }

    if (kanjiItem.favorite == 1) {
        favoriteImageView.setImageResource(R.drawable.icon_favorite_active);
    } else {
        favoriteImageView.setImageResource(R.drawable.icon_favorite_inactive);
    }

    favoriteImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (kanjiItem.favorite == 0) {
                kanjiItem.favorite = 1;
                favoriteImageView.setImageResource(R.drawable.icon_favorite_active);
            } else {
                kanjiItem.favorite = 0;
                favoriteImageView.setImageResource(R.drawable.icon_favorite_inactive);
            }
            KanjiProvider.updateFavorite(getActivity(), kanjiItem);
        }
    });
}

From source file:de.vanita5.twittnuker.activity.support.ThemedFragmentActivity.java

@Override
protected void onTitleChanged(CharSequence title, int color) {
    final SpannableStringBuilder builder = new SpannableStringBuilder(title);
    final int themeResId = getCurrentThemeResourceId();
    final int themeColor = getThemeColor(), contrastColor = ColorUtils.getContrastYIQ(themeColor, 192);
    if (!ThemeUtils.isDarkTheme(themeResId)) {
        builder.setSpan(new ForegroundColorSpan(contrastColor), 0, builder.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }/*from  www  .  j  av a 2  s.com*/
    super.onTitleChanged(title, color);
}

From source file:org.telegram.ui.Cells.AboutLinkCell.java

public void setTextAndIcon(String text, int resId) {
    if (text == null || text.length() == 0) {
        setVisibility(GONE);// w w w  .j  a  va 2 s.c om
        return;
    }
    if (text != null && oldText != null && text.equals(oldText)) {
        return;
    }
    oldText = text;
    stringBuilder = new SpannableStringBuilder(oldText);
    MessageObject.addLinks(stringBuilder, false);
    Emoji.replaceEmoji(stringBuilder, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
    requestLayout();
    if (resId == 0) {
        imageView.setImageDrawable(null);
    } else {
        imageView.setImageResource(resId);
        imageView.getDrawable().setTint(ContextCompat.getColor(getContext(), R.color.secondary_text));
    }
}

From source file:com.vuze.android.remote.adapter.SideFilterAdapter.java

@Override
public void onBindFlexibleViewHolder(SideFilterViewHolder holder, int position) {
    SideFilterInfo item = getItem(position);
    if (item.letters.equals(TorrentListFragment.LETTERS_BS)) {
        ImageSpan imageSpan = new ImageSpan(context, R.drawable.ic_backspace_white_24dp,
                DynamicDrawableSpan.ALIGN_BOTTOM);
        SpannableStringBuilder ss = new SpannableStringBuilder(",");
        ss.setSpan(imageSpan, 0, 1, 0);//from   w  w w .ja  v a2 s  . c  o m
        holder.tvText.setText(ss);
    } else {
        holder.tvText.setText(item.letters);

        int resID = item.letters.length() > 1 ? android.R.style.TextAppearance_Small
                : android.R.style.TextAppearance_Large;
        holder.tvText.setTextAppearance(context, resID);
        holder.tvText.setTextColor(ContextCompat.getColor(context, R.color.login_text_color));
    }
    holder.tvCount.setText(item.count > 0 ? String.valueOf(item.count) : "");
}

From source file:org.openlmis.core.view.viewmodel.InventoryViewModel.java

public SpannableStringBuilder getStyleType() {
    if (type != null) {
        return new SpannableStringBuilder(type);
    } else {/*  w  w w  .j  a v a2  s  .  c  o m*/
        return new SpannableStringBuilder("Other"); //arbitrary default type in case server product form is null caused by human error
    }
}

From source file:com.avapira.bobroreader.hanabira.HanabiraParser.java

public HanabiraParser(HanabiraPost post) {
    Context context = Hanabira.getFlower();
    if (!contextInitCompleted) {
        bulletMarginPerLevel = Utils.convertDpToPx(context.getApplicationContext(), 12);
        spoilerHiddenColor = context.getColor(R.color.dobro_dark);
        spoilerShownColor = context.getColor(R.color.dobro_primary_text);
        refLinkColor = context.getColor(R.color.dobro_ref_text);
        quoteColor = context.getColor(R.color.dobro_quote);
        showSpoilers = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_spoilers",
                false);//from ww  w .  j ava 2s. co  m
        contextInitCompleted = true;
    }
    this.post = post;
    builder = new SpannableStringBuilder(replaceInternalLinkWithReference(post.getMessage()));
    Linkify.addLinks(builder, Linkify.WEB_URLS);
}

From source file:com.hackensack.umc.activity.ViewProfileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_profile);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    sharedPreferences = getSharedPreferences(Constant.SHAREPREF_TAG, MODE_PRIVATE);
    insuranceInfoTv = (TextView) findViewById(R.id.prof_insurance_tv);
    if (Util.isUserLogin(this) && Util.isPatientIdValid(this)) {

        try {//from   w  w w.  j  a  v  a 2 s .co  m
            mPatient = new LoginUserData(new JSONObject(Util.getPatientJSON(this)));
            ((TextView) findViewById(R.id.profile_fname)).setText(mPatient.getFirstName());
            ((TextView) findViewById(R.id.prof_lname)).setText(mPatient.getLastName());
            ((TextView) findViewById(R.id.prof_license)).setText(
                    TextUtils.isEmpty(mPatient.getDrivingLicense()) ? "-" : mPatient.getDrivingLicense());
            DateFormat formatterDate = new SimpleDateFormat("MM-dd-yyyy");

            Date d = null;
            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
                d = sdf.parse(mPatient.getBirthDate());
            } catch (Exception e) {
                Log.e("Date", " " + e);
            }

            //Bug is there : Null Pointer : Appointment Date
            ((TextView) findViewById(R.id.prof_date)).setText(formatterDate.format(d.getTime()));
            ((TextView) findViewById(R.id.prof_gender_tv)).setText(mPatient.getGender());
            //Code for getting and displaying phone numbers
            ArrayList<Telecom> telecom = mPatient.getTelephone();
            Log.v("Telecom", telecom.toString());
            String phonestr = null;
            for (int i = 0; i < telecom.size(); i++) {
                if (((Telecom) telecom.get(i)).getSystem().equalsIgnoreCase(Telecom.TELECOM_EMAIL)) {
                    ((TextView) findViewById(R.id.prof_email)).setText(((Telecom) telecom.get(i)).getValue());
                } else if (((Telecom) telecom.get(i)).getSystem().equalsIgnoreCase(Telecom.TELECOM_PHONE)) {
                    phonestr = telecom.get(i).getValue();
                    final Editable doctorPhoneNum = new SpannableStringBuilder(phonestr);
                    PhoneNumberUtils.formatNumber(doctorPhoneNum,
                            PhoneNumberUtils.getFormatTypeForLocale(Locale.US));
                    if (((Telecom) telecom.get(i)).getUse().equalsIgnoreCase(Telecom.TELECOM_MOBILE_PHONE)) {
                        findViewById(R.id.mobile_ll).setVisibility(View.VISIBLE);
                        ((TextView) findViewById(R.id.prof_mob_num)).setText(doctorPhoneNum);

                    } else if (((Telecom) telecom.get(i)).getUse()
                            .equalsIgnoreCase(Telecom.TELECOM_HOME_PHONE)) {
                        findViewById(R.id.home_ll).setVisibility(View.VISIBLE);
                        ((TextView) findViewById(R.id.prof_home_num)).setText(doctorPhoneNum);

                    } else if (((Telecom) telecom.get(i)).getUse()
                            .equalsIgnoreCase(Telecom.TELECOM_WORK_PHONE)) {
                        findViewById(R.id.work_ll).setVisibility(View.VISIBLE);
                        ((TextView) findViewById(R.id.prof_work_num)).setText(doctorPhoneNum);
                    }
                }
            }
            //Code to get and display address
            if (mPatient.getAddress() != null && mPatient.getAddress().size() > 0) {
                Address address = ((ArrayList<Address>) mPatient.getAddress()).get(0);
                ((TextView) findViewById(R.id.prof_addr_tv)).setText(address.getStreet1() + ","
                        + (TextUtils.isEmpty(address.getStreet2()) ? "" : address.getStreet2() + ",")
                        + address.getCity() + "," + address.getState() + "," + address.getZip() + ","
                        + address.getCountry());
            }

        } catch (Exception e) {
            Log.e("isUserLogin", "", e);

        }
        //Code to get and display insurance info

        new GetInsuranceInfo().execute(mPatient.getMRNId());
    }

    /* mProgressDialog = new ProgressDialog(this);
     mProgressDialog.setCancelable(false);*/
}

From source file:com.android.mail.browse.SubjectAndFolderView.java

public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) {
    mVisibleFolders = true;/*  w w w  .jav  a 2 s. c om*/
    final BidiFormatter bidiFormatter = getBidiFormatter();
    final String wrappedSubject = mSubject == null ? "" : bidiFormatter.unicodeWrap(mSubject);
    final SpannableStringBuilder sb = new SpannableStringBuilder(wrappedSubject);
    sb.append('\u0020');
    final Settings settings = account.settings;
    final int start = sb.length();
    if (settings.importanceMarkersEnabled && conv.isImportant()) {
        sb.append(".\u0020");
        sb.setSpan(new ReplacementSpan() {
            @Override
            public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
                return mImportanceMarkerDrawable.getIntrinsicWidth();
            }

            @Override
            public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top,
                    int baseline, int bottom, Paint paint) {
                canvas.save();
                final int transY = baseline + mChipVerticalOffset
                        - mImportanceMarkerDrawable.getIntrinsicHeight();
                canvas.translate(x, transY);
                mImportanceMarkerDrawable.draw(canvas);
                canvas.restore();
            }
        }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }

    mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */);
    mFolderDisplayer.constructFolderChips(sb);

    final int end = sb.length();
    sb.setSpan(new ChangeLabelsSpan(callbacks), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    setText(sb);
    setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.pocketsoap.admin.UserDetailFragment.java

private void bindUi() {
    // header section
    setText(R.id.detail_name, user.Name);
    setText(R.id.detail_username, user.Username);
    setText(R.id.detail_title, user.Title);

    // contact section
    setText(R.id.contact_email, user.Email);
    setText(R.id.contact_phone, user.Phone);
    setText(R.id.contact_mobile, user.MobilePhone);

    // no auto link for SMS, so we need to build our own URLSpan for it.
    if (user.MobilePhone != null && user.MobilePhone.length() > 0) {
        SpannableStringBuilder b = new SpannableStringBuilder(user.MobilePhone);
        b.setSpan(new URLSpan("smsto:" + user.MobilePhone), 0, user.MobilePhone.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setText(R.id.contact_mobile_text, b).setMovementMethod(LinkMovementMethod.getInstance());
    } else {// w w w . j  ava2  s .c  o  m
        setText(R.id.contact_mobile_text, "");
    }

    //action section
    isActive.setChecked(user.IsActive);
    isActive.setOnClickListener(new ToggleActive());

    // user photo
    // the default person image is https://blah/.../005/T but we don't want to bother fetching that, we'll just use our local default instead.
    if (user.SmallPhotoUrl != null && user.SmallPhotoUrl.length() > 0
            && !user.SmallPhotoUrl.endsWith("/005/T")) {
        PhotoLoaderTask photoLoader = new PhotoLoaderTask(getActivityHelper());
        photoLoader.execute(user.SmallPhotoUrl);
    } else {
        this.userPhoto.setImageResource(R.drawable.ic_contact_picture);
    }
}