Skip to content

Commit

Permalink
v.1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GrenderG committed Jan 19, 2017
1 parent 49ef88a commit 6b37d9b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.)**

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/es/dmoral/toastysample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

/**
* This file is part of Toasty.
* <p>
*
* 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.
* <p>
*
* 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.
* <p>
*
* You should have received a copy of the GNU General Public License
* along with Toasty. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down
6 changes: 3 additions & 3 deletions toasty/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"

Expand Down
70 changes: 34 additions & 36 deletions toasty/src/main/java/es/dmoral/toasty/Toasty.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,21 +17,22 @@

/**
* This file is part of Toasty.
* <p>
*
* 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.
* <p>
*
* 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.
* <p>
*
* You should have received a copy of the GNU General Public License
* along with Toasty. If not, see <http://www.gnu.org/licenses/>.
*/

@SuppressLint("InflateParams")
public class Toasty {
private static final @ColorInt int DEFAULT_TEXT_COLOR = Color.parseColor("#FFFFFF");

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
}
6 changes: 3 additions & 3 deletions toasty/src/main/java/es/dmoral/toasty/ToastyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

/**
* This file is part of Toasty.
* <p>
*
* 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.
* <p>
*
* 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.
* <p>
*
* You should have received a copy of the GNU General Public License
* along with Toasty. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down

0 comments on commit 6b37d9b

Please sign in to comment.