Ejemplo n.º 1
0
  /** Hide and remove the XActivityToast */
  void removeSuperToast(final XActivityToast xActivityToast) {

    /* If XActivityToast has been dismissed before it shows, do not attempt to show it */
    if (!xActivityToast.isShowing()) {

      mList.remove(xActivityToast);

      return;
    }

    /* If being called somewhere else get rid of delayed remove message */
    removeMessages(Messages.REMOVE, xActivityToast);

    final ViewGroup viewGroup = xActivityToast.getViewGroup();

    final View toastView = xActivityToast.getView();

    if (viewGroup != null) {

      Animation animation = getDismissAnimation(xActivityToast);

      animation.setAnimationListener(
          new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

              /* Do nothing */

            }

            @Override
            public void onAnimationEnd(Animation animation) {

              if (xActivityToast.getOnDismissWrapper() != null) {

                xActivityToast.getOnDismissWrapper().onDismiss(xActivityToast.getView());
              }

              /* Show the XActivityToast next in the list if any exist */
              ManagerXActivityToast.this.showNextSuperToast();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

              /* Do nothing */

            }
          });

      toastView.startAnimation(animation);

      viewGroup.removeView(toastView);

      mList.poll();
    }
  }
Ejemplo n.º 2
0
  /**
   * 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);
    }
  }
Ejemplo n.º 3
0
  /** Removes all SuperActivityToasts and clears the list */
  void cancelAllSuperActivityToasts() {

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

    for (XActivityToast xActivityToast : mList) {

      if (xActivityToast.isShowing()) {

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

        xActivityToast.getViewGroup().invalidate();
      }
    }

    mList.clear();
  }
Ejemplo n.º 4
0
  /** 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();
      }
    }
  }
Ejemplo n.º 5
0
  /** 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());
    }
  }