Skip to content

Commit

Permalink
Removed tintColor from usual Toasty method calls and added an example…
Browse files Browse the repository at this point in the history
… of custom config.
  • Loading branch information
GrenderG committed Apr 27, 2017
1 parent 109607a commit 8d70191
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 86 deletions.
Binary file added app/src/main/assets/PCap Terminal.otf
Binary file not shown.
12 changes: 12 additions & 0 deletions app/src/main/java/es/dmoral/toastysample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ public void onClick(View view) {
Toasty.info(MainActivity.this, getFormattedMessage()).show();
}
});
findViewById(R.id.button_custom_config).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toasty.Config.getInstance()
.setTextColor(Color.GREEN)
.setToastTypeface(getAssets(), "PCap Terminal.otf")
.apply();
Toasty.custom(MainActivity.this, "sudo kill -9 everyone", getResources().getDrawable(R.drawable.laptop512),
Color.BLACK, Toast.LENGTH_SHORT, true, true).show();
Toasty.Config.reset(); // Use this if you want to use the configuration above only once
}
});
}

private CharSequence getFormattedMessage() {
Expand Down
Binary file added app/src/main/res/drawable/laptop512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 91 additions & 75 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,90 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="es.dmoral.toastysample.MainActivity">

<Button
android:text="@string/error_toast"
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_error_toast"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">

<Button
android:text="@string/success_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_error_toast"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_success_toast"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="@string/error_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_error_toast"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
android:text="@string/info_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_success_toast"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_info_toast"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="@string/success_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_error_toast"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_success_toast"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
android:text="@string/info_toast_with_formatting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button_info_toast"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_info_toast_with_formatting"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="@string/info_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_success_toast"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_info_toast"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
android:text="@string/warning_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_info_toast_with_formatting"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/button_warning_toast" />
<Button
android:text="@string/info_toast_with_formatting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button_info_toast"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_info_toast_with_formatting"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
android:text="@string/normal_toast_without_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_warning_toast"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_normal_toast_wo_icon"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="@string/warning_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_info_toast_with_formatting"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/button_warning_toast" />

<Button
android:text="@string/normal_toast_with_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_normal_toast_wo_icon"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_normal_toast_w_icon"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="@string/normal_toast_without_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_warning_toast"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_normal_toast_wo_icon"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
android:text="@string/normal_toast_with_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_normal_toast_wo_icon"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_normal_toast_w_icon"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
android:text="@string/custom_configuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_normal_toast_w_icon"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/button_custom_config"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

</RelativeLayout>
</RelativeLayout>
</ScrollView>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<string name="info_toast_with_formatting">INFO TOAST WITH FORMATTING</string>
<string name="error_toast">ERROR TOAST</string>
<string name="success_toast">SUCCESS TOAST</string>
<string name="custom_configuration">CUSTOM CONFIGURATION</string>
</resources>
22 changes: 11 additions & 11 deletions toasty/src/main/java/es/dmoral/toasty/Toasty.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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, DEFAULT_TEXT_COLOR, duration, withIcon);
return custom(context, message, icon, duration, withIcon);
}

@CheckResult
Expand All @@ -93,7 +93,7 @@ public static Toast warning(@NonNull Context context, @NonNull CharSequence mess
@CheckResult
public static Toast warning(@NonNull Context context, @NonNull CharSequence 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);
WARNING_COLOR, duration, withIcon, true);
}

@CheckResult
Expand All @@ -109,7 +109,7 @@ public static Toast info(@NonNull Context context, @NonNull CharSequence message
@CheckResult
public static Toast info(@NonNull Context context, @NonNull CharSequence 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);
INFO_COLOR, duration, withIcon, true);
}

@CheckResult
Expand All @@ -125,7 +125,7 @@ public static Toast success(@NonNull Context context, @NonNull CharSequence mess
@CheckResult
public static Toast success(@NonNull Context context, @NonNull CharSequence 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);
SUCCESS_COLOR, duration, withIcon, true);
}

@CheckResult
Expand All @@ -141,26 +141,26 @@ public static Toast error(@NonNull Context context, @NonNull CharSequence messag
@CheckResult
public static Toast error(@NonNull Context context, @NonNull CharSequence 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);
ERROR_COLOR, duration, withIcon, true);
}

@CheckResult
public static Toast custom(@NonNull Context context, @NonNull CharSequence message, Drawable icon,
@ColorInt int textColor, int duration, boolean withIcon) {
return custom(context, message, icon, textColor, -1, duration, withIcon, false);
int duration, boolean withIcon) {
return custom(context, message, icon, -1, duration, withIcon, false);
}

@CheckResult
public static Toast custom(@NonNull Context context, @NonNull CharSequence message, @DrawableRes int iconRes,
@ColorInt int textColor, @ColorInt int tintColor, int duration,
@ColorInt int tintColor, int duration,
boolean withIcon, boolean shouldTint) {
return custom(context, message, ToastyUtils.getDrawable(context, iconRes), textColor,
return custom(context, message, ToastyUtils.getDrawable(context, iconRes),
tintColor, duration, withIcon, shouldTint);
}

@CheckResult
public static Toast custom(@NonNull Context context, @NonNull CharSequence message, Drawable icon,
@ColorInt int textColor, @ColorInt int tintColor, int duration,
@ColorInt int tintColor, int duration,
boolean withIcon, boolean shouldTint) {
final Toast currentToast = new Toast(context);
final View toastLayout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
Expand All @@ -182,7 +182,7 @@ public static Toast custom(@NonNull Context context, @NonNull CharSequence messa
} else
toastIcon.setVisibility(View.GONE);

toastTextView.setTextColor(textColor);
toastTextView.setTextColor(DEFAULT_TEXT_COLOR);
toastTextView.setText(message);
if (assetManager == null)
toastTextView.setTypeface(Typeface.create(TOAST_TYPEFACE, Typeface.NORMAL));
Expand Down

0 comments on commit 8d70191

Please sign in to comment.