/* Cancels/removes all showing pending SuperToasts */
  protected void cancelAllSuperToasts() {

    removeMessages(Messages.ADD_SUPERTOAST);
    removeMessages(Messages.DISPLAY_SUPERTOAST);
    removeMessages(Messages.REMOVE_SUPERTOAST);

    for (SuperToast superToast : mQueue) {

      if (superToast.isShowing()) {

        superToast.getWindowManager().removeView(superToast.getView());
      }
    }

    mQueue.clear();
  }
  /* Get duration and add one second to compensate for show/hide animations */
  private long getDuration(SuperToast superToast) {

    long duration = superToast.getDuration();
    duration += 1000;

    return duration;
  }
  /* Hide and remove the SuperToast */
  protected void removeSuperToast(SuperToast superToast) {

    final WindowManager windowManager = superToast.getWindowManager();

    final View toastView = superToast.getView();

    if (windowManager != null) {

      mQueue.poll();

      windowManager.removeView(toastView);

      sendMessageDelayed(superToast, Messages.DISPLAY_SUPERTOAST, 500);

      if (superToast.getOnDismissListener() != null) {

        superToast.getOnDismissListener().onDismiss(superToast.getView());
      }
    }
  }
  /* Displays a SuperToast */
  private void displaySuperToast(SuperToast superToast) {

    if (superToast.isShowing()) {

      /* If the SuperToast is already showing do not show again */

      return;
    }

    final WindowManager windowManager = superToast.getWindowManager();

    final View toastView = superToast.getView();

    final WindowManager.LayoutParams params = superToast.getWindowManagerParams();

    if (windowManager != null) {

      windowManager.addView(toastView, params);
    }

    sendMessageDelayed(superToast, Messages.REMOVE_SUPERTOAST, superToast.getDuration() + 500);
  }
  /* Shows the next SuperToast in the list */
  private void showNextSuperToast() {

    if (mQueue.isEmpty()) {

      /* There is no SuperToast to display next */

      return;
    }

    /* Get next SuperToast in the queue */
    final SuperToast superToast = mQueue.peek();

    /* Show SuperToast if none are showing (not sure why this works but it does) */
    if (!superToast.isShowing()) {

      final Message message = obtainMessage(Messages.ADD_SUPERTOAST);
      message.obj = superToast;
      sendMessage(message);

    } else {

      sendMessageDelayed(superToast, Messages.DISPLAY_SUPERTOAST, getDuration(superToast));
    }
  }