MCPcopy Index your code
hub / github.com/neworld/spanner

github.com/neworld/spanner @1.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.2.0 ↗ · + Follow
96 symbols 214 edges 19 files 36 documented · 38% 22 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Android Arsenal Build Status Javadoc

This lib provides simple and fluent API for creating Android Spannable. Features: - Simple and fluent API - Helpers to create spans - Small method footprint (<200 methods, 29kb AAR package)

This library focuses on building spannable. If you prefer put full text first and then apply spans, take a look at another awesome library

Examples:

Spannable spannable = new Spanner()
        .append("Original text\n\n")
        .append("Big and blurry\n", Spans.sizePX(100))
        .span("blurry", blur(5.0f, BlurMaskFilter.Blur.SOLID))
        .append("big in DP\n", sizeDP(30))
        .append("50% of original size\n", scaleSize(0.5f))
        .append("bold\n", bold())
        .append("italic\n", italic())
        .append("bold and italic\n", boldItalic())
        .append("custom typeface\n", font("sans-serif-black"))
        .append("strike through\n", strikeThrough())
        .append("underline\n", underline())
        .append("background\n", background(Color.YELLOW))
        .append("foreground\n", foreground(Color.RED))
        .append("subscript\n", subscript())
        .append("superscript\n", superscript())
        .append(image(context, R.drawable.ic_android_16dp)).append("\n")
        .append("quite\n", quote())
        .append("The quick brown fox jumps over the lazy dog\n", bold(), foreground(0xFF904f1c), Spans.quote())
        .append("Custom\n", custom(new CustomSpan()))
        .append("Click here\n", click(onClickListener))
        .append("http://www.android.com\n", url("http://www.android.com"))
        ;

It looks like:

preview

You can manipulate text in many more ways:

Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog")
        .span("fox", foreground(Color.RED)) // search and span by given text
        .replace("dog", "cat", strikeThrough()) // any number of spans
        .insert(5, "foo", bold(), italic()) // any number of spans
        .append("bar", underline()); // any number of spans

If you need custom span, you need span builder:

//java 7
Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog")
        .span("fox", custom(new SpanBuilder() {
                 @Override
                 public Object build() {
                     return new StyleSpan(Typeface.ITALIC);
                 }
             });

//java 8
Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog")
        .span("fox", custom(() -> new StyleSpan(Typeface.ITALIC));

//kotlin
val spannable = Spanner("The quick brown fox jumps over the lazy dog")
        .span("fox", custom { StyleSpan(Typeface.ITALIC) })

Reference

Spans:

sizePX(int) background(int color) center()
sizeDP(int) foreground(int color) alignmentOpposite()
sizeSP(int) subscript() alignmentNormal()
scaleSize(float) superscript() bullet(...)
bold() image(...) imageMargin(...)
italic() click(listener) leadingMargin(...)
boldItalic() url(url) edit(...)
font(String) custom(spanBuilder) emboss(...)
strikeThrough() quote() blur(...)
underline() appearance(...) locale(...)
tabStop(where) suggestion(...) lineBackground(color)
lineHeight(height)

Text manipulation:

Methods Description
append(text, spans...) appends text
append(image(...)) appends image
replace(search, replace, spans...) search and replace text
span(search, ignoreCase = false, spans...) search text and apply spans
insert(pos, text, spans...) insert given text in given position

How to use

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

    dependencies {
        implementation 'lt.neworld:spanner:1.1.0'
    }

License

Copyright 2017 Andrius Semionovas

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Extension points exported contracts — how you extend this code

SpanBuilder (Interface)
(no doc) [14 implementers]
lib/src/main/java/lt/neworld/spanner/SpanBuilder.java

Core symbols most depended-on inside this repo

append
called by 26
lib/src/main/java/lt/neworld/spanner/Spanner.kt
span
called by 12
lib/src/main/java/lt/neworld/spanner/Spanner.kt
foreground
called by 4
lib/src/main/java/lt/neworld/spanner/Spans.java
bold
called by 2
lib/src/main/java/lt/neworld/spanner/Spans.java
background
called by 2
lib/src/main/java/lt/neworld/spanner/Spans.java
image
called by 2
lib/src/main/java/lt/neworld/spanner/Spans.java
quote
called by 2
lib/src/main/java/lt/neworld/spanner/Spans.java
buildSpan
called by 1
lib/src/main/java/lt/neworld/spanner/Span.kt

Shape

Method 75
Class 20
Interface 1

Languages

Kotlin51%
Java49%

Modules by API surface

lib/src/main/java/lt/neworld/spanner/Spans.java38 symbols
lib/src/test/java/lt/neworld/spanner/SpannerTest.kt15 symbols
lib/src/main/java/lt/neworld/spanner/Spanner.kt7 symbols
sample/src/main/java/lt/neworld/spanner/sample/SampleJavaActivity.java5 symbols
lib/src/main/java/lt/neworld/spanner/ClickSpanBuilder.kt4 symbols
lib/src/main/java/lt/neworld/spanner/StyleSpanBuilder.kt2 symbols
lib/src/main/java/lt/neworld/spanner/SpanBuilder.java2 symbols
lib/src/main/java/lt/neworld/spanner/Span.kt2 symbols
lib/src/main/java/lt/neworld/spanner/QuoteSpanBuilder.kt2 symbols
lib/src/main/java/lt/neworld/spanner/LineHeightSpanBuilder.kt2 symbols
lib/src/main/java/lt/neworld/spanner/LineBackgroundSpanBuilder.kt2 symbols
lib/src/main/java/lt/neworld/spanner/LeadingMarginSpanBuilder.kt2 symbols

For agents

$ claude mcp add spanner \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact