Skip to content

Commit

Permalink
Merge pull request #26 from Fueled/custom-bullet
Browse files Browse the repository at this point in the history
feat(*): add custom bullet.
  • Loading branch information
Chetan Sachdeva authored Jan 14, 2018
2 parents 0f39b6c + 0a391d3 commit f35d323
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 14 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
```

Expand All @@ -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());
```

Expand Down
Binary file modified README_images/ic_html_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion extra/gradle/libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ext {

//library
libraryGroup = 'com.github.fueled'
libraryVersion = '1.1.0'
libraryVersion = '1.1.1'

//android libraries
supportVersion = '25.3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -86,17 +85,26 @@ 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

.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();
Expand Down
38 changes: 37 additions & 1 deletion snippety/src/main/java/com/fueled/snippety/core/Snippety.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand All @@ -320,14 +331,27 @@ 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
*
* @param bitmap bitmap to add as bullet
* @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;
}
Expand All @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit f35d323

Please sign in to comment.