From d611e7c7fa6a0b8ddba863e5cfcfe632e1a7ac85 Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Mon, 15 Jun 2020 17:49:34 +0700 Subject: [PATCH 1/2] Add background drawable support --- README.md | 2 ++ .../main/java/de/mateware/snacky/Snacky.java | 33 +++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c58237f..bad8489 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/library/src/main/java/de/mateware/snacky/Snacky.java b/library/src/main/java/de/mateware/snacky/Snacky.java index 2996313..75766e6 100644 --- a/library/src/main/java/de/mateware/snacky/Snacky.java +++ b/library/src/main/java/de/mateware/snacky/Snacky.java @@ -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; @@ -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) { @@ -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() { } @@ -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; } From 90e96fa673fb40e58f1104836e74ca04094eb952 Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Mon, 22 Jun 2020 15:01:44 +0700 Subject: [PATCH 2/2] Remove label name and support RTL --- library/src/main/AndroidManifest.xml | 10 +--------- library/src/main/res/values/strings.xml | 3 --- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 library/src/main/res/values/strings.xml diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index b9acac8..a7bd024 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,10 +1,2 @@ - - - - - - + package="de.mateware.snacky" /> \ No newline at end of file diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml deleted file mode 100644 index 79919d1..0000000 --- a/library/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - Snacky -