-
Notifications
You must be signed in to change notification settings - Fork 500
SuperCardToast
##Introduction SuperCardToasts are made to augment the stock Android Toast class. The idea for this SuperToast came from Benjamin Weiss's Crouton library.
SuperCardToasts should be used wherever an Activity context is available.
SuperCardToasts can NOT be used in a non-Activity context.
SuperCardToasts offer a new way of showing toast messages.
SuperCardToasts attach themselves to the activity's content and will not linger from activity to activity.
SuperCardToasts can have buttons, progressbars, and icons.
- Customization options such as background color, font, text size, animations etc.
- SuperCardToasts are stackable.
- Swipe/touch to dismiss options.
- Does not hide any of the activity's existing content.
- Duration can be any millisecond value.
- Orientation change support
You must place this layout in the top of your activity's layout. This is where SuperCardToasts will be attached. If you are using fragments you should put this at the top of your host activity's layout. Try setting the background color of this layout to match your ActionBar.
<LinearLayout
android:id="@+id/card_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#15000000"
android:orientation="vertical" />
SuperCardToast.create(Activity.this, "Hello world!", SuperToast.Duration.LONG).show();
SuperCardToast.create(Playground.this, "Hello world!", SuperToast.Duration.SHORT,
Style.getStyle(Style.BLUE, SuperToast.Animations.FLYIN)).show();
A SuperCardToast displaying the text "Hello world!" with a different background, text color, and will dismiss if the user swipes it.
SuperCardToast superCardToast = new SuperCardToast(Activity.this);
superCardToast.setText("Hello world!");
superCardToast.setDuration(SuperToast.Duration.LONG);
superCardToast.setBackground(SuperToast.Background.PURPLE);
superCardToast.setTextColor(Color.WHITE);
superCardToast.setSwipeToDismiss(true);
superCardToast.show();
An indeterminate SuperCardToast displaying the text "Hello world!" with an indeterminate progressbar.
SuperCardToast superCardToast = new SuperCardToast(Activity.this, SuperToast.Type.PROGRESS);
superCardToast.setText("Hello world!");
superCardToast.setIndeterminate(true);
superCardToast.setProgressIndeterminate(true);
superCardToast.show();
SuperCardToast superCardToast = new SuperCardToast(Activity.this, SuperToast.Type.BUTTON));
superCardToast.setDuration(SuperToast.Duration.EXTRA_LONG);
superCardToast.setText("Some action performed.");
superCardToast.setButtonIcon(SuperToast.Icon.Dark.UNDO, "UNDO");
superCardToast.setOnClickWrapper(onClickWrapper);
superCardToast.show();
To use the button in BUTTON type SuperCardToasts, define an OnClickWrapper somewhere in your Activity.
The first parameter is a string tag unique to this OnClickWrapper, the second parameter is the OnClickListener.
OnClickWrapper onClickWrapper = new OnClickWrapper("supercardtoast", new SuperToast.OnClickListener() {
@Override
public void onClick(View view, Parcelable token) {
/** On click event */
}
});
To have SuperCardToasts retain themselves on orientation change add this code to your Activity.
If you do not call SuperCardToast.onSaveState() you may have lingering SuperCardToasts when a new Activity is started on top of a showing SuperCardToast.
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
SuperCardToast.onSaveState(outState);
}
Also, add this restore method to the onCreate of your Activity if you are NOT using any OnClickWrappers/OnDismissWrapers.
SuperCardToast.onRestoreState(savedInstanceState, Activity.this);
If you ARE using any OnClickWrappers/OnDismissWrapers you must use the following code instead.
The Wrappers object helps to reattach any OnClickWrappers/OnDismissWrapers on orientation change so any OnClickWrappers/OnDismissWrapers used must be added to it.
Wrappers wrappers = new Wrappers();
wrappers.add(onClickWrapper);
SuperCardToast.onRestoreState(Activity.this, savedInstanceState, wrappers);