From 6ba3eaee0885e585a19c8b1e2cc7a6360e618d5d Mon Sep 17 00:00:00 2001 From: GrenderG Date: Fri, 28 Apr 2017 22:44:45 +0200 Subject: [PATCH] Now you can decide to tint icon color along with the text. --- build.gradle | 4 ++-- .../src/main/java/es/dmoral/toasty/Toasty.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 726c884..eb222e4 100644 --- a/build.gradle +++ b/build.gradle @@ -27,8 +27,8 @@ ext { supportLibVersion = '25.3.1' - versionCode = 120 - versionName = '1.2.0' + versionCode = 121 + versionName = '1.2.1' } task clean(type: Delete) { diff --git a/toasty/src/main/java/es/dmoral/toasty/Toasty.java b/toasty/src/main/java/es/dmoral/toasty/Toasty.java index f27a047..c0321ca 100644 --- a/toasty/src/main/java/es/dmoral/toasty/Toasty.java +++ b/toasty/src/main/java/es/dmoral/toasty/Toasty.java @@ -48,6 +48,7 @@ public class Toasty { private static String TOAST_TYPEFACE = "sans-serif-condensed"; private static AssetManager assetManager = null; + private static boolean tintIcon = true; private Toasty() { // avoiding instantiation @@ -178,9 +179,12 @@ public static Toast custom(@NonNull Context context, @NonNull CharSequence messa if (withIcon) { if (icon == null) throw new IllegalArgumentException("Avoid passing 'icon' as null if 'withIcon' is set to true"); - ToastyUtils.setBackground(toastIcon, ToastyUtils.tintIcon(icon, DEFAULT_TEXT_COLOR)); - } else + if (tintIcon) + icon = ToastyUtils.tintIcon(icon, DEFAULT_TEXT_COLOR); + ToastyUtils.setBackground(toastIcon, icon); + } else { toastIcon.setVisibility(View.GONE); + } toastTextView.setTextColor(DEFAULT_TEXT_COLOR); toastTextView.setText(message); @@ -210,6 +214,7 @@ public static class Config { private String TOAST_TYPEFACE = Toasty.TOAST_TYPEFACE; private AssetManager assetManager = Toasty.assetManager; + private boolean tintIcon = Toasty.tintIcon; private Config() { // avoiding instantiation @@ -276,6 +281,12 @@ public Config setToastTypeface(@NonNull String toastTypefaceFamily) { return this; } + @CheckResult + public Config tintIcon(boolean tintIcon) { + this.tintIcon = tintIcon; + return this; + } + public void apply() { Toasty.DEFAULT_TEXT_COLOR = DEFAULT_TEXT_COLOR; Toasty.ERROR_COLOR = ERROR_COLOR; @@ -284,6 +295,7 @@ public void apply() { Toasty.WARNING_COLOR = WARNING_COLOR; Toasty.assetManager = assetManager; Toasty.TOAST_TYPEFACE = TOAST_TYPEFACE; + Toasty.tintIcon = tintIcon; configInstance = null; } }