Skip to content

Commit

Permalink
Add image append
Browse files Browse the repository at this point in the history
  • Loading branch information
neworld committed Mar 22, 2018
1 parent 4ef4518 commit 7516424
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Spannable spannable = new Spanner()
.append("foreground\n", foreground(Color.RED))
.append("subscript\n", subscript())
.append("superscript\n", superscript())
.append(" \n", image(getResources().getDrawable(R.drawable.ic_android_16dp)))
.append(image(getResources().getDrawable(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()))
Expand Down Expand Up @@ -96,6 +96,7 @@ Text manipulation:
| Methods | Description |
| --------------- | --------------------------- |
| append(text, spans...) | appends text |
| append(image(...)) | appends image |
| replace(search, replace, spans...)| search and replace text |
| span(search, spans...) | search text and apply spans |
| insert(pos, text, spans...) | insert given text in given position |
Expand Down
7 changes: 7 additions & 0 deletions lib/src/main/java/lt/neworld/spanner/ImageSpan.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lt.neworld.spanner

/**
* @author Andrius Semionovas
* @since 2017-10-01
*/
class ImageSpan internal constructor(builder: SpanBuilder) : Span(builder)
2 changes: 1 addition & 1 deletion lib/src/main/java/lt/neworld/spanner/Span.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ package lt.neworld.spanner
* @author Andrius Semionovas
* @since 2017-10-01
*/
class Span internal constructor(private val builder: SpanBuilder) {
open class Span internal constructor(private val builder: SpanBuilder) {
internal fun buildSpan() = builder.build()
}
10 changes: 10 additions & 0 deletions lib/src/main/java/lt/neworld/spanner/Spanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ class Spanner(text: CharSequence?) : SpannableStringBuilder(text) {
return this
}

fun append(span: ImageSpan): Spanner {
val start = length

append(" ")

setSpans(start, length, span)

return this
}

fun insert(where: Int, text: CharSequence, vararg spans: Span): Spanner {
super.insert(where, text)

Expand Down
8 changes: 4 additions & 4 deletions lib/src/main/java/lt/neworld/spanner/Spans.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public Object build() {
/**
* @see android.text.style.ImageSpan#ImageSpan(Drawable)
*/
public static Span image(@NonNull final Drawable drawable) {
return new Span(new SpanBuilder() {
public static lt.neworld.spanner.ImageSpan image(@NonNull final Drawable drawable) {
return new lt.neworld.spanner.ImageSpan(new SpanBuilder() {
@Override
public Object build() {
return new ImageSpan(drawable);
Expand All @@ -204,8 +204,8 @@ public Object build() {
/**
* @see android.text.style.ImageSpan#ImageSpan(Drawable, int)
*/
public static Span image(@NonNull final Drawable drawable, final int verticalAlignment) {
return new Span(new SpanBuilder() {
public static lt.neworld.spanner.ImageSpan image(@NonNull final Drawable drawable, final int verticalAlignment) {
return new lt.neworld.spanner.ImageSpan(new SpanBuilder() {
@Override
public Object build() {
return new ImageSpan(drawable, verticalAlignment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void onClick(View view) {
.append("foreground\n", foreground(Color.RED))
.append("subscript\n", subscript())
.append("superscript\n", superscript())
.append(" \n", image(drawable))
.append(image(drawable)).append("\n")
.append("quite\n", quote())
.append("The quick brown fox jumps over the lazy dog\n", bold(), foreground(0xFF904f1c), Spans.quote())
.span("fox", foreground(Color.RED))
Expand Down

0 comments on commit 7516424

Please sign in to comment.