Example usage for android.text.style BulletSpan BulletSpan

List of usage examples for android.text.style BulletSpan BulletSpan

Introduction

In this page you can find the example usage for android.text.style BulletSpan BulletSpan.

Prototype

public BulletSpan(@NonNull Parcel src) 

Source Link

Document

Creates a BulletSpan from a parcel.

Usage

From source file:Main.java

/**
 * Returns a CharSequence containing a bulleted and properly indented list.
 *
 * @param leadingMargin/*from w  w  w .  j  a v a 2  s . c  o  m*/
 *            In pixels, the space between the left edge of the bullet and
 *            the left edge of the text.
 * @param lines
 *            An array of CharSequences. Each CharSequences will be a
 *            separate line/bullet-point.
 * @return
 */
public static CharSequence makeBulletList(int leadingMargin, CharSequence... lines) {
    SpannableStringBuilder sb = new SpannableStringBuilder();
    for (int i = 0; i < lines.length; i++) {
        CharSequence line = lines[i] + (i < lines.length - 1 ? "\n" : "");
        Spannable spannable = new SpannableString(line);
        spannable.setSpan(new BulletSpan(leadingMargin), 0, spannable.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        sb.append(spannable);
    }
    return sb;
}

From source file:Main.java

/**
 * Returns the bulleted list based on the given {@code lines}.
 * If one of lines starts with {@link BulletListUtil#BAD_FIRST_SYMBOLS}, then such symbol is
 * removed from there (sometimes bad lines are received from the Food2Work).
 * Also if line consists of the upper case words, then this line is used like a header and is
 * underlined./*ww  w  .  j  a  v a  2 s  . c om*/
 *
 * @param leadingMargin In pixels, the space between the left edge of the bullet and the left
 *                         edge of the text
 * @param lines List of strings. Each string will be a separate item in the bulleted list
 * @return The bulleted list based on the given {@code lines}
 */
public static CharSequence makeBulletList(List<String> lines, int leadingMargin) {
    List<Spanned> spanned = new ArrayList<>(lines.size());
    for (String line : lines) {
        if (!line.trim().isEmpty()) {
            Spanned spannedLine = Html.fromHtml(removeBadFirstCharacters(line.trim()));
            spanned.add(spannedLine);
        }
    }

    SpannableStringBuilder sb = new SpannableStringBuilder();
    for (int i = 0; i < spanned.size(); i++) {
        CharSequence line = spanned.get(i) + (i < spanned.size() - 1 ? "\n" : "");
        boolean underlineNeeded = isUpperCase(line);
        Spannable spannable = new SpannableString(line);
        if (underlineNeeded) {
            spannable.setSpan(new UnderlineSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        } else {
            spannable.setSpan(new BulletSpan(leadingMargin), 0, spannable.length(),
                    Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        }
        sb.append(spannable);
    }
    return sb;
}

From source file:org.eyeseetea.malariacare.network.CustomParser.java

@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
    if (tag.equalsIgnoreCase("ul")) {
        if (opening) {
            lists.push(tag);/*  w w  w  . j av a2 s. c om*/
        } else {
            lists.pop();
        }
    } else if (tag.equalsIgnoreCase("ol")) {
        if (opening) {
            lists.push(tag);
            olNextIndex.push(Integer.valueOf(1)).toString();//TODO: add support for lists starting other index than 1
        } else {
            lists.pop();
            olNextIndex.pop().toString();
        }
    } else if (tag.equalsIgnoreCase("li")) {
        if (opening) {
            if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                output.append("\n");
            }
            String parentList = lists.peek();
            if (parentList.equalsIgnoreCase("ol")) {
                start(output, new Ol());
                output.append(olNextIndex.peek().toString() + ". ");
                olNextIndex.push(Integer.valueOf(olNextIndex.pop().intValue() + 1));
            } else if (parentList.equalsIgnoreCase("ul")) {
                start(output, new Ul());
            }
        } else {
            if (lists.peek().equalsIgnoreCase("ul")) {
                if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                    output.append("\n");
                }
                // Nested BulletSpans increases distance between bullet and text, so we must prevent it.
                int bulletMargin = indent;
                if (lists.size() > 1) {
                    bulletMargin = indent - bullet.getLeadingMargin(true);
                    if (lists.size() > 2) {
                        // This get's more complicated when we add a LeadingMarginSpan into the same line:
                        // we have also counter it's effect to BulletSpan
                        bulletMargin -= (lists.size() - 2) * listItemIndent;
                    }
                }
                BulletSpan newBullet = new BulletSpan(bulletMargin);
                end(output, Ul.class, new LeadingMarginSpan.Standard(listItemIndent * (lists.size() - 1)),
                        newBullet);
            } else if (lists.peek().equalsIgnoreCase("ol")) {
                if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
                    output.append("\n");
                }
                int numberMargin = listItemIndent * (lists.size() - 1);
                if (lists.size() > 2) {
                    // Same as in ordered lists: counter the effect of nested Spans
                    numberMargin -= (lists.size() - 2) * listItemIndent;
                }
                end(output, Ol.class, new LeadingMarginSpan.Standard(numberMargin));
            }
        }
    } else {
        if (opening)
            Log.d("TagHandler", "Found an unsupported tag " + tag);
    }
}

From source file:com.android.settings.applications.ClearDefaultsPreference.java

public boolean updateUI(PreferenceViewHolder view) {
    boolean hasBindAppWidgetPermission = mAppWidgetManager
            .hasBindAppWidgetPermission(mAppEntry.info.packageName);

    TextView autoLaunchView = (TextView) view.findViewById(R.id.auto_launch);
    boolean autoLaunchEnabled = AppUtils.hasPreferredActivities(mPm, mPackageName)
            || isDefaultBrowser(mPackageName) || AppUtils.hasUsbDefaults(mUsbManager, mPackageName);
    if (!autoLaunchEnabled && !hasBindAppWidgetPermission) {
        resetLaunchDefaultsUi(autoLaunchView);
    } else {// w  w w  .  j  av a2s  .  c om
        boolean useBullets = hasBindAppWidgetPermission && autoLaunchEnabled;

        if (hasBindAppWidgetPermission) {
            autoLaunchView.setText(R.string.auto_launch_label_generic);
        } else {
            autoLaunchView.setText(R.string.auto_launch_label);
        }

        Context context = getContext();
        CharSequence text = null;
        int bulletIndent = context.getResources()
                .getDimensionPixelSize(R.dimen.installed_app_details_bullet_offset);
        if (autoLaunchEnabled) {
            CharSequence autoLaunchEnableText = context.getText(R.string.auto_launch_enable_text);
            SpannableString s = new SpannableString(autoLaunchEnableText);
            if (useBullets) {
                s.setSpan(new BulletSpan(bulletIndent), 0, autoLaunchEnableText.length(), 0);
            }
            text = (text == null) ? TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n");
        }
        if (hasBindAppWidgetPermission) {
            CharSequence alwaysAllowBindAppWidgetsText = context
                    .getText(R.string.always_allow_bind_appwidgets_text);
            SpannableString s = new SpannableString(alwaysAllowBindAppWidgetsText);
            if (useBullets) {
                s.setSpan(new BulletSpan(bulletIndent), 0, alwaysAllowBindAppWidgetsText.length(), 0);
            }
            text = (text == null) ? TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n");
        }
        autoLaunchView.setText(text);
        mActivitiesButton.setEnabled(true);
    }
    return true;
}

From source file:com.sahildave.snackbar.SnackBar.java

private CharSequence getBulletSpanMessage(String[] subMessageArray) {
    CharSequence subMessage = "";
    for (String subMessageItem : subMessageArray) {

        SpannableString spannableString = new SpannableString(subMessageItem + "\n");
        spannableString.setSpan(new BulletSpan(15), 0, subMessageItem.length(), 0);

        subMessage = TextUtils.concat(subMessage, spannableString);
    }/*from w w w.  j ava 2 s .  c o m*/
    return subMessage;
}