Skip to content

Commit

Permalink
Now you can decide to tint icon color along with the text.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrenderG committed Apr 28, 2017
1 parent c3a8802 commit 6ba3eae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 14 additions & 2 deletions toasty/src/main/java/es/dmoral/toasty/Toasty.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 6ba3eae

Please sign in to comment.