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:com.guldencoin.androidwallet.nlg.ui.RequestCoinsFragment.java

private void updateView() {
    if (!isResumed())
        return;/*  w ww  . j  a  va2s  .  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 = "GULDENCOIN:-" + 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);

    // update bluetooth message
    final boolean serviceRunning = application.isServiceRunning(AcceptBluetoothService.class);
    bluetoothEnabledView.setVisibility(
            bluetoothAdapter != null && bluetoothAdapter.isEnabled() && serviceRunning ? View.VISIBLE
                    : View.GONE);

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

From source file:com.hippo.ehviewer.ui.scene.FavoritesScene.java

private void updateSearchBar() {
    Context context = getContext2();
    if (null == context || null == mUrlBuilder || null == mSearchBar || null == mFavCatArray) {
        return;//from   w w  w.  j a v a 2  s  . c o m
    }

    // Update title
    int favCat = mUrlBuilder.getFavCat();
    String favCatName;
    if (favCat >= 0 && favCat < 10) {
        favCatName = mFavCatArray[favCat];
    } else if (favCat == FavListUrlBuilder.FAV_CAT_LOCAL) {
        favCatName = getString(R.string.local_favorites);
    } else {
        favCatName = getString(R.string.cloud_favorites);
    }
    String keyword = mUrlBuilder.getKeyword();
    if (TextUtils.isEmpty(keyword)) {
        if (!ObjectUtils.equal(favCatName, mOldFavCat)) {
            mSearchBar.setTitle(getString(R.string.favorites_title, favCatName));
        }
    } else {
        if (!ObjectUtils.equal(favCatName, mOldFavCat) || !ObjectUtils.equal(keyword, mOldKeyword)) {
            mSearchBar.setTitle(getString(R.string.favorites_title_2, favCatName, keyword));
        }
    }

    // Update hint
    if (!ObjectUtils.equal(favCatName, mOldFavCat)) {
        Drawable searchImage = DrawableManager.getDrawable(context, R.drawable.v_magnify_x24);
        SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
        ssb.append(getString(R.string.favorites_search_bar_hint, favCatName));
        int textSize = (int) (mSearchBar.getEditTextTextSize() * 1.25);
        if (searchImage != null) {
            searchImage.setBounds(0, 0, textSize, textSize);
            ssb.setSpan(new ImageSpan(searchImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        mSearchBar.setEditTextHint(ssb);
    }

    mOldFavCat = favCatName;
    mOldKeyword = keyword;

    // Save recent fav cat
    Settings.putRecentFavCat(mUrlBuilder.getFavCat());
}

From source file:systems.soapbox.ombuds.client.ui.WalletTransactionsFragment.java

@Override
public void onLoadFinished(final Loader<List<Transaction>> loader, final List<Transaction> transactions) {
    final Direction direction = ((TransactionsLoader) loader).getDirection();

    adapter.replace(transactions);//from  www  .  java2 s .  c o  m

    if (transactions.isEmpty()) {
        viewGroup.setDisplayedChild(1);

        final SpannableStringBuilder emptyText = new SpannableStringBuilder("You have no Bitcoin.");
        emptyText.setSpan(new StyleSpan(Typeface.BOLD), 0, emptyText.length(),
                SpannableStringBuilder.SPAN_POINT_MARK);
        emptyText.append("\n\n").append(getString(R.string.profile_email_for_bitcoin));
        emptyView.setText(emptyText);
    } else {
        viewGroup.setDisplayedChild(2);
    }
}

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

public Emoji.XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    text.setText(Utilities.formatName(user.first_name, user.last_name));

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);/*  ww w  . j a  v  a2s .c  o m*/
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    Emoji.XImageSpan span = new Emoji.XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.id, span);
    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());
    return span;
}

From source file:org.hopestarter.wallet.ui.RequestCoinsFragment.java

private void updateView() {
    if (!isResumed())
        return;/*from   ww  w. j  ava2s. co  m*/

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

    // update qr-code
    final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size);
    final String qrContent;
    if (config.getQrPaymentRequestEnabled())
        qrContent = "BITCOIN:-" + Qr.encodeBinary(paymentRequest);
    else
        qrContent = bitcoinRequest;
    qrCodeBitmap = Qr.bitmap(qrContent, size);
    qrView.setImageBitmap(qrCodeBitmap);

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

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

    paymentRequestRef.set(paymentRequest);
}

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

private void updateView() {
    if (!isResumed())
        return;/*from   ww  w.j  a  v a 2s .  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 = "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);
}

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

private void updateView() {
    if (!isResumed())
        return;//from w  w  w  .ja v a2  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:com.blu3f1re.reddwallet.ui.RequestCoinsFragment.java

private void updateView() {
    if (!isResumed())
        return;//w  w  w  . ja  v  a 2s.  c  om

    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:cc.mintcoin.wallet.ui.RequestCoinsFragment.java

private void updateView() {
    if (!isResumed())
        return;/* w  ww  .  j a v  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 = "MINTCOIN:-" + 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.yahala.ui.GroupCreateActivity.java

public XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    String name = Utilities.formatName(user.first_name, user.last_name);
    if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
        name = PhoneFormat.getInstance().format("+" + user.phone);
    }//from www .j  a  v a  2  s. co  m
    text.setText(name + ", ");

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    XImageSpan span = new XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.jid, span);
    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());
    return span;
}