/** * Shows the next SuperActivityToast in the list. Called by add() and when the dismiss animation * of a previously showing SuperActivityToast ends. */ private void showNextSuperToast() { final SuperActivityToast superActivityToast = mList.peek(); if (mList.isEmpty() || superActivityToast.getActivity() == null) { return; } if (!superActivityToast.isShowing()) { final Message message = obtainMessage(Messages.DISPLAY); message.obj = superActivityToast; sendMessage(message); } }
/** * 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(); } } }
/** * 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()); } }