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

SuperActivityToast

John Persano edited this page Aug 1, 2013 · 22 revisions

SuperActivityToasts

Introduction

SuperActivityToasts are made to replace stock Android Toasts that are used in an Activity Context. SuperActivityToasts can NOT be used in a non-Activity Context.

Usage

SuperActivityToasts should be used wherever an Activity Context is available. SuperActivityToasts attach themselves to the Activity's content meaning that the SuperActivityToast will not linger from screen to screen. When the Activity's content gets destroyed the SuperActivityToast gets destroyed along with it, eliminating out of Context messages. There are four types of SuperActivityToasts: STANDARD, BUTTON, PROGRESS, and PROGRESS_HORIZONTAL.

Features

  1. Customization options such as background color, font, text size, etc.
  2. Duration can be any millisecond value.
  3. Developers can choose between any animation.
  4. An Image can be displayed along with the SuperActivityToast.
  5. SuperActivityToasts can have an OnClickListener attached to them.
  6. Touch to dismiss function.
  7. SuperActivityToasts are attached to the Activity's content, not the WindowManager.
  8. Four variations.

Examples

To create a simple SuperActivityToast developers can create a new object.

 SuperActivityToast superActivityToast = new SuperActivityToast(this);  
 superActivityToast.setDuration(SuperToast.DURATION_LONG);  
 superActivityToast.setText("Hello world!");  
 superActivityToast.show();  

Developers can also use a static method.

 SuperActivityToast.createDarkSuperActivityToast(this, "Hello world!", SuperToast.DURATION_LONG).show();  

To style a SuperActivityToast developers will have to create a new object.

 SuperActivityToast superActivityToast = new SuperActivityToast(this, SuperToast.Type.STANDARD);  
 superActivityToast.setDuration(SuperToast.DURATION_LONG);  
 superActivityToast.setShowAnimation(mShowAnimation);  
 superActivityToast.setDismissAnimation(mDismissAnimation);  
 superActivityToast.setBackgroundResource(SuperToast.BACKGROUND_BLUETRANSLUCENT);  
 superActivityToast.setTextColor(Color.WHITE);  
 superActivityToast.setTextSize(SuperToast.TEXTSIZE_MEDIUM);  
 superActivityToast.setText("Hello world!");  
 superActivityToast.setIconResource(R.drawable.image, SuperToast.IconPosition.LEFT);
 superActivityToast.setTouchToDismiss(true);  
 superActivityToast.show();  

Important note

If a SuperActivityToast is showing when an Intent to another Activity is started the SuperActivityToast may linger upon return to the previous Activity. To remedy this developers have two options.

Developers may call this in the Activity that calls the Intent.

 @Override  
public void onPause() {  
  super.onPause();  
   
  /* Don't let the SuperActivityToast linger */  
  SuperActivityToast.cancelAllSuperActivityToasts();  
   
}  

Or call the same method before starting the Intent.

 /* Don't let the SuperActivityToast linger */  
 SuperActivityToast.cancelAllSuperActivityToasts();  
 startActivity(new Intent(ActivityOne.this, ActivityTwo.class));  
Clone this wiki locally