/** * Removes all SuperActivityToasts and clears the list */ void cancelAllSuperActivityToasts() { removeMessages(Messages.DISPLAY); removeMessages(Messages.REMOVE); for (SuperActivityToast superActivityToast : mList) { if (superActivityToast.isShowing()) { superActivityToast.getViewGroup().removeView( superActivityToast.getView()); superActivityToast.getViewGroup().invalidate(); } } mList.clear(); }
/** * Removes all SuperActivityToasts and clears the list for a specific activity */ void cancelAllSuperActivityToastsForActivity(Activity activity) { Iterator<SuperActivityToast> superActivityToastIterator = mList .iterator(); while (superActivityToastIterator.hasNext()) { SuperActivityToast superActivityToast = superActivityToastIterator .next(); if ((superActivityToast.getActivity()) != null && superActivityToast.getActivity().equals(activity)) { if (superActivityToast.isShowing()) { superActivityToast.getViewGroup().removeView( superActivityToast.getView()); } removeMessages(Messages.DISPLAY, superActivityToast); removeMessages(Messages.REMOVE, superActivityToast); superActivityToastIterator.remove(); } } }
final ViewGroup viewGroup = superActivityToast.getViewGroup();
/** * Displays a SuperActivityToast. */ private void displaySuperToast(SuperActivityToast superActivityToast) { /* If this SuperActivityToast is somehow already showing do nothing */ if(superActivityToast.isShowing()) { return; } final ViewGroup viewGroup = superActivityToast.getViewGroup(); final View toastView = superActivityToast.getView(); if(viewGroup != null) { try { viewGroup.addView(toastView); if(!superActivityToast.getShowImmediate()) { toastView.startAnimation(getShowAnimation(superActivityToast)); } } catch(IllegalStateException e) { this.cancelAllSuperActivityToastsForActivity(superActivityToast.getActivity()); } } /* Dismiss the SuperActivityToast at the set duration time unless indeterminate */ if(!superActivityToast.isIndeterminate()) { Message message = obtainMessage(Messages.REMOVE); message.obj = superActivityToast; sendMessageDelayed(message, superActivityToast.getDuration() + getShowAnimation(superActivityToast).getDuration()); } }