diff --git a/README.md b/README.md index b3cfe0c..f38389f 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,6 @@ int gapWidth = getResources().getDimensionPixelOffset(R.dimen.space_xlarge); textView.setText(new Truss() .appendln("Number One", new Snippety().number(leadGap, gapWidth, 1)) .appendln("Number Two", new Snippety().number(leadGap, gapWidth, 2)) - .appendln("Number Three", new Snippety().number(leadGap, gapWidth, 3)) .build()); ``` @@ -272,20 +271,29 @@ int gapWidth = getResources().getDimensionPixelOffset(R.dimen.space_xlarge); textView.setText(new Truss() .appendln("Number One", new Snippety().bullet(leadGap, gapWidth)) .appendln("Number Two", new Snippety().bullet(leadGap, gapWidth)) - .appendln("Number Three", new Snippety().bullet(leadGap, gapWidth)) .build()); ``` - Custom Unordered List +```java +int leadGap = getResources().getDimensionPixelOffset(R.dimen.space_medium); +int gapWidth = getResources().getDimensionPixelOffset(R.dimen.space_xlarge); +textView.setText(new Truss() + .appendln("Custom Bullet One", new Snippety().bullet(bitmap, leadGap, "I.")) + .appendln("Custom Bullet Two", new Snippety().bullet(bitmap, leadGap, "II.")) + .build()); +``` + +- Image Unordered List + ```java Drawable drawable = ContextCompat.getDrawable(getContext(), R.mipmap.ic_launcher); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_star_black_24dp); int leadGap = getResources().getDimensionPixelOffset(R.dimen.space_medium); textView.setText(new Truss() - .appendln("Custom Bullet One", new Snippety().imageBullet(bitmap, leadGap)) - .appendln("Custom Bullet Two", new Snippety().imageBullet(bitmap, leadGap)) - .appendln("Custom Bullet Three", new Snippety().imageBullet(bitmap, leadGap)) + .appendln("Image Bullet One", new Snippety().bullet(bitmap, leadGap)) + .appendln("Image Bullet Two", new Snippety().bullet(bitmap, leadGap)) .build()); ``` diff --git a/README_images/ic_html_screen.png b/README_images/ic_html_screen.png index 99ca662..11a2c0c 100644 Binary files a/README_images/ic_html_screen.png and b/README_images/ic_html_screen.png differ diff --git a/extra/gradle/libraries.gradle b/extra/gradle/libraries.gradle index 4280a25..0b49c1b 100644 --- a/extra/gradle/libraries.gradle +++ b/extra/gradle/libraries.gradle @@ -12,7 +12,7 @@ ext { //library libraryGroup = 'com.github.fueled' - libraryVersion = '1.1.0' + libraryVersion = '1.1.1' //android libraries supportVersion = '25.3.0' diff --git a/sample/src/main/java/com/fueled/snippety/sample/fragment/HtmlFragment.java b/sample/src/main/java/com/fueled/snippety/sample/fragment/HtmlFragment.java index f1d1f74..d0671f1 100644 --- a/sample/src/main/java/com/fueled/snippety/sample/fragment/HtmlFragment.java +++ b/sample/src/main/java/com/fueled/snippety/sample/fragment/HtmlFragment.java @@ -63,7 +63,7 @@ private CharSequence getHtmlTrussText() { return new Truss() - .appendSelectiveln("Hey! This is Snippety", "Snippety", + .appendSelective("Hey! This is Snippety. ", "Snippety", new Snippety().textColor(colorAccent)) // ForegroundColorSpan .appendDelimiterizedln("You can also write `HTML`!", "`", new Snippety().textColor(colorAccent)) // ForegroundColorSpan @@ -76,7 +76,6 @@ private CharSequence getHtmlTrussText() { .appendln("Number One", new Snippety().number(leadGap, gapWidth, 1)) // TextIndentSpan .appendln("Number Two", new Snippety().number(leadGap, gapWidth, 2)) - .appendln("Number Three", new Snippety().number(leadGap, gapWidth, 3)) .appendln() // Unordered List @@ -86,7 +85,6 @@ private CharSequence getHtmlTrussText() { .appendln("Bullet One", new Snippety().bullet(leadGap, gapWidth)) // TextIndentSpan .appendln("Bullet Two", new Snippety().bullet(leadGap, gapWidth)) - .appendln("Bullet Three", new Snippety().bullet(leadGap, gapWidth)) .appendln() // Custom Unordered List @@ -94,9 +92,19 @@ private CharSequence getHtmlTrussText() { .appendln("Custom Unordered List", new Snippety().fontStyle(Snippety.FontStyle.BOLD)) .appendln(new Snippety().hr(oneDp, colorGrey)) - .appendln("Custom Bullet One", new Snippety().imageBullet(bitmap, leadGap)) // IconMarginSpan - .appendln("Custom Bullet Two", new Snippety().imageBullet(bitmap, leadGap)) - .appendln("Custom Bullet Three", new Snippety().imageBullet(bitmap, leadGap)) + .appendln("Custom Bullet One", new Snippety().bullet(leadGap, gapWidth, "I.")) // TextIndentSpan + .appendln("Custom Bullet Two", new Snippety().bullet(leadGap, gapWidth, "II.")) + .appendln("Custom Bullet Three", new Snippety().bullet(leadGap, gapWidth, "III.")) + .appendln() + + // Image Unordered List + + .appendln("Image Unordered List", new Snippety().fontStyle(Snippety.FontStyle.BOLD)) + .appendln(new Snippety().hr(oneDp, colorGrey)) + + .appendln("Image Bullet One", new Snippety().bullet(bitmap, leadGap)) // IconMarginSpan + .appendln("Image Bullet Two", new Snippety().bullet(bitmap, leadGap)) + .appendln("Image Bullet Three", new Snippety().bullet(bitmap, leadGap)) .appendln() .build(); diff --git a/snippety/src/main/java/com/fueled/snippety/core/Snippety.java b/snippety/src/main/java/com/fueled/snippety/core/Snippety.java index fefdd27..d0c6382 100644 --- a/snippety/src/main/java/com/fueled/snippety/core/Snippety.java +++ b/snippety/src/main/java/com/fueled/snippety/core/Snippety.java @@ -7,6 +7,7 @@ import android.text.style.AbsoluteSizeSpan; import android.text.style.AlignmentSpan; import android.text.style.BackgroundColorSpan; +import android.text.style.BulletSpan; import android.text.style.ClickableSpan; import android.text.style.ForegroundColorSpan; import android.text.style.IconMarginSpan; @@ -308,6 +309,16 @@ public Snippety suggestions(String... suggestions) { return this; } + /** + * add bullets + * + * @return Snippety + */ + public Snippety bullet() { + spans.add(new BulletSpan()); + return this; + } + /** * add bullets with specified leadGap and gapWidth * @@ -320,6 +331,19 @@ public Snippety bullet(int leadGap, int gapWidth) { return this; } + /** + * add custom bullets with specified leadGap and gapWidth + * + * @param leadGap starting gap from left + * @param gapWidth gap between bullet and text + * @param data data to show on bullet + * @return Snippety + */ + public Snippety bullet(int leadGap, int gapWidth, String data) { + spans.add(new TextIndentSpan(new TextIndentSpan.Options(leadGap, gapWidth), data)); + return this; + } + /** * add image bullets with specified padding * @@ -327,7 +351,7 @@ public Snippety bullet(int leadGap, int gapWidth) { * @param padding padding between bullet and text * @return Snippety */ - public Snippety imageBullet(Bitmap bitmap, int padding) { + public Snippety bullet(Bitmap bitmap, int padding) { spans.add(new IconMarginSpan(bitmap, padding)); return this; } @@ -343,6 +367,18 @@ public Snippety bullet(TextIndentSpan.Options options) { return this; } + /** + * add bullets with specified options + * + * @param options for leadGap and gapWidth + * @param data data to show on bullet + * @return Snippety + */ + public Snippety bullet(TextIndentSpan.Options options, String data) { + spans.add(new TextIndentSpan(options, data)); + return this; + } + /** * add numbers with specified leadGap and gapWidth * diff --git a/snippety/src/main/java/com/fueled/snippety/span/TextIndentSpan.java b/snippety/src/main/java/com/fueled/snippety/span/TextIndentSpan.java index cdfddc4..2227b69 100644 --- a/snippety/src/main/java/com/fueled/snippety/span/TextIndentSpan.java +++ b/snippety/src/main/java/com/fueled/snippety/span/TextIndentSpan.java @@ -4,6 +4,7 @@ import android.graphics.Paint; import android.graphics.Typeface; import android.text.Layout; +import android.text.TextPaint; import android.text.style.LeadingMarginSpan; /** @@ -36,7 +37,7 @@ public int getLeadingMargin(boolean first) { public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout l) { if (first) { - Paint paint = new Paint(p); + TextPaint paint = new TextPaint(p); paint.setStyle(Paint.Style.FILL);