Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Version 2.0 feature showcase

John Persano edited this page Feb 13, 2015 · 2 revisions

Are you finished checking out the migration page? If so, check out the following new features and code practices introduced in version 2.0.

Method chaining

Thanks to his feature request, Github user akohout convinced me to return the current instance from the setter methods. This means you can invoke multiple method calls in a row on a single SuperToast or SuperActivityToast object. Check out the example of a simple SuperToast below.

new SuperToast(MainActivity.this)
    .setText("Something something SuperToast.")
    .setDuration(Style.DURATION_SHORT)
    .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
    .setAnimations(Style.ANIMATIONS_POP)
    .show();

I should warn you that there is a specific order to the methods you can chain when using a SuperActivityToast. Use any methods specific to a SuperActivityToast first. Since SuperActivityToasts extend SuperToasts, they share basic methods. SuperToast methods will return a SuperToast instance which are not compatible with methods specifically designed for SuperActivityToasts.

new SuperActivityToast(MainActivity.this, Style.green(), Style.TYPE_PROGRESS_BAR)
    .setProgressIndeterminate(true) //SuperActivityToast method
    .setIndeterminate(true) //SuperActivityToast method
    .setText("I am a SuperActivityToast") //SuperToast method
    .setDuration(Style.DURATION_LONG) //SuperToast method
    .show();

SDK specific frames

In version 1.3.4 of the library, the frame (or background shape) was set accordingly depending on the device's SDK level. With version 2.0, it still is! The difference is that now you can explicitly request a specific frame to be used with a SuperToast or SuperActivityToast. Of course, setting the frame explicitly will mean that the library will no longer choose a frame based on the device's SDK level.

new SuperToast(MainActivity.this)
   .setText("Don't frame me for this!")
   .setDuration(Style.DURATION_SHORT)
   .setFrame(Style.FRAME_STANDARD)
//  .setFrame(Style.FRAME_KITKAT)
//  .setFrame(Style.FRAME_LOLLIPOP)
   .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
   .show();

Priority colors

Borrowing a page from the Crouton book, you can use a method to add a colored border to signify the "priority level" of the message.

new SuperToast(MainActivity.this)
    .setText("This must be a good message if its green.")
    .setDuration(Style.DURATION_LONG)
    .setFrame(Style.FRAME_LOLLIPOP)
    .setColor(PaletteUtils.getTransparentColor(PaletteUtils.DARK_GREY))
    .setPriorityColor(PaletteUtils.getTransparentColor(PaletteUtils.MATERIAL_GREEN))
    .show();

Palette utility class

If you need a background color for anything, either transparent or solid, check out the PaletteUtils class.

PaletteUtils.getTransparentColor(PaletteUtils.MATERIAL_DEEP_ORANGE)

Or:

PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_TEAL)

I added a bunch of Material design constants that were copied directly from Google's webpage. Try to stick with transparent colors for backgrounds and solid colors for text.