Example usage for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE

List of usage examples for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE

Introduction

In this page you can find the example usage for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE.

Prototype

int SPAN_EXCLUSIVE_EXCLUSIVE

To view the source code for android.text Spanned SPAN_EXCLUSIVE_EXCLUSIVE.

Click Source Link

Document

Spans of type SPAN_EXCLUSIVE_EXCLUSIVE do not expand to include text inserted at either their starting or ending point.

Usage

From source file:Main.java

public static void makeAboutSpannable(SpannableStringBuilder span, String str_link, String replace,
        final Runnable on_click) {
    Pattern pattern = Pattern.compile(str_link);
    Matcher matcher = pattern.matcher(span);
    ForegroundColorSpan color_theme = new ForegroundColorSpan(Color.parseColor("#53b7bb"));
    if (matcher.find()) {
        span.setSpan(new ClickableSpan() {
            @Override// ww  w  .j  a v  a 2s.c om
            public void onClick(View widget) {
                if (on_click != null)
                    on_click.run();
            }
        }, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        span.setSpan(color_theme, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (replace != null)
            span.replace(matcher.start(), matcher.end(), replace);
    }
}

From source file:Main.java

public static Spannable applyKerning(CharSequence src, float kerning, int start, int end) {
    if (src == null)
        return null;
    final int srcLength = src.length();
    if (srcLength < 2)
        return src instanceof Spannable ? (Spannable) src : new SpannableString(src);
    if (start < 0)
        start = 0;/*from   w w w .  ja  va2s. c om*/
    if (end > srcLength)
        end = srcLength;

    final String nonBreakingSpace = "\u00A0";
    final SpannableStringBuilder builder = src instanceof SpannableStringBuilder ? (SpannableStringBuilder) src
            : new SpannableStringBuilder(src);
    for (int i = src.length(); i >= 1; i--) {
        builder.insert(i, nonBreakingSpace);
        builder.setSpan(new ScaleXSpan(kerning), i, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return builder;
}

From source file:com.googlecode.eyesfree.brailleback.DisplaySpans.java

/**
 * Marks a region of {@code spanned} as having focus.
 */// ww  w. ja  v  a2  s  .  c o  m
public static void addFocus(Spannable spannable, int start, int end) {
    spannable.setSpan(new FocusSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

From source file:Main.java

/**
 * Given a snippet string with matching segments surrounded by curly
 * braces, turn those areas into bold spans, removing the curly braces.
 *///from   w  ww .  ja v a 2 s .c om
public static Spannable buildStyledSnippet(String snippet) {
    final SpannableStringBuilder builder = new SpannableStringBuilder(snippet);

    // Walk through string, inserting bold snippet spans
    int startIndex = -1, endIndex = -1, delta = 0;
    while ((startIndex = snippet.indexOf('{', endIndex)) != -1) {
        endIndex = snippet.indexOf('}', startIndex);

        // Remove braces from both sides
        builder.delete(startIndex - delta, startIndex - delta + 1);
        builder.delete(endIndex - delta - 1, endIndex - delta);

        // Insert bold style
        builder.setSpan(sBoldSpan, startIndex - delta, endIndex - delta - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        delta += 2;
    }

    return builder;
}

From source file:Main.java

public static void setClickable(final TextView textView) {
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    Spannable sp = (Spannable) textView.getText();
    ImageSpan[] images = sp.getSpans(0, textView.getText().length(), ImageSpan.class);

    for (ImageSpan span : images) {
        final String image_src = span.getSource();
        final int start = sp.getSpanStart(span);
        final int end = sp.getSpanEnd(span);

        ClickableSpan click_span = new ClickableSpan() {
            @Override//from   ww w  .j  a  va  2  s .  c  om
            public void onClick(View widget) {
                String[] strs = image_src.split("/");
                String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/LilyClient/"
                        + strs[strs.length - 2] + "-" + strs[strs.length - 1];

                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setType("image/*");
                intent.setDataAndType(Uri.fromFile(new File(filePath)), "image/*");
                textView.getContext().startActivity(intent);

            }
        };
        ClickableSpan[] click_spans = sp.getSpans(start, end, ClickableSpan.class);
        if (click_spans.length != 0) {
            for (ClickableSpan c_span : click_spans) {
                sp.removeSpan(c_span);
            }
        }
        sp.setSpan(click_span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}

From source file:com.googlecode.eyesfree.brailleback.DisplaySpans.java

/**
 * Marks a portion of {@code spannable} as containing text selection.  If
 * {@code start} and {@code end} are equal, then then added span marks a
 * cursor.//  w  ww  . ja  v  a  2  s.com
 */
public static void addSelection(Spannable spannable, int start, int end) {
    int flags;
    if (start == end) {
        flags = Spanned.SPAN_EXCLUSIVE_INCLUSIVE;
    } else {
        flags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
    }
    spannable.setSpan(new SelectionSpan(), start, end, flags);
}

From source file:Main.java

public static void setTitle(TextView titleTv, int titleColor, int titleTextSize, int messageColor,
        int messageTextSize, CharSequence title, CharSequence message) {
    titleTv.setMinHeight(titleTextSize * 3);

    if (!TextUtils.isEmpty(title) && TextUtils.isEmpty(message)) {
        titleTv.setTextColor(titleColor);
        titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
        titleTv.getPaint().setFakeBoldText(true);
        titleTv.setText(title);/*from w w w  .  j a va 2 s  .c o m*/
    } else if (TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        titleTv.setTextColor(messageColor);
        titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, messageTextSize);
        titleTv.setText(message);
    } else if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        SpannableString titleSs = new SpannableString(title + "\n" + message);
        titleSs.setSpan(new ForegroundColorSpan(titleColor), 0, title.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new AbsoluteSizeSpan(titleTextSize), 0, title.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        titleSs.setSpan(new ForegroundColorSpan(messageColor), title.length(), titleSs.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new AbsoluteSizeSpan(messageTextSize), title.length(), titleSs.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleTv.setText(titleSs);
        titleTv.setLineSpacing(0.0f, 1.2f);
    } else {
        titleTv.setVisibility(View.GONE);
    }
}

From source file:Main.java

/**
 * "Closes" the specified tags on a Spannable by updating the spans to be
 * endpoint-exclusive so that future text appended to the end will not take
 * on the same styling. Do not call this method directly.
 *//* ww  w.j  a  v  a 2s  . c  o  m*/
private static void closeTags(Spannable text, Object[] tags) {
    int len = text.length();
    for (Object tag : tags) {
        if (len > 0) {
            text.setSpan(tag, 0, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            text.removeSpan(tag);
        }
    }
}

From source file:Main.java

public static void showChangelog(final Context context, final String title, final String appname,
        final int resChanges, final int resNotes) {
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context);
    final String v0 = p.getString(PREFS_LAST_RUN, "");
    String v1 = null;//ww  w  .j  a  v  a2  s.c o  m
    try {
        v1 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "package not found: " + context.getPackageName(), e);
    }
    p.edit().putString(PREFS_LAST_RUN, v1).commit();
    if (v0.length() == 0) {
        Log.d(TAG, "first boot, skip changelog");
        // return;
    }
    if (v0.equals(v1)) {
        Log.d(TAG, "no changes");
        return;
    }

    String[] changes = context.getResources().getStringArray(resChanges);
    String[] notes = resNotes > 0 ? context.getResources().getStringArray(resNotes) : null;

    final SpannableStringBuilder sb = new SpannableStringBuilder();
    for (String s : notes) {
        SpannableString ss = new SpannableString(s + "\n");
        int j = s.indexOf(":");
        if (j > 0) {
            if (!TextUtils.isEmpty(s)) {
                ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        sb.append(ss);
        sb.append("\n");
    }
    if (notes != null && notes.length > 0) {
        sb.append("\n");
    }
    for (String s : changes) {
        s = appname + " " + s.replaceFirst(": ", ":\n* ").replaceAll(", ", "\n* ") + "\n";
        SpannableString ss = new SpannableString(s);
        int j = s.indexOf(":");
        if (j > 0) {
            ss.setSpan(new StyleSpan(Typeface.BOLD), 0, j, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        sb.append(ss);
        sb.append("\n");
    }
    sb.setSpan(new RelativeSizeSpan(0.75f), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    changes = null;
    notes = null;

    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(title);
    b.setMessage(sb);
    b.setCancelable(true);
    b.setPositiveButton(android.R.string.ok, null);
    b.show();
}

From source file:com.googlecode.eyesfree.brailleback.DisplaySpans.java

/**
 * Marks the whole of {@code spannable} as containing the content
 * coming from {@code node}.  A copy of {@code node} is stored.
 *
 * @see #recycleSpans/*from  w w  w  .  j  ava 2s  .  com*/
 */
public static void setAccessibilityNode(Spannable spannable, AccessibilityNodeInfoCompat node) {
    spannable.setSpan(AccessibilityNodeInfoCompat.obtain(node), 0, spannable.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}