From 6b37d9bb05135bb393da446cd721538359d779b6 Mon Sep 17 00:00:00 2001 From: GrenderG Date: Thu, 19 Jan 2017 20:01:51 +0100 Subject: [PATCH] v.1.1.1 --- README.md | 2 +- .../es/dmoral/toastysample/MainActivity.java | 6 +- toasty/build.gradle | 6 +- .../main/java/es/dmoral/toasty/Toasty.java | 70 +++++++++---------- .../java/es/dmoral/toasty/ToastyUtils.java | 6 +- 5 files changed, 44 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 663ebcc..5e9f873 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Toasty -[![](https://jitpack.io/v/GrenderG/Toasty.svg)](https://jitpack.io/#GrenderG/Toasty) +[![API](https://img.shields.io/badge/API-9%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=9) [![](https://jitpack.io/v/GrenderG/Toasty.svg)](https://jitpack.io/#GrenderG/Toasty) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Toasty-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5102) The usual Toast, but with steroids. **(Screenshots at the end of the file.)** diff --git a/app/src/main/java/es/dmoral/toastysample/MainActivity.java b/app/src/main/java/es/dmoral/toastysample/MainActivity.java index 10549e7..2824d99 100644 --- a/app/src/main/java/es/dmoral/toastysample/MainActivity.java +++ b/app/src/main/java/es/dmoral/toastysample/MainActivity.java @@ -10,17 +10,17 @@ /** * This file is part of Toasty. - *

+ * * Toasty is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - *

+ * * Toasty is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - *

+ * * You should have received a copy of the GNU General Public License * along with Toasty. If not, see . */ diff --git a/toasty/build.gradle b/toasty/build.gradle index fda9f69..b91a01c 100644 --- a/toasty/build.gradle +++ b/toasty/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' group = 'com.github.GrenderG' -version = '1.0' +version = '1.1.1' android { compileSdkVersion 25 @@ -10,8 +10,8 @@ android { defaultConfig { minSdkVersion 9 targetSdkVersion 25 - versionCode 11 - versionName "1.1" + versionCode 111 + versionName "1.1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/toasty/src/main/java/es/dmoral/toasty/Toasty.java b/toasty/src/main/java/es/dmoral/toasty/Toasty.java index d4e9cd7..192e25f 100644 --- a/toasty/src/main/java/es/dmoral/toasty/Toasty.java +++ b/toasty/src/main/java/es/dmoral/toasty/Toasty.java @@ -1,10 +1,12 @@ package es.dmoral.toasty; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; +import android.support.annotation.CheckResult; import android.support.annotation.ColorInt; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; @@ -15,21 +17,22 @@ /** * This file is part of Toasty. - *

+ * * Toasty is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - *

+ * * Toasty is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - *

+ * * You should have received a copy of the GNU General Public License * along with Toasty. If not, see . */ +@SuppressLint("InflateParams") public class Toasty { private static final @ColorInt int DEFAULT_TEXT_COLOR = Color.parseColor("#FFFFFF"); @@ -40,94 +43,96 @@ public class Toasty { private static final String TOAST_TYPEFACE = "sans-serif-condensed"; - private static Toast currentToast; - - public static Toast normal(@NonNull Context context, @NonNull String message) { + public static @CheckResult Toast normal(@NonNull Context context, @NonNull String message) { return normal(context, message, Toast.LENGTH_SHORT, null, false); } - public static Toast normal(@NonNull Context context, @NonNull String message, Drawable icon) { + public static @CheckResult Toast normal(@NonNull Context context, @NonNull String message, Drawable icon) { return normal(context, message, Toast.LENGTH_SHORT, icon, true); } - public static Toast normal(@NonNull Context context, @NonNull String message, int duration, + public static @CheckResult Toast normal(@NonNull Context context, @NonNull String message, int duration) { + return normal(context, message, duration, null, false); + } + + public static @CheckResult Toast normal(@NonNull Context context, @NonNull String message, int duration, Drawable icon) { return normal(context, message, duration, icon, true); } - public static Toast normal(@NonNull Context context, @NonNull String message, int duration, + public static @CheckResult Toast normal(@NonNull Context context, @NonNull String message, int duration, Drawable icon, boolean withIcon) { return custom(context, message, icon, DEFAULT_TEXT_COLOR, duration, withIcon); } - public static Toast warning(@NonNull Context context, @NonNull String message) { + public static @CheckResult Toast warning(@NonNull Context context, @NonNull String message) { return warning(context, message, Toast.LENGTH_SHORT, true); } - public static Toast warning(@NonNull Context context, @NonNull String message, int duration) { + public static @CheckResult Toast warning(@NonNull Context context, @NonNull String message, int duration) { return warning(context, message, duration, true); } - public static Toast warning(@NonNull Context context, @NonNull String message, int duration, boolean withIcon) { + public static @CheckResult Toast warning(@NonNull Context context, @NonNull String message, int duration, boolean withIcon) { return custom(context, message, ToastyUtils.getDrawable(context, R.drawable.ic_error_outline_white_48dp), DEFAULT_TEXT_COLOR, WARNING_COLOR, duration, withIcon, true); } - public static Toast info(@NonNull Context context, @NonNull String message) { + public static @CheckResult Toast info(@NonNull Context context, @NonNull String message) { return info(context, message, Toast.LENGTH_SHORT, true); } - public static Toast info(@NonNull Context context, @NonNull String message, int duration) { + public static @CheckResult Toast info(@NonNull Context context, @NonNull String message, int duration) { return info(context, message, duration, true); } - public static Toast info(@NonNull Context context, @NonNull String message, int duration, boolean withIcon) { + public static @CheckResult Toast info(@NonNull Context context, @NonNull String message, int duration, boolean withIcon) { return custom(context, message, ToastyUtils.getDrawable(context, R.drawable.ic_info_outline_white_48dp), DEFAULT_TEXT_COLOR, INFO_COLOR, duration, withIcon, true); } - public static Toast success(@NonNull Context context, @NonNull String message) { + public static @CheckResult Toast success(@NonNull Context context, @NonNull String message) { return success(context, message, Toast.LENGTH_SHORT, true); } - public static Toast success(@NonNull Context context, @NonNull String message, int duration) { + public static @CheckResult Toast success(@NonNull Context context, @NonNull String message, int duration) { return success(context, message, duration, true); } - public static Toast success(@NonNull Context context, @NonNull String message, int duration, boolean withIcon) { + public static @CheckResult Toast success(@NonNull Context context, @NonNull String message, int duration, boolean withIcon) { return custom(context, message, ToastyUtils.getDrawable(context, R.drawable.ic_check_white_48dp), DEFAULT_TEXT_COLOR, SUCCESS_COLOR, duration, withIcon, true); } - public static Toast error(@NonNull Context context, @NonNull String message) { + public static @CheckResult Toast error(@NonNull Context context, @NonNull String message) { return error(context, message, Toast.LENGTH_SHORT, true); } - public static Toast error(@NonNull Context context, @NonNull String message, int duration) { + public static @CheckResult Toast error(@NonNull Context context, @NonNull String message, int duration) { return error(context, message, duration, true); } - public static Toast error(@NonNull Context context, @NonNull String message, int duration, boolean withIcon) { + public static @CheckResult Toast error(@NonNull Context context, @NonNull String message, int duration, boolean withIcon) { return custom(context, message, ToastyUtils.getDrawable(context, R.drawable.ic_clear_white_48dp), DEFAULT_TEXT_COLOR, ERROR_COLOR, duration, withIcon, true); } - public static Toast custom(@NonNull Context context, @NonNull String message, Drawable icon, + public static @CheckResult Toast custom(@NonNull Context context, @NonNull String message, Drawable icon, @ColorInt int textColor, int duration, boolean withIcon) { return custom(context, message, icon, textColor, -1, duration, withIcon, false); } - public static Toast custom(@NonNull Context context, @NonNull String message, @DrawableRes int iconRes, + public static @CheckResult Toast custom(@NonNull Context context, @NonNull String message, @DrawableRes int iconRes, @ColorInt int textColor, @ColorInt int tintColor, int duration, boolean withIcon, boolean shouldTint) { return custom(context, message, ToastyUtils.getDrawable(context, iconRes), textColor, tintColor, duration, withIcon, shouldTint); } - public static Toast custom(@NonNull Context context, @NonNull String message, Drawable icon, + public static @CheckResult Toast custom(@NonNull Context context, @NonNull String message, Drawable icon, @ColorInt int textColor, @ColorInt int tintColor, int duration, boolean withIcon, boolean shouldTint) { - currentToast = new Toast(context); + final Toast currentToast = new Toast(context); final View toastLayout = ((Activity) context).getLayoutInflater().inflate(R.layout.toast_layout, null); final ImageView toastIcon = (ImageView) toastLayout.findViewById(R.id.toast_icon); final TextView toastTextView = (TextView) toastLayout.findViewById(R.id.toast_text); @@ -139,9 +144,11 @@ public static Toast custom(@NonNull Context context, @NonNull String message, Dr drawableFrame = ToastyUtils.getDrawable(context, R.drawable.toast_frame); ToastyUtils.setBackground(toastLayout, drawableFrame); - if (withIcon) + if (withIcon) { + if (icon == null) + throw new IllegalArgumentException("Avoid passing 'icon' as null if 'withIcon' is set to true"); ToastyUtils.setBackground(toastIcon, icon); - else + } else toastIcon.setVisibility(View.GONE); toastTextView.setTextColor(textColor); @@ -152,13 +159,4 @@ public static Toast custom(@NonNull Context context, @NonNull String message, Dr currentToast.setDuration(duration); return currentToast; } - - public static boolean cancel() { - if (currentToast != null) { - currentToast.cancel(); - currentToast = null; - return true; - } - return false; - } } diff --git a/toasty/src/main/java/es/dmoral/toasty/ToastyUtils.java b/toasty/src/main/java/es/dmoral/toasty/ToastyUtils.java index a97f1e2..ba028fa 100644 --- a/toasty/src/main/java/es/dmoral/toasty/ToastyUtils.java +++ b/toasty/src/main/java/es/dmoral/toasty/ToastyUtils.java @@ -13,17 +13,17 @@ /** * This file is part of Toasty. - *

+ * * Toasty is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - *

+ * * Toasty is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - *

+ * * You should have received a copy of the GNU General Public License * along with Toasty. If not, see . */