/** Removes all SuperActivityToasts and clears the list for a specific activity */
  void cancelAllSuperActivityToastsForActivity(Activity activity) {

    Iterator<XActivityToast> superActivityToastIterator = mList.iterator();

    while (superActivityToastIterator.hasNext()) {

      XActivityToast xActivityToast = superActivityToastIterator.next();

      if ((xActivityToast.getActivity()) != null && xActivityToast.getActivity().equals(activity)) {

        if (xActivityToast.isShowing()) {

          xActivityToast.getViewGroup().removeView(xActivityToast.getView());
        }

        removeMessages(Messages.DISPLAY, xActivityToast);
        removeMessages(Messages.REMOVE, xActivityToast);

        superActivityToastIterator.remove();
      }
    }
  }
  /**
   * Shows the next XActivityToast in the list. Called by add() and when the dismiss animation of a
   * previously showing XActivityToast ends.
   */
  private void showNextSuperToast() {

    final XActivityToast xActivityToast = mList.peek();

    if (mList.isEmpty() || xActivityToast.getActivity() == null) {

      return;
    }

    if (!xActivityToast.isShowing()) {

      final Message message = obtainMessage(Messages.DISPLAY);
      message.obj = xActivityToast;
      sendMessage(message);
    }
  }
  /** Displays a XActivityToast. */
  private void displaySuperToast(XActivityToast xActivityToast) {

    /* If this XActivityToast is somehow already showing do nothing */
    if (xActivityToast.isShowing()) {

      return;
    }

    final ViewGroup viewGroup = xActivityToast.getViewGroup();

    final View toastView = xActivityToast.getView();

    if (viewGroup != null) {

      try {

        viewGroup.addView(toastView);

        if (!xActivityToast.getShowImmediate()) {

          toastView.startAnimation(getShowAnimation(xActivityToast));
        }

      } catch (IllegalStateException e) {

        this.cancelAllSuperActivityToastsForActivity(xActivityToast.getActivity());
      }
    }

    /* Dismiss the XActivityToast at the set duration time unless indeterminate */
    if (!xActivityToast.isIndeterminate()) {

      Message message = obtainMessage(Messages.REMOVE);
      message.obj = xActivityToast;
      sendMessageDelayed(
          message, xActivityToast.getDuration() + getShowAnimation(xActivityToast).getDuration());
    }
  }