Example usage for android.text SpannableStringBuilder append

List of usage examples for android.text SpannableStringBuilder append

Introduction

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

Prototype

public SpannableStringBuilder append(char text) 

Source Link

Usage

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);
    } else {// w  w  w  .j av  a2s. c o  m
        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.kncwallet.wallet.ui.HomeFragment.java

@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    viewBalance = view.findViewById(R.id.wallet_balance);
    viewBalance.setEnabled(false);/*w w  w  .j  a v a2 s. c o m*/

    viewBalanceBtc = (CurrencyTextView) view.findViewById(R.id.wallet_balance_btc);
    viewBalanceLocal = (CurrencyTextView) view.findViewById(R.id.wallet_balance_local);

    viewBalanceLocal.setPrecision(Constants.LOCAL_PRECISION, 0);
    viewBalanceLocal.setStrikeThru(Constants.TEST);

    viewBalanceBtc.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            HomeFragment.this.switchBalance();
        }
    });

    viewBalanceLocal.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            HomeFragment.this.switchBalance();
        }
    });

    viewProgress = (TextView) view.findViewById(R.id.wallet_balance_progress);

    TextView header = ((TextView) view.findViewById(R.id.header_text));

    bitcoinAddressLabel = (TextView) view.findViewById(R.id.bitcoin_address_label);
    header.setText(R.string.home_heading);

    //transaction list stuff

    final ViewPagerTabs pagerTabs = (ViewPagerTabs) view.findViewById(R.id.transactions_pager_tabs);
    pagerTabs.addTabLabels(R.string.wallet_transactions_fragment_tab_sent,
            R.string.wallet_transactions_fragment_tab_all, R.string.wallet_transactions_fragment_tab_received);

    final ViewPager subViewPager = (ViewPager) view.findViewById(R.id.transactions_pager);

    transactionsListViewPagerAdapter = new TransactionsListViewPagerAdapter(activity);
    subViewPager.setAdapter(transactionsListViewPagerAdapter);
    subViewPager.setOnPageChangeListener(pagerTabs);
    subViewPager.setPageMargin(0);
    subViewPager.setCurrentItem(1);
    subViewPager.setPageMarginDrawable(R.color.knc_background_darker);

    subViewPager.setOffscreenPageLimit(3);

    pagerTabs.forceRedrawAtPosition(1);

    bottomLayout = (LinearLayout) view.findViewById(R.id.home_bottom);
    bottomLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            ((WalletActivity) activity).handleExportKeys();
        }
    });

    final SpannableStringBuilder text = new SpannableStringBuilder();
    text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_backup)));
    text.append("\n");
    text.append(Html.fromHtml(getString(R.string.wallet_disclaimer_fragment_remind_safety)));

    TextView bottomBackupinfo = (TextView) bottomLayout.findViewById(R.id.home_bottom_backup_info);
    bottomBackupinfo.setText(text);
}

From source file:com.orangelabs.rcs.ri.messaging.chat.ChatCursorAdapter.java

/**
 * Format text with smiley/* w  w  w. j  a v a 2  s. c o m*/
 * 
 * @param txt Text
 * @return String
 */
private CharSequence formatMessageWithSmiley(String txt) {
    SpannableStringBuilder buf = new SpannableStringBuilder();
    if (!TextUtils.isEmpty(txt)) {
        SmileyParser smileyParser = new SmileyParser(txt, mSmileyResources);
        smileyParser.parse();
        buf.append(smileyParser.getSpannableString(mContext));
    }
    return buf;
}

From source file:com.pindroid.fragment.ViewBookmarkFragment.java

private void loadBookmark() {
    if (bookmark != null) {
        if (viewType == BookmarkViewType.VIEW) {

            Date d = new Date(bookmark.getTime());

            if (bookmark.getDescription() != null && !bookmark.getDescription().equals("null"))
                mTitle.setText(bookmark.getDescription());

            mUrl.setText(bookmark.getUrl());

            if (bookmark.getNotes() != null && !bookmark.getNotes().equals("null")
                    && !bookmark.getNotes().equals("")) {
                mNotes.setText(bookmark.getNotes());
                notesSection.setVisibility(View.VISIBLE);
            } else {
                notesSection.setVisibility(View.GONE);
            }//from   w ww  .ja v a  2 s .co  m

            mTime.setText(d.toString());

            mTags.setMovementMethod(LinkMovementMethod.getInstance());
            SpannableStringBuilder tagBuilder = new SpannableStringBuilder();

            if (bookmark.getTags().size() > 0) {
                for (Tag t : bookmark.getTags()) {
                    addTag(tagBuilder, t, tagOnClickListener);
                }

                mTags.setText(tagBuilder);

                tagsSection.setVisibility(View.VISIBLE);
            } else {
                tagsSection.setVisibility(View.GONE);
            }

            if (isMyself()) {
                Uri.Builder ub = new Uri.Builder();
                ub.scheme("content");
                ub.authority(BookmarkContentProvider.AUTHORITY);
                ub.appendPath("bookmark");
                ub.appendPath(Integer.toString(bookmark.getId()));

                getActivity().getContentResolver().unregisterContentObserver(observer);
                getActivity().getContentResolver().registerContentObserver(ub.build(), true, observer);

                mUsername.setText(bookmark.getAccount());

                if (bookmark.getToRead() && bookmark.getShared()) {
                    bookmarkIcon.setImageResource(R.drawable.ic_unread);
                } else if (!bookmark.getToRead() && bookmark.getShared()) {
                    bookmarkIcon.setImageResource(R.drawable.ic_bookmark);
                } else if (bookmark.getToRead() && !bookmark.getShared()) {
                    bookmarkIcon.setImageResource(R.drawable.ic_unread_private);
                } else if (!bookmark.getToRead() && !bookmark.getShared()) {
                    bookmarkIcon.setImageResource(R.drawable.ic_bookmark_private);
                }

            } else {
                if (bookmark.getAccount() != null) {
                    SpannableStringBuilder builder = new SpannableStringBuilder();
                    int start = builder.length();
                    builder.append(bookmark.getAccount());
                    int end = builder.length();

                    AccountSpan span = new AccountSpan(bookmark.getAccount());
                    span.setOnAccountClickListener(accountOnClickListener);

                    builder.setSpan(span, start, end, 0);

                    mUsername.setText(builder);
                }

                mUsername.setMovementMethod(LinkMovementMethod.getInstance());
            }
        } else if (viewType == BookmarkViewType.READ) {
            showInWebView(Constants.INSTAPAPER_URL + bookmark.getUrl());

            if (isMyself() && bookmark.getToRead() && SettingsHelper.getMarkAsRead(getActivity()))
                bookmarkSelectedListener.onBookmarkMark(bookmark);
        } else if (viewType == BookmarkViewType.WEB) {
            showInWebView(bookmark.getUrl());
        }
    } else {
        clearView();
    }
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyKeybaseFragment.java

@Override
public void onCryptoOperationSuccess(KeybaseVerificationResult result) {

    result.createNotify(getActivity()).show();

    String proofUrl = result.mProofUrl;
    String presenceUrl = result.mPresenceUrl;
    String presenceLabel = result.mPresenceLabel;

    Proof proof = mProof; // TODO: should ideally be contained in result

    String proofLabel;/*from  w  w  w .  j a v a  2s .  c o  m*/
    switch (proof.getType()) {
    case Proof.PROOF_TYPE_TWITTER:
        proofLabel = getString(R.string.keybase_twitter_proof);
        break;
    case Proof.PROOF_TYPE_DNS:
        proofLabel = getString(R.string.keybase_dns_proof);
        break;
    case Proof.PROOF_TYPE_WEB_SITE:
        proofLabel = getString(R.string.keybase_web_site_proof);
        break;
    case Proof.PROOF_TYPE_GITHUB:
        proofLabel = getString(R.string.keybase_github_proof);
        break;
    case Proof.PROOF_TYPE_REDDIT:
        proofLabel = getString(R.string.keybase_reddit_proof);
        break;
    default:
        proofLabel = getString(R.string.keybase_a_post);
        break;
    }

    SpannableStringBuilder ssb = new SpannableStringBuilder();

    ssb.append(getString(R.string.keybase_proof_succeeded));
    StyleSpan bold = new StyleSpan(Typeface.BOLD);
    ssb.setSpan(bold, 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append("\n\n");
    int length = ssb.length();
    ssb.append(proofLabel);
    if (proofUrl != null) {
        URLSpan postLink = new URLSpan(proofUrl);
        ssb.setSpan(postLink, length, length + proofLabel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (Proof.PROOF_TYPE_DNS == proof.getType()) {
        ssb.append(" ").append(getString(R.string.keybase_for_the_domain)).append(" ");
    } else {
        ssb.append(" ").append(getString(R.string.keybase_fetched_from)).append(" ");
    }
    length = ssb.length();
    URLSpan presenceLink = new URLSpan(presenceUrl);
    ssb.append(presenceLabel);
    ssb.setSpan(presenceLink, length, length + presenceLabel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    if (Proof.PROOF_TYPE_REDDIT == proof.getType()) {
        ssb.append(", ").append(getString(R.string.keybase_reddit_attribution)).append(" ")
                .append(proof.getHandle()).append("?, ");
    }
    ssb.append(" ").append(getString(R.string.keybase_contained_signature));

    displaySpannableResult(ssb);
}

From source file:com.android.screenspeak.formatter.EventSpeechRule.java

/**
 * Performs a recursive preorder traversal of a DOM tree and aggregating the
 * text content.//ww w  . j av a2s.c  o m
 *
 * @param node The currently explored node.
 * @param builder Builder that aggregates the text content.
 */
private static void getTextContentRecursive(Node node, SpannableStringBuilder builder) {
    NodeList children = node.getChildNodes();
    for (int i = 0, count = children.getLength(); i < count; i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.TEXT_NODE) {
            builder.append(child.getNodeValue());
        }
        getTextContentRecursive(child, builder);
    }
}

From source file:com.vuze.android.remote.spanbubbles.SpanTags.java

public void setTagBubbles(final SpannableStringBuilder ss, String text, String token) {
    if (ss.length() > 0) {
        // hack to ensure descent is always added by TextView
        ss.append("\u200B");
    }/* w  ww  .  j av a  2  s .co  m*/

    if (tvTags == null) {
        Log.e(TAG, "no tvTags");
        return;
    }

    TextPaint p = tvTags.getPaint();

    // Start and end refer to the points where the span will apply
    int tokenLen = token.length();
    int base = 0;

    if (showIcon && tagDrawables == null) {
        createDrawTagables();
    }

    while (true) {
        int start = text.indexOf(token, base);
        int end = text.indexOf(token, start + tokenLen);

        if (start < 0 || end < 0) {
            break;
        }

        base = end + tokenLen;

        final int fSpanStart = start;
        final int fSpanEnd = end + tokenLen;

        String id = text.substring(start + tokenLen, end);

        Map mapTag = null;
        try {
            long tagUID = Long.parseLong(id);
            mapTag = sessionInfo.getTag(tagUID);
        } catch (Throwable ignore) {
        }

        final String word = MapUtils.getMapString(mapTag, "name", "" + id);
        final Map fMapTag = mapTag;

        final DrawableTag imgDrawable = new DrawableTag(context, p, word, showIcon ? tagDrawables : null,
                mapTag, drawCount) {

            @Override
            public boolean isTagPressed() {
                if (!AndroidUtils.usesNavigationControl()) {
                    return false;
                }
                int selectionEnd = tvTags.getSelectionEnd();
                if (selectionEnd < 0) {
                    return false;
                }
                int selectionStart = tvTags.getSelectionStart();
                return selectionStart == fSpanStart && selectionEnd == fSpanEnd;
            }

            @Override
            public int getTagState() {
                if (listener == null) {
                    return TAG_STATE_SELECTED;
                }
                return listener.getTagState(fMapTag, word);
            }
        };

        if (countFontRatio > 0) {
            imgDrawable.setCountFontRatio(countFontRatio);
        }

        imgDrawable.setBounds(0, 0, imgDrawable.getIntrinsicWidth(), imgDrawable.getIntrinsicHeight());
        //         Log.d(TAG, "State=" + Arrays.toString(imgDrawable.getState()));

        if (listener != null && showIcon) {
            int tagState = listener.getTagState(mapTag, word);
            int[] state = makeState(tagState, mapTag == null, false);
            imgDrawable.setState(state);
        }

        ImageSpan imageSpan = new ImageSpan(imgDrawable, DynamicDrawableSpan.ALIGN_BASELINE) {

            @Override
            public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
                int size = super.getSize(paint, text, start, end, fm);
                int width = -1;
                if (tvTags.getLayoutParams().width == ViewGroup.LayoutParams.WRAP_CONTENT) {
                    if (tvTags.getParent() instanceof ViewGroup) {
                        width = ((ViewGroup) tvTags.getParent()).getWidth();
                    }
                } else {
                    width = tvTags.getWidth();
                }
                if (width <= 0) {
                    return size;
                }
                return Math.min(size, width);
            }
        };

        ss.setSpan(imageSpan, start, end + tokenLen, 0);

        if (listener != null) {
            ClickableSpan clickSpan = new ClickableSpan() {

                @Override
                public void onClick(View widget) {
                    listener.tagClicked(fMapTag, word);

                    if (AndroidUtils.hasTouchScreen()) {
                        Selection.removeSelection((Spannable) tvTags.getText());
                    }
                    widget.invalidate();
                }
            };

            ss.setSpan(clickSpan, start, end + tokenLen, 0);
        }

    }
}

From source file:com.blu3f1re.reddwallet.ui.RequestCoinsFragment.java

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

    final String bitcoinRequest = determineBitcoinRequestStr(true);
    final byte[] paymentRequest = determinePaymentRequest(true);

    // update qr-code
    final int size = (int) (256 * getResources().getDisplayMetrics().density);
    final String qrContent;
    if (config.getQrPaymentRequestEnabled())
        qrContent = "RDDCOIN:-" + Qr.encodeBinary(paymentRequest);
    else
        qrContent = bitcoinRequest;
    qrCodeBitmap = Qr.bitmap(qrContent, size);
    qrView.setImageBitmap(qrCodeBitmap);

    // update nfc ndef message
    final boolean nfcSuccess;
    if (config.getNfcPaymentRequestEnabled())
        nfcSuccess = Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_PAYMENTREQUEST,
                paymentRequest, false);
    else
        nfcSuccess = Nfc.publishUri(nfcManager, activity, bitcoinRequest);

    // update initiate request message
    final SpannableStringBuilder initiateText = new SpannableStringBuilder(
            getString(R.string.request_coins_fragment_initiate_request_qr));
    if (nfcSuccess)
        initiateText.append(' ').append(getString(R.string.request_coins_fragment_initiate_request_nfc));
    initiateRequestView.setText(initiateText);

    // focus linking
    final int activeAmountViewId = amountCalculatorLink.activeTextView().getId();
    addressView.setNextFocusUpId(activeAmountViewId);
}

From source file:com.dopecoin.wallet.ui.RequestCoinsFragment.java

private void updateView() {
    if (!isResumed())
        return;//from   ww  w .  j  a va  2 s  . co  m

    final String bitcoinRequest = determineBitcoinRequestStr(true);
    final byte[] paymentRequest = determinePaymentRequest(true);

    // update qr-code
    final int size = (int) (256 * getResources().getDisplayMetrics().density);
    final String qrContent;
    if (config.getQrPaymentRequestEnabled())
        qrContent = "DOPECOIN:-" + Qr.encodeBinary(paymentRequest);
    else
        qrContent = bitcoinRequest;
    qrCodeBitmap = Qr.bitmap(qrContent, size);
    qrView.setImageBitmap(qrCodeBitmap);

    // update nfc ndef message
    final boolean nfcSuccess;
    if (config.getNfcPaymentRequestEnabled())
        nfcSuccess = Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_PAYMENTREQUEST,
                paymentRequest, false);
    else
        nfcSuccess = Nfc.publishUri(nfcManager, activity, bitcoinRequest);

    // update initiate request message
    final SpannableStringBuilder initiateText = new SpannableStringBuilder(
            getString(R.string.request_coins_fragment_initiate_request_qr));
    if (nfcSuccess)
        initiateText.append(' ').append(getString(R.string.request_coins_fragment_initiate_request_nfc));
    initiateRequestView.setText(initiateText);

    // focus linking
    final int activeAmountViewId = amountCalculatorLink.activeTextView().getId();
    addressView.setNextFocusUpId(activeAmountViewId);
}

From source file:in.leafco.wallet.ui.RequestCoinsFragment.java

private void updateView() {
    if (!isResumed())
        return;//from   w  ww. j  a v  a 2 s  .com

    final String bitcoinRequest = determineBitcoinRequestStr(true);
    final byte[] paymentRequest = determinePaymentRequest(true);

    // update qr-code
    final int size = (int) (256 * getResources().getDisplayMetrics().density);
    final String qrContent;
    if (config.getQrPaymentRequestEnabled())
        qrContent = "LEAFCOIN:-" + Qr.encodeBinary(paymentRequest);
    else
        qrContent = bitcoinRequest;
    qrCodeBitmap = Qr.bitmap(qrContent, size);
    qrView.setImageBitmap(qrCodeBitmap);

    // update nfc ndef message
    final boolean nfcSuccess;
    if (config.getNfcPaymentRequestEnabled())
        nfcSuccess = Nfc.publishMimeObject(nfcManager, activity, Constants.MIMETYPE_PAYMENTREQUEST,
                paymentRequest, false);
    else
        nfcSuccess = Nfc.publishUri(nfcManager, activity, bitcoinRequest);

    // update initiate request message
    final SpannableStringBuilder initiateText = new SpannableStringBuilder(
            getString(R.string.request_coins_fragment_initiate_request_qr));
    if (nfcSuccess)
        initiateText.append(' ').append(getString(R.string.request_coins_fragment_initiate_request_nfc));
    initiateRequestView.setText(initiateText);

    // focus linking
    final int activeAmountViewId = amountCalculatorLink.activeTextView().getId();
    addressView.setNextFocusUpId(activeAmountViewId);
}