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.silentcircle.contacts.vcard.ManageVCardActivity.java

private Dialog getVCardFileSelectDialog(boolean multipleSelect) {
    final int size = mAllVCardFileList.size();
    final VCardSelectedListener listener = new VCardSelectedListener(multipleSelect);

    final AlertDialog.Builder builder = new AlertDialog.Builder(this)
            .setTitle(R.string.select_vcard_title_remove).setPositiveButton(android.R.string.ok, listener)
            .setOnCancelListener(mCancelListener).setNegativeButton(android.R.string.cancel, mCancelListener);

    CharSequence[] items = new CharSequence[size];
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (int i = 0; i < size; i++) {
        VCardFile vcardFile = mAllVCardFileList.get(i);
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
        stringBuilder.append(vcardFile.getName());
        stringBuilder.append('\n');
        int indexToBeSpanned = stringBuilder.length();
        // Smaller date text looks better, since each file name becomes easier to read.
        // The value set to RelativeSizeSpan is arbitrary. You can change it to any other
        // value (but the value bigger than 1.0f would not make nice appearance :)
        stringBuilder.append("(" + dateFormat.format(new Date(vcardFile.getLastModified())) + ")");
        stringBuilder.setSpan(new RelativeSizeSpan(0.7f), indexToBeSpanned, stringBuilder.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        items[i] = stringBuilder;/*from  w ww .j a  v  a 2 s  .  c  o m*/
    }
    if (multipleSelect) {
        builder.setMultiChoiceItems(items, (boolean[]) null, listener);
    } else {
        builder.setSingleChoiceItems(items, 0, listener);
    }
    return builder.create();
}

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

private void updateView() {
    if (!isResumed())
        return;/*from   w  ww .  j a v a  2  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 = CoinDefinition.coinURIScheme.toUpperCase() + ":-" + Qr.encodeBinary(paymentRequest);
    else
        qrContent = bitcoinRequest;
    qrCodeBitmap = Qr.bitmap(qrContent, size);
    qrView.setImageBitmap(qrCodeBitmap);

    // update nfc ndef message
    final boolean nfcSuccess = Nfc.publishMimeObject(nfcManager, activity,
            PaymentProtocol.MIMETYPE_PAYMENTREQUEST, paymentRequest, false);

    // 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();
    acceptBluetoothPaymentView.setNextFocusUpId(activeAmountViewId);
}

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

private void updateView() {
    if (!isResumed())
        return;/*from   www .j ava  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 = CoinDefinition.coinURIScheme.toUpperCase() + ":-" + Qr.encodeBinary(paymentRequest);
    else
        qrContent = bitcoinRequest;
    qrCodeBitmap = Qr.bitmap(qrContent, size);
    qrView.setImageBitmap(qrCodeBitmap);

    // update nfc ndef message
    final boolean nfcSuccess = Nfc.publishMimeObject(nfcManager, activity,
            PaymentProtocol.MIMETYPE_PAYMENTREQUEST, paymentRequest);

    // 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();
    acceptBluetoothPaymentView.setNextFocusUpId(activeAmountViewId);
}

From source file:hashengineering.digitalcoin.wallet.ui.RequestCoinsFragment.java

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

    final String request = determineRequestStr(true);

    // update qr code
    final int size = (int) (256 * getResources().getDisplayMetrics().density);
    qrCodeBitmap = Qr.bitmap(request, size);
    qrView.setImageBitmap(qrCodeBitmap);

    // update ndef message
    final boolean nfcSuccess = Nfc.publishUri(nfcManager, getActivity(), request);

    // 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.isEnabled() && serviceRunning ? View.VISIBLE : View.GONE);
}

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

private void updateView() {
    if (!isResumed())
        return;//from   w  w  w.ja va  2  s  .  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 = "DEFCOIN:-" + Qr.encodeBinary(paymentRequest);
    else
        qrContent = bitcoinRequest;
    qrCodeBitmap = Qr.bitmap(qrContent, size);
    qrView.setImageBitmap(qrCodeBitmap);

    // update nfc ndef message
    final boolean nfcSuccess = Nfc.publishMimeObject(nfcManager, activity,
            PaymentProtocol.MIMETYPE_PAYMENTREQUEST, paymentRequest, false);

    // 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();
    acceptBluetoothPaymentView.setNextFocusUpId(activeAmountViewId);
}

From source file:de.jdellay.wallet.ui.RequestCoinsFragment.java

private void updateView() {
    if (!isResumed())
        return;/*from  ww w .  ja v a  2s .  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 = "CCNCOIN:-" + Qr.encodeBinary(paymentRequest);
    else
        qrContent = bitcoinRequest;
    qrCodeBitmap = Qr.bitmap(qrContent, size);
    qrView.setImageBitmap(qrCodeBitmap);

    // update nfc ndef message
    final boolean nfcSuccess = Nfc.publishMimeObject(nfcManager, activity,
            PaymentProtocol.MIMETYPE_PAYMENTREQUEST, paymentRequest, false);

    // 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();
    acceptBluetoothPaymentView.setNextFocusUpId(activeAmountViewId);
}

From source file:org.chromium.chrome.browser.notifications.NotificationUIManager.java

/**
 * Creates the ticker text for a notification having |title| and |body|. The notification's
 * title will be printed in bold, followed by the text of the body.
 *
 * @param title Title of the notification.
 * @param body Textual contents of the notification.
 * @return A character sequence containing the ticker's text.
 */// w ww.j  a va2s.c o m
private CharSequence createTickerText(String title, String body) {
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();

    spannableStringBuilder.append(title);
    spannableStringBuilder.append("\n");
    spannableStringBuilder.append(body);

    // Mark the title of the notification as being bold.
    spannableStringBuilder.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, title.length(),
            Spannable.SPAN_INCLUSIVE_INCLUSIVE);

    return spannableStringBuilder;
}

From source file:app.abhijit.iter.MainActivity.java

private void setupGettingStartedHint() {
    TextView gettingStartedHint = (TextView) findViewById(R.id.hint_getting_started);
    int lineHeight = gettingStartedHint.getLineHeight();
    Drawable hamburgerIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_hamburger, null);
    hamburgerIcon.setBounds(0, 0, lineHeight, lineHeight);
    SpannableStringBuilder hintText = new SpannableStringBuilder();
    hintText.append(getResources().getString(R.string.hint_getting_started_1)).append(" ");
    hintText.setSpan(new ImageSpan(hamburgerIcon), hintText.length() - 1, hintText.length(), 0);
    hintText.append(getResources().getString(R.string.hint_getting_started_2));
    gettingStartedHint.setText(hintText);
}

From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java

private void updateEditorState(@Nonnull Context context, @Nonnull RemoteViews views, @Nonnull EditorState state,
        @Nonnull SimpleTheme theme) {// www . jav  a2  s .com
    final boolean unspan = App.getTheme().light != theme.light;

    final CharSequence text = state.text;
    final int selection = state.selection;
    if (selection < 0 || selection > text.length()) {
        views.setTextViewText(R.id.calculator_editor, unspan ? App.unspan(text) : text);
        return;
    }

    final SpannableStringBuilder result;
    // inject cursor
    if (unspan) {
        final CharSequence beforeCursor = text.subSequence(0, selection);
        final CharSequence afterCursor = text.subSequence(selection, text.length());

        result = new SpannableStringBuilder();
        result.append(App.unspan(beforeCursor));
        result.append(getCursorString(context));
        result.append(App.unspan(afterCursor));
    } else {
        result = new SpannableStringBuilder(text);
        result.insert(selection, getCursorString(context));
    }
    views.setTextViewText(R.id.calculator_editor, result);
}

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);
        }/*  w  ww .  j  a  v a  2 s  .c  om*/
        builder.append(tagString);
    }
    return builder;
}