Skip to content

Commit f35d323

Browse files
author
Chetan Sachdeva
authored
Merge pull request #26 from Fueled/custom-bullet
feat(*): add custom bullet.
2 parents 0f39b6c + 0a391d3 commit f35d323

File tree

6 files changed

+67
-14
lines changed

6 files changed

+67
-14
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ int gapWidth = getResources().getDimensionPixelOffset(R.dimen.space_xlarge);
260260
textView.setText(new Truss()
261261
.appendln("Number One", new Snippety().number(leadGap, gapWidth, 1))
262262
.appendln("Number Two", new Snippety().number(leadGap, gapWidth, 2))
263-
.appendln("Number Three", new Snippety().number(leadGap, gapWidth, 3))
264263
.build());
265264
```
266265

@@ -272,20 +271,29 @@ int gapWidth = getResources().getDimensionPixelOffset(R.dimen.space_xlarge);
272271
textView.setText(new Truss()
273272
.appendln("Number One", new Snippety().bullet(leadGap, gapWidth))
274273
.appendln("Number Two", new Snippety().bullet(leadGap, gapWidth))
275-
.appendln("Number Three", new Snippety().bullet(leadGap, gapWidth))
276274
.build());
277275
```
278276

279277
- Custom Unordered List
280278

279+
```java
280+
int leadGap = getResources().getDimensionPixelOffset(R.dimen.space_medium);
281+
int gapWidth = getResources().getDimensionPixelOffset(R.dimen.space_xlarge);
282+
textView.setText(new Truss()
283+
.appendln("Custom Bullet One", new Snippety().bullet(bitmap, leadGap, "I."))
284+
.appendln("Custom Bullet Two", new Snippety().bullet(bitmap, leadGap, "II."))
285+
.build());
286+
```
287+
288+
- Image Unordered List
289+
281290
```java
282291
Drawable drawable = ContextCompat.getDrawable(getContext(), R.mipmap.ic_launcher);
283292
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_star_black_24dp);
284293
int leadGap = getResources().getDimensionPixelOffset(R.dimen.space_medium);
285294
textView.setText(new Truss()
286-
.appendln("Custom Bullet One", new Snippety().imageBullet(bitmap, leadGap))
287-
.appendln("Custom Bullet Two", new Snippety().imageBullet(bitmap, leadGap))
288-
.appendln("Custom Bullet Three", new Snippety().imageBullet(bitmap, leadGap))
295+
.appendln("Image Bullet One", new Snippety().bullet(bitmap, leadGap))
296+
.appendln("Image Bullet Two", new Snippety().bullet(bitmap, leadGap))
289297
.build());
290298
```
291299

README_images/ic_html_screen.png

12.3 KB
Loading

extra/gradle/libraries.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ext {
1212

1313
//library
1414
libraryGroup = 'com.github.fueled'
15-
libraryVersion = '1.1.0'
15+
libraryVersion = '1.1.1'
1616

1717
//android libraries
1818
supportVersion = '25.3.0'

sample/src/main/java/com/fueled/snippety/sample/fragment/HtmlFragment.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private CharSequence getHtmlTrussText() {
6363

6464
return new Truss()
6565

66-
.appendSelectiveln("Hey! This is Snippety", "Snippety",
66+
.appendSelective("Hey! This is Snippety. ", "Snippety",
6767
new Snippety().textColor(colorAccent)) // ForegroundColorSpan
6868
.appendDelimiterizedln("You can also write `HTML`!", "`",
6969
new Snippety().textColor(colorAccent)) // ForegroundColorSpan
@@ -76,7 +76,6 @@ private CharSequence getHtmlTrussText() {
7676

7777
.appendln("Number One", new Snippety().number(leadGap, gapWidth, 1)) // TextIndentSpan
7878
.appendln("Number Two", new Snippety().number(leadGap, gapWidth, 2))
79-
.appendln("Number Three", new Snippety().number(leadGap, gapWidth, 3))
8079
.appendln()
8180

8281
// Unordered List
@@ -86,17 +85,26 @@ private CharSequence getHtmlTrussText() {
8685

8786
.appendln("Bullet One", new Snippety().bullet(leadGap, gapWidth)) // TextIndentSpan
8887
.appendln("Bullet Two", new Snippety().bullet(leadGap, gapWidth))
89-
.appendln("Bullet Three", new Snippety().bullet(leadGap, gapWidth))
9088
.appendln()
9189

9290
// Custom Unordered List
9391

9492
.appendln("Custom Unordered List", new Snippety().fontStyle(Snippety.FontStyle.BOLD))
9593
.appendln(new Snippety().hr(oneDp, colorGrey))
9694

97-
.appendln("Custom Bullet One", new Snippety().imageBullet(bitmap, leadGap)) // IconMarginSpan
98-
.appendln("Custom Bullet Two", new Snippety().imageBullet(bitmap, leadGap))
99-
.appendln("Custom Bullet Three", new Snippety().imageBullet(bitmap, leadGap))
95+
.appendln("Custom Bullet One", new Snippety().bullet(leadGap, gapWidth, "I.")) // TextIndentSpan
96+
.appendln("Custom Bullet Two", new Snippety().bullet(leadGap, gapWidth, "II."))
97+
.appendln("Custom Bullet Three", new Snippety().bullet(leadGap, gapWidth, "III."))
98+
.appendln()
99+
100+
// Image Unordered List
101+
102+
.appendln("Image Unordered List", new Snippety().fontStyle(Snippety.FontStyle.BOLD))
103+
.appendln(new Snippety().hr(oneDp, colorGrey))
104+
105+
.appendln("Image Bullet One", new Snippety().bullet(bitmap, leadGap)) // IconMarginSpan
106+
.appendln("Image Bullet Two", new Snippety().bullet(bitmap, leadGap))
107+
.appendln("Image Bullet Three", new Snippety().bullet(bitmap, leadGap))
100108
.appendln()
101109

102110
.build();

snippety/src/main/java/com/fueled/snippety/core/Snippety.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.text.style.AbsoluteSizeSpan;
88
import android.text.style.AlignmentSpan;
99
import android.text.style.BackgroundColorSpan;
10+
import android.text.style.BulletSpan;
1011
import android.text.style.ClickableSpan;
1112
import android.text.style.ForegroundColorSpan;
1213
import android.text.style.IconMarginSpan;
@@ -308,6 +309,16 @@ public Snippety suggestions(String... suggestions) {
308309
return this;
309310
}
310311

312+
/**
313+
* add bullets
314+
*
315+
* @return Snippety
316+
*/
317+
public Snippety bullet() {
318+
spans.add(new BulletSpan());
319+
return this;
320+
}
321+
311322
/**
312323
* add bullets with specified leadGap and gapWidth
313324
*
@@ -320,14 +331,27 @@ public Snippety bullet(int leadGap, int gapWidth) {
320331
return this;
321332
}
322333

334+
/**
335+
* add custom bullets with specified leadGap and gapWidth
336+
*
337+
* @param leadGap starting gap from left
338+
* @param gapWidth gap between bullet and text
339+
* @param data data to show on bullet
340+
* @return Snippety
341+
*/
342+
public Snippety bullet(int leadGap, int gapWidth, String data) {
343+
spans.add(new TextIndentSpan(new TextIndentSpan.Options(leadGap, gapWidth), data));
344+
return this;
345+
}
346+
323347
/**
324348
* add image bullets with specified padding
325349
*
326350
* @param bitmap bitmap to add as bullet
327351
* @param padding padding between bullet and text
328352
* @return Snippety
329353
*/
330-
public Snippety imageBullet(Bitmap bitmap, int padding) {
354+
public Snippety bullet(Bitmap bitmap, int padding) {
331355
spans.add(new IconMarginSpan(bitmap, padding));
332356
return this;
333357
}
@@ -343,6 +367,18 @@ public Snippety bullet(TextIndentSpan.Options options) {
343367
return this;
344368
}
345369

370+
/**
371+
* add bullets with specified options
372+
*
373+
* @param options for leadGap and gapWidth
374+
* @param data data to show on bullet
375+
* @return Snippety
376+
*/
377+
public Snippety bullet(TextIndentSpan.Options options, String data) {
378+
spans.add(new TextIndentSpan(options, data));
379+
return this;
380+
}
381+
346382
/**
347383
* add numbers with specified leadGap and gapWidth
348384
*

snippety/src/main/java/com/fueled/snippety/span/TextIndentSpan.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.graphics.Paint;
55
import android.graphics.Typeface;
66
import android.text.Layout;
7+
import android.text.TextPaint;
78
import android.text.style.LeadingMarginSpan;
89

910
/**
@@ -36,7 +37,7 @@ public int getLeadingMargin(boolean first) {
3637
public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline,
3738
int bottom, CharSequence text, int start, int end, boolean first, Layout l) {
3839
if (first) {
39-
Paint paint = new Paint(p);
40+
TextPaint paint = new TextPaint(p);
4041

4142
paint.setStyle(Paint.Style.FILL);
4243

0 commit comments

Comments
 (0)