From 3f697d021db2fcdf9b072ee64eeb7995f50e1969 Mon Sep 17 00:00:00 2001 From: Andrius Semionovas Date: Tue, 10 Oct 2017 21:32:12 +0300 Subject: [PATCH] Release 0.3 --- CHANGELOG.md | 5 ++ README.md | 53 ++++++++++++++----- sample/build.gradle | 6 ++- .../spanner/sample/SampleJavaActivity.java | 3 +- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc952d..91e44cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### v0.3 + +- Add missing spans +- Add link to docs + ### v0.2 - New span support: `click`, `url`, `custom` diff --git a/README.md b/README.md index 4c349a0..22baa90 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ [![](https://jitpack.io/v/neworld/spanner.svg)](https://jitpack.io/#neworld/spanner) +[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Spanner-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/6271) This lib provides simple and fluent API for creating [Android Spannable](https://developer.android.com/reference/android/text/Spannable.html). Features: - Simple and fluent API - Helpers to create spans -- Small method footprint (<100 methods, 16kb AAR package) +- Small method footprint (<200 methods, 24kb 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](https://github.com/jaychang0917/SimpleText) @@ -14,7 +15,8 @@ If you prefer put full text first and then apply spans, take a look at [another ```java Spannable spannable = new Spanner() .append("Original text\n\n") - .append("big\n", Spans.sizePX(100)) + .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()) @@ -35,7 +37,12 @@ Spannable spannable = new Spanner() .append("http://www.android.com\n", url("http://www.android.com")) ; ``` -Here is more methods to work with text: + +It looks like: + +![preview](https://i.imgur.com/SRnNRdm.png?1) + +You can manipulate text in many more ways: ```java Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog") .span("fox", foreground(Color.RED)) // search and span by given text @@ -44,14 +51,7 @@ Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog") .append("bar", underline()); // any number of spans ``` -You can use `span` to apply spans on the existing text: -```java -Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog") - .span("fox", foreground(Color.RED)) - .span("dog", foreground(Color.BLUE)); -``` - -If you need custom span, you have to use builder: +If you need custom span, you need span builder: ``` //java 7 Spannable spannable = new Spanner("The quick brown fox jumps over the lazy dog") @@ -71,6 +71,35 @@ val spannable = Spanner("The quick brown fox jumps over the lazy dog") .span("fox", custom { StyleSpan(Typeface.ITALIC) }) ``` +#### Reference + +| Main spans | +|------------------------------------| +| sizePx(int) | +| sizeDP(int) | +| scaleSize(float) | +| bold() | +| italic() | +| boldItalic() | +| font(String) | +| strikeThrough() | +| underline() | +| background(int color) | +| foreground(int color) | +| subscript() | +| superscript() | +| image(...) | +| click(listener) | +| url(url) | +| custom(spanBuilder) | + +| Modify methods | Description | +| --------------- | --------------------------- | +| append(text, spans...) | appends text | +| replace(search, replace, spans...)| search and replace text | +| span(search, spans...) | search text and apply spans | +| insert(pos, text, spans...) | instert given text in given position | + #### How to use ``` allprojects { @@ -81,7 +110,7 @@ val spannable = Spanner("The quick brown fox jumps over the lazy dog") } dependencies { - compile 'lt.neworld:spanner:v0.2' + compile 'lt.neworld:spanner:v0.3' } ``` diff --git a/sample/build.gradle b/sample/build.gradle index c8acbd5..f7c8895 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -11,7 +11,11 @@ android { } } +repositories { + maven { url 'https://jitpack.io' } +} + dependencies { - compile project(":lib") + compile 'lt.neworld:spanner:c353c6fa50' compile "com.android.support:appcompat-v7:$SUPPORT_LIB_VERSION" } \ No newline at end of file diff --git a/sample/src/main/java/lt/neworld/spanner/sample/SampleJavaActivity.java b/sample/src/main/java/lt/neworld/spanner/sample/SampleJavaActivity.java index 0452dbd..7ea492d 100644 --- a/sample/src/main/java/lt/neworld/spanner/sample/SampleJavaActivity.java +++ b/sample/src/main/java/lt/neworld/spanner/sample/SampleJavaActivity.java @@ -43,7 +43,8 @@ public void onClick(View view) { // @formatter:off Spannable spannable = new Spanner() .append("Original text\n\n") - .append("big\n", Spans.sizePX(100)) + .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())