Skip to content

Commit

Permalink
Now Toasty's Toasts have the original Toast's size (16sp).
Browse files Browse the repository at this point in the history
  • Loading branch information
GrenderG committed May 10, 2017
1 parent 15a08d8 commit 2e0e46c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 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 = 123
versionName = '1.2.3'
versionCode = 125
versionName = '1.2.5'
}

task clean(type: Delete) {
Expand Down
16 changes: 15 additions & 1 deletion toasty/src/main/java/es/dmoral/toasty/Toasty.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
Expand Down Expand Up @@ -44,9 +45,12 @@ public class Toasty {
private static int SUCCESS_COLOR = Color.parseColor("#388E3C");
@ColorInt
private static int WARNING_COLOR = Color.parseColor("#FFA900");
@ColorInt
private static int NORMAL_COLOR = Color.parseColor("#353A3E");

private static final Typeface LOADED_TOAST_TYPEFACE = Typeface.create("sans-serif-condensed", Typeface.NORMAL);
private static Typeface currentTypeface = LOADED_TOAST_TYPEFACE;
private static int textSize = 16; // in SP

private static boolean tintIcon = true;

Expand Down Expand Up @@ -78,7 +82,7 @@ public static Toast normal(@NonNull Context context, @NonNull CharSequence messa
@CheckResult
public static Toast normal(@NonNull Context context, @NonNull CharSequence message, int duration,
Drawable icon, boolean withIcon) {
return custom(context, message, icon, duration, withIcon);
return custom(context, message, icon, NORMAL_COLOR, duration, withIcon, true);
}

@CheckResult
Expand Down Expand Up @@ -189,6 +193,7 @@ public static Toast custom(@NonNull Context context, @NonNull CharSequence messa
toastTextView.setTextColor(DEFAULT_TEXT_COLOR);
toastTextView.setText(message);
toastTextView.setTypeface(currentTypeface);
toastTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);

currentToast.setView(toastLayout);
currentToast.setDuration(duration);
Expand All @@ -208,6 +213,7 @@ public static class Config {
private int WARNING_COLOR = Toasty.WARNING_COLOR;

private Typeface typeface = Toasty.currentTypeface;
private int textSize = Toasty.textSize;

private boolean tintIcon = Toasty.tintIcon;

Expand All @@ -227,6 +233,7 @@ public static void reset() {
Toasty.SUCCESS_COLOR = Color.parseColor("#388E3C");
Toasty.WARNING_COLOR = Color.parseColor("#FFA900");
Toasty.currentTypeface = LOADED_TOAST_TYPEFACE;
Toasty.textSize = 16;
Toasty.tintIcon = true;
}

Expand Down Expand Up @@ -266,6 +273,12 @@ public Config setToastTypeface(@NonNull Typeface typeface) {
return this;
}

@CheckResult
public Config setTextSize(int sizeInSp) {
this.textSize = sizeInSp;
return this;
}

@CheckResult
public Config tintIcon(boolean tintIcon) {
this.tintIcon = tintIcon;
Expand All @@ -279,6 +292,7 @@ public void apply() {
Toasty.SUCCESS_COLOR = SUCCESS_COLOR;
Toasty.WARNING_COLOR = WARNING_COLOR;
Toasty.currentTypeface = typeface;
Toasty.textSize = textSize;
Toasty.tintIcon = tintIcon;
}
}
Expand Down

0 comments on commit 2e0e46c

Please sign in to comment.