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() 

Source Link

Document

Create a new SpannableStringBuilder with empty contents

Usage

From source file:com.frostwire.android.gui.views.KeywordTagView.java

private void updateComponents() {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    sb = append(sb, keywordFilter.getKeyword(), keywordSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (count != -1) {
        sb = append(sb, "  (" + String.valueOf(count) + ")", countSpan, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }//  w  w  w  . j a  v a  2 s.co  m
    setText(sb, TextView.BufferType.NORMAL);

    if (dismissible) {
        setBackgroundResource(R.drawable.keyword_tag_background_active);
        int drawableResId = keywordFilter.isInclusive() ? R.drawable.keyword_tag_filter_add
                : R.drawable.keyword_tag_filter_minus;
        setCompoundDrawablesWithIntrinsicBounds(drawableResId, 0,
                R.drawable.keyword_tag_close_clear_cancel_full, 0);
        setTextColor(ContextCompat.getColor(getContext(), R.color.app_text_white));
    } else {
        setBackgroundResource(R.drawable.keyword_tag_background);
        setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        setTextColor(ContextCompat.getColor(getContext(), R.color.app_text_primary));
    }

    setOnClickListener(v -> onTouched());
    if (dismissible) {
        setOnTouchListener((v, event) -> {
            if (event.getAction() != MotionEvent.ACTION_UP) {
                return false;
            }
            TextView tv = (TextView) v;
            if (event.getX() >= tv.getWidth() - tv.getTotalPaddingRight()) {
                onDismissed();
                return true;
            }
            return false;
        });
    }
}

From source file:cc.mintcoin.wallet.ui.WalletDisclaimerFragment.java

private void updateView() {
    if (!isResumed())
        return;/*w w  w  .j  av  a2  s. co  m*/

    final boolean showBackup = config.remindBackup();
    final boolean showDisclaimer = config.getDisclaimerEnabled();

    final int progressResId;
    if (download == BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK)
        progressResId = 0;
    else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_STORAGE_PROBLEM) != 0)
        progressResId = R.string.blockchain_state_progress_problem_storage;
    else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_NETWORK_PROBLEM) != 0)
        progressResId = R.string.blockchain_state_progress_problem_network;
    else
        throw new IllegalStateException("download=" + download);

    final SpannableStringBuilder text = new SpannableStringBuilder();
    if (progressResId != 0)
        text.append(Html.fromHtml("<b>" + getString(progressResId) + "</b>"));
    if (progressResId != 0 && (showBackup || showDisclaimer))
        text.append('\n');
    if (showBackup)
        text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_backup)));
    if (showBackup && showDisclaimer)
        text.append('\n');
    if (showDisclaimer)
        text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_safety)));
    messageView.setText(text);

    final View view = getView();
    final ViewParent parent = view.getParent();
    final View fragment = parent instanceof FrameLayout ? (FrameLayout) parent : view;
    fragment.setVisibility(text.length() > 0 ? View.VISIBLE : View.GONE);
}

From source file:com.yutong.axxc.parents.view.common.ActivityUtils.java

/**
 * /*  ww w  .  j  av a 2  s. c om*/
 * @param str
 * @return
 */
public static SpannableStringBuilder str2Span(String str) {
    // str = qj2bj(str).replace(",", ", ");
    if (StringUtils.isBlank(str))
        return new SpannableStringBuilder();
    SpannableStringBuilder builder = new SpannableStringBuilder(str);
    // ??
    // char[] chars = str.toCharArray();
    //
    // for (char ch : chars) {
    // if ((ch >= '0' && ch <= '9') || ch == '.') {
    // SpannableString string = new SpannableString(StringUtil.parseStr(ch));
    // string.setSpan(new RelativeSizeSpan(1.0f), 0, 1, 0);
    // string.setSpan(new StyleSpan(Typeface.BOLD), 0, 1, 0);
    // builder.append(string);
    // continue;
    // }
    // builder.append(ch);
    // }
    return builder;
}

From source file:de.schildbach.litecoinwallet.ui.WalletDisclaimerFragment.java

private void updateView() {
    if (!isResumed())
        return;/* w  w  w .j  a  v a2 s. c  o  m*/

    final boolean showBackup = prefs.getBoolean(Constants.PREFS_KEY_REMIND_BACKUP, true);
    final boolean showSafety = prefs.getBoolean(Constants.PREFS_KEY_DISCLAIMER, true);

    final int progressResId;
    if (download == BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK)
        progressResId = 0;
    else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_STORAGE_PROBLEM) != 0)
        progressResId = R.string.blockchain_state_progress_problem_storage;
    else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_NETWORK_PROBLEM) != 0)
        progressResId = R.string.blockchain_state_progress_problem_network;
    else
        throw new IllegalStateException("download=" + download);

    final SpannableStringBuilder text = new SpannableStringBuilder();
    if (progressResId != 0)
        text.append(Html.fromHtml("<b>" + getString(progressResId) + "</b>"));
    if (progressResId != 0 && (showBackup || showSafety))
        text.append('\n');
    if (showBackup)
        text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_backup)));
    if (showBackup && showSafety)
        text.append('\n');
    if (showSafety)
        text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_safety)));
    messageView.setText(text);

    final View view = getView();
    final ViewParent parent = view.getParent();
    final View fragment = parent instanceof FrameLayout ? (FrameLayout) parent : view;
    fragment.setVisibility(text.length() > 0 ? View.VISIBLE : View.GONE);
}

From source file:com.simplifynowsoftware.flickrdemo.UserFragment.java

public void onClickShowUserInfo(final View v) {
    if (null != mUserData) {
        final Person user = mUserData.getPerson();

        // Assemble user data for display
        SpannableStringBuilder builder = new SpannableStringBuilder();

        StaticUtil.addPairToSpannable(builder, "Real Name", user.getRealname().getContent());
        StaticUtil.addPairToSpannable(builder, "User Name", user.getUsername().getContent());
        StaticUtil.addPairToSpannable(builder, "Profile URL", user.getProfileurl().getContent());
        StaticUtil.addPairToSpannable(builder, "Description", user.getDescription().getContent());

        StaticUtil.showOkAlert(getActivity(), new SpannableString(builder));
    }//from  w  w  w.ja v a  2 s  .c om
}

From source file:com.todoroo.astrid.tags.TagsControlSet.java

private CharSequence buildTagString() {
    List<TagData> sortedTagData = orderByName.sortedCopy(selectedTags);
    List<SpannableString> tagStrings = Lists.transform(sortedTagData, tagToString(Float.MAX_VALUE));
    SpannableStringBuilder builder = new SpannableStringBuilder();
    for (SpannableString tagString : tagStrings) {
        if (builder.length() > 0) {
            builder.append(SPACE);//from  w w w.  ja  v a 2  s.c om
        }
        builder.append(tagString);
    }
    return builder;
}

From source file:com.csipsimple.ui.messages.ConversationsAdapter.java

private CharSequence formatMessage(Cursor cursor) {
    SpannableStringBuilder buf = new SpannableStringBuilder();
    /*/*  www  . j a v  a 2  s  . c o m*/
    String remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM));
    if (remoteContact.equals("SELF")) {
    remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO));
    buf.append("To: ");
    }
    */
    String remoteContactFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    CallerInfo callerInfo = CallerInfo.getCallerInfoFromSipUri(mContext, remoteContactFull);
    if (callerInfo != null && callerInfo.contactExists) {
        buf.append(callerInfo.name);
        buf.append(" / ");
        buf.append(SipUri.getDisplayedSimpleContact(remoteContactFull));
    } 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);
    }
    return buf;
}

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

private CharSequence formatMessage(Cursor cursor) {
    SpannableStringBuilder buf = new SpannableStringBuilder();
    /*//w w w  . j av a  2s.c o  m
    String remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM));
    if (remoteContact.equals("SELF")) {
    remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO));
    buf.append("To: ");
    }
    */
    String remoteContactFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
    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);
    }
    return buf;
}

From source file:org.telegram.ui.IdenticonActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//from   w  w w. j ava  2 s. c om
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new LinearLayout(context);
    LinearLayout linearLayout = (LinearLayout) fragmentView;
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setWeightSum(100);
    linearLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    fragmentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    FrameLayout frameLayout = new FrameLayout(context);
    frameLayout.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20),
            AndroidUtilities.dp(20));
    linearLayout.addView(frameLayout,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));

    ImageView identiconView = new ImageView(context);
    identiconView.setScaleType(ImageView.ScaleType.FIT_XY);
    frameLayout.addView(identiconView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    frameLayout = new FrameLayout(context);
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.background));
    frameLayout.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), AndroidUtilities.dp(10));
    linearLayout.addView(frameLayout,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));

    TextView textView = new TextView(context);
    textView.setTextColor(ContextCompat.getColor(context, R.color.secondary_text));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLinksClickable(true);
    textView.setClickable(true);
    textView.setMovementMethod(new LinkMovementMethodMy());
    //textView.setAutoLinkMask(Linkify.WEB_URLS);
    textView.setLinkTextColor(Theme.MSG_LINK_TEXT_COLOR);
    textView.setGravity(Gravity.CENTER);
    frameLayout.addView(textView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(chat_id);
    if (encryptedChat != null) {
        IdenticonDrawable drawable = new IdenticonDrawable();
        identiconView.setImageDrawable(drawable);
        drawable.setEncryptedChat(encryptedChat);
        TLRPC.User user = MessagesController.getInstance().getUser(encryptedChat.user_id);
        SpannableStringBuilder hash = new SpannableStringBuilder();
        if (encryptedChat.key_hash.length > 16) {
            String hex = Utilities.bytesToHex(encryptedChat.key_hash);
            for (int a = 0; a < 32; a++) {
                if (a != 0) {
                    if (a % 8 == 0) {
                        hash.append('\n');
                    } else if (a % 4 == 0) {
                        hash.append(' ');
                    }
                }
                hash.append(hex.substring(a * 2, a * 2 + 2));
                hash.append(' ');
            }
            hash.append("\n\n");
        }
        hash.append(AndroidUtilities.replaceTags(LocaleController.formatString("EncryptionKeyDescription",
                R.string.EncryptionKeyDescription, user.first_name, user.first_name)));
        final String url = "telegram.org";
        int index = hash.toString().indexOf(url);
        if (index != -1) {
            hash.setSpan(
                    new URLSpanReplacement(
                            LocaleController.getString("EncryptionKeyLink", R.string.EncryptionKeyLink)),
                    index, index + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        textView.setText(hash);
    }

    return fragmentView;
}

From source file:com.newcell.calltext.ui.messages.ConversationsAdapter.java

private CharSequence formatMessage(Cursor cursor) {
    SpannableStringBuilder buf = new SpannableStringBuilder();
    /*//from w w  w.j av  a 2  s  .  c  om
    String remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM));
    Log.i(TAG, "remoteContact: '" + remoteContact + "'");
    if (remoteContact.equals("SELF")) {
    remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO));
    //            buf.append("To: ");
    }
    */

    String remoteContactFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));

    Log.i(TAG, "RemoteContactFull::" + remoteContactFull);
    /*
    String newRemoteContact = SipUri.getPhoneNumberFromApiSipString(remoteContactFull);
    if(newRemoteContact != "") {
       remoteContactFull = newRemoteContact;
       remoteContactFull = "\"" + remoteContactFull 
      + "\" <sip:" 
      + remoteContactFull 
      + "@" + SipManager.SERVER_DOMAIN + ">";
    Log.i(TAG, "New remoteContactFull::" + remoteContactFull);
    }
    */

    CallerInfo callerInfo = CallerInfo.getCallerInfoFromSipUri(mContext, remoteContactFull);
    //Log.i(TAG, "CallerInfo.number: '" + callerInfo.phoneNumber + "'");

    if (callerInfo != null && callerInfo.contactExists) {
        buf.append(callerInfo.name);
        /*
         * 6/19/2014 Removed the addition of the phone number to the title when the recipient is a contact
         */
        //buf.append(" / ");
        //buf.append(SipUri.getDisplayedSimpleContact(remoteContactFull));
    } 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);
    }
    return buf;
}