Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ most of them are self-explaining, all colors are *not* Resource Ids, but parsed

`.setBackgroundColor()` Color

`.setBackgroundResource()` Drawable resource

`.setText()` Charset or IntRes for text

`.setTextColor()` Color or ColorStateList
Expand Down
10 changes: 1 addition & 9 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.mateware.snacky">

<application
android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
package="de.mateware.snacky" />
33 changes: 23 additions & 10 deletions library/src/main/java/de/mateware/snacky/Snacky.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@
public class Snacky {

private enum Type {
DEFAULT(null, null, null), SUCCESS(Color.parseColor("#388E3C"),
R.drawable.ic_check_black_24dp,
Color.WHITE), ERROR(Color.parseColor("#D50000"),
R.drawable.ic_clear_black_24dp,
Color.WHITE), INFO(Color.parseColor("#3F51B5"),
R.drawable.ic_info_outline_black_24dp,
Color.WHITE), WARNING(Color.parseColor("#FFA900"),
R.drawable.ic_error_outline_black_24dp,
Color.BLACK);
DEFAULT(null, null, null),
SUCCESS(Color.parseColor("#388E3C"),
R.drawable.ic_check_black_24dp,
Color.WHITE),
ERROR(Color.parseColor("#D50000"),
R.drawable.ic_clear_black_24dp,
Color.WHITE),
INFO(Color.parseColor("#3F51B5"),
R.drawable.ic_info_outline_black_24dp,
Color.WHITE),
WARNING(Color.parseColor("#FFA900"),
R.drawable.ic_error_outline_black_24dp,
Color.BLACK);

private Integer color;
private Integer iconResId;
Expand Down Expand Up @@ -99,7 +103,8 @@ public void onClick(View v) {
Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbar.getView();

if (builder.backgroundColor == null) builder.backgroundColor = builder.type.getColor();
if (builder.backgroundColor != null) snackbarLayout.setBackgroundColor(builder.backgroundColor);
if (builder.backgroundResId != null) snackbarLayout.setBackgroundResource(builder.backgroundResId);
else if (builder.backgroundColor != null) snackbarLayout.setBackgroundColor(builder.backgroundColor);

TextView actionText = snackbarLayout.findViewById(com.google.android.material.R.id.snackbar_action);
if (builder.actionTextSize != null) {
Expand Down Expand Up @@ -201,6 +206,7 @@ public static class Builder {
private Drawable icon = null;
private int iconResId = 0;
private Integer backgroundColor = null;
private Integer backgroundResId = null;

private Builder() {
}
Expand Down Expand Up @@ -335,6 +341,13 @@ public Builder setIcon(Drawable drawable) {

public Builder setBackgroundColor(@ColorInt int color) {
this.backgroundColor = color;
this.backgroundResId = null;
return this;
}

public Builder setBackgroundResource(@DrawableRes int resId) {
this.backgroundResId = resId;
this.backgroundColor = null;
return this;
}

Expand Down
3 changes: 0 additions & 3 deletions library/src/main/res/values/strings.xml

This file was deleted.