Skip to content

Commit

Permalink
Merge pull request #33 from istiakshihab/feature/new-snackbar
Browse files Browse the repository at this point in the history
Added New Icon Tint Feature
  • Loading branch information
Pradyuman7 authored Oct 20, 2021
2 parents 4f07cbb + a847397 commit bf746c6
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 18 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ ChocoBar is now also available in Kotlin, thanks to @JamesEllerbee
![Love Chocobar](https://user-images.githubusercontent.com/35525781/96970060-c012c080-1530-11eb-926c-59edd1844413.png)
![image](https://user-images.githubusercontent.com/26584526/136639395-7a70f775-b5d3-4ad4-8b4f-d0ce91490c18.png)
![image](https://user-images.githubusercontent.com/26584526/136639381-19bfd6f0-a34e-49f9-8b7e-4e34c4e02ba7.png)
![image](https://user-images.githubusercontent.com/36191408/137777366-738ce9c7-d942-4ccb-845a-38f4891196ea.png)
<img src="https://user-images.githubusercontent.com/36191408/137777366-738ce9c7-d942-4ccb-845a-38f4891196ea.png" width=40% >
<img src="https://user-images.githubusercontent.com/36191408/138039703-976e65b1-c65a-47ea-865d-5d54a7951e3e.png" width=40% >

>Custom Cyan Tint was used on Info Gray.
## Documentation
[Find how to use the in-built Chocobars here](documentation/ReadMe.md)
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/pd/snickers/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ protected void onCreate(Bundle savedInstanceState) {
.setIcon(R.mipmap.ic_launcher)
.setActivity(MainActivity.this)
.setDuration(ChocoBar.LENGTH_INDEFINITE)
.setIconTint(Color.WHITE)
.build()
.show());

Expand Down Expand Up @@ -127,6 +128,15 @@ protected void onCreate(Bundle savedInstanceState) {
.infoGray()
.show());

findViewById(R.id.button_custom_tint).setOnClickListener(v-> ChocoBar.builder()
.setView(v)
.centerText()
.setDuration(ChocoBar.LENGTH_LONG)
.setIconTint(Color.CYAN)
.setText("Custom Cyan Tinted Icon")
.infoGray()
.show());

findViewById(R.id.button_next).setOnClickListener(v -> {
Intent secondaryActivityIntent = new Intent(this, SecondaryActivity.class);
startActivity(secondaryActivityIntent);
Expand Down
24 changes: 22 additions & 2 deletions app/src/main/res/layout/content_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,38 @@
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/info_gray"
app:layout_constraintBottom_toTopOf="@+id/button_next"
app:layout_constraintBottom_toTopOf="@+id/custom_tint"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_blocked" />

<Button
android:id="@+id/button_custom_tint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button_info_gray"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/custom_tint"
app:layout_constraintBottom_toTopOf="@+id/button_next"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_info_gray" />

<ImageButton
android:id="@+id/button_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_below="@id/button_info_gray"
android:layout_below="@id/button_custom_tint"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="@string/kotlin_icon"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
<string name="kotlin_icon">Kotlin icon</string>
<string name="java_icon">java icon</string>
<string name="info_gray">Info Gray Chocobar</string>
<string name="custom_tint">Custom Icon Color</string>
</resources>
45 changes: 30 additions & 15 deletions chocobar/src/main/java/com/pd/chocobar/ChocoBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,33 @@
public class ChocoBar {

private enum Type {
DEFAULT(null, null, null, null),
GREEN(Color.parseColor("#388E3C"), R.drawable.check_mark, Color.WHITE, "SUCCESS !"),
RED(Color.parseColor("#D50000"), R.drawable.cross_mark, Color.WHITE, "ERROR !"),
CYAN(Color.parseColor("#e0ffff"), R.drawable.info_mark, Color.WHITE, "CYAN"),
ORANGE(Color.parseColor("#ffa500"), R.drawable.warning_mark, Color.BLACK, "WARNING !"),
GOOD(Color.parseColor("#C5BEBE"), R.drawable.good_mark, Color.WHITE, "GRAY_GOOD"),
BAD(Color.parseColor("#C5BEBE"), R.drawable.bad_mark, Color.WHITE, "GRAY_BAD"),
BLACK(Color.parseColor("#000000"), R.drawable.off_notification_mark, Color.WHITE, "Black"),
LOVE(Color.parseColor("#E8290B"), R.drawable.ic_love, Color.BLACK, "LOVE"),
BLOCKED(Color.parseColor("#E8290B"), R.drawable.blocked_mark, Color.BLACK, "BLOCKED"),
NOTIFICATION_ON(Color.parseColor("#000000"), R.drawable.on_notification_mark, Color.WHITE, "NOTIFICATIONS ON"),
INFOGRAY(Color.parseColor("#BB353535"), R.drawable.info_mark, Color.WHITE,"INFO GRAYBLUE");
DEFAULT(null, null, null, null, null),
GREEN(Color.parseColor("#388E3C"), R.drawable.check_mark, Color.WHITE, "SUCCESS !", Color.WHITE),
RED(Color.parseColor("#D50000"), R.drawable.cross_mark, Color.WHITE, "ERROR !", Color.WHITE),
CYAN(Color.parseColor("#e0ffff"), R.drawable.info_mark, Color.WHITE, "CYAN", Color.WHITE),
ORANGE(Color.parseColor("#ffa500"), R.drawable.warning_mark, Color.BLACK, "WARNING !", Color.BLACK),
GOOD(Color.parseColor("#C5BEBE"), R.drawable.good_mark, Color.WHITE, "GRAY_GOOD", Color.WHITE),
BAD(Color.parseColor("#C5BEBE"), R.drawable.bad_mark, Color.WHITE, "GRAY_BAD", Color.WHITE),
BLACK(Color.parseColor("#000000"), R.drawable.off_notification_mark, Color.WHITE, "Black", Color.WHITE),
LOVE(Color.parseColor("#E8290B"), R.drawable.ic_love, Color.BLACK, "LOVE", Color.BLACK),
BLOCKED(Color.parseColor("#E8290B"), R.drawable.blocked_mark, Color.BLACK, "BLOCKED", Color.BLACK),
NOTIFICATION_ON(Color.parseColor("#000000"), R.drawable.on_notification_mark, Color.WHITE, "NOTIFICATIONS ON", Color.WHITE),
INFOGRAY(Color.parseColor("#BB353535"), R.drawable.info_mark, Color.WHITE,"INFO GRAYBLUE", Color.parseColor("#4895ED"));

private Integer color;
private Integer iconResId;
private Integer standardTextColor;
private CharSequence text;
private Integer iconTint;

Type(@ColorInt Integer color, @DrawableRes Integer iconResId, @ColorInt Integer standardTextColor, CharSequence text) {
Type(@ColorInt Integer color, @DrawableRes Integer iconResId, @ColorInt Integer standardTextColor, CharSequence text, @ColorInt Integer iconTint) {
this.color = color;

this.iconResId = iconResId;
this.standardTextColor = standardTextColor;

this.text = text;
this.iconTint = iconTint;
}

public Integer getColor() {
Expand All @@ -86,6 +88,8 @@ public Integer getStandardTextColor() {
public CharSequence getText() {
return text;
}

public Integer getIconTint(){return iconTint;}
}

private final Builder builder;
Expand Down Expand Up @@ -208,8 +212,13 @@ else if (builder.textColor != null)
else
text.setCompoundDrawablesWithIntrinsicBounds(builder.icon, null, transparentHelperDrawable, null);

if (Build.VERSION.SDK_INT >= 21 && builder.type == Type.INFOGRAY){
builder.icon.setTint(Color.parseColor("#4895ED"));
if (Build.VERSION.SDK_INT >= 21 && builder.iconTint != null){
builder.icon.setTint(builder.iconTint);
Log.d("TAG","HERE");
}
else if(Build.VERSION.SDK_INT >= 21 && builder.iconTint == null ){
builder.icon.setTint(builder.type.getIconTint());
Log.d("TAG","NOHERE");
}
text.setCompoundDrawablePadding(text.getResources().getDimensionPixelOffset(R.dimen.icon_padding));
}
Expand Down Expand Up @@ -260,6 +269,7 @@ public static class Builder {
private Drawable icon = null;
private int iconResId = 0;
private Integer backgroundColor = null;
private Integer iconTint = null;

private Builder() {
}
Expand Down Expand Up @@ -397,6 +407,11 @@ public Builder setBackgroundColor(@ColorInt int color) {
return this;
}

public Builder setIconTint(@ColorInt int color){
this.iconTint = color;
return this;
}

public Snackbar build() {
return make();
}
Expand Down
12 changes: 12 additions & 0 deletions documentation/documentation-java.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ ChocoBar.builder()
.show());
```

- To display a Chocobar with Custom Icon Tint:
```java
ChocoBar.builder()
.setView(v)
.centerText()
.setDuration(ChocoBar.LENGTH_LONG)
.setIconTint(Color.CYAN)
.setText("Custom Cyan Tinted Icon")
.infoGray()
.show());
```

- You can also create highly customized ChocoBars:

``` java
Expand Down

0 comments on commit bf746c6

Please # to comment.