/* 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(); }
/* 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)); } }