private void CallOnGlobalLayout(Crouton crouton, View croutonView)
        {
            var layoutListener = new GlobalLayoutListener();

            layoutListener.OnGlobalLayout(delegate
            {
                if (Build.VERSION.SdkInt < Build.VERSION_CODES.JellyBean)
                {
                    croutonView.ViewTreeObserver.RemoveGlobalOnLayoutListener(layoutListener);
                }
                else
                {
                    croutonView.ViewTreeObserver.RemoveOnGlobalLayoutListener(layoutListener);
                }

                if (crouton.GetInAnimation() != null)
                {
                    croutonView.StartAnimation(crouton.GetInAnimation());
                    AnnounceForAccessibilityCompat(crouton.GetActivity(), crouton.GetText());
                    if (Configuration.DURATION_INFINITE != crouton.GetConfiguration().DurationInMilliseconds)
                    {
                        SendMessageDelayed(crouton, Messages.REMOVE_CROUTON,
                                           crouton.GetConfiguration().DurationInMilliseconds + crouton.GetInAnimation().Duration);
                    }
                }
            });
        }
        /**
         * Adds a {@link Crouton} to the {@link ViewParent} of it's {@link Activity}.
         *
         * @param crouton
         *     The {@link Crouton} that should be added.
         */

        private void AddCroutonToView(Crouton crouton)
        {
            // don't Add if it is already showing
            if (crouton.IsShowing())
            {
                return;
            }

            View croutonView = crouton.GetView();

            if (null == croutonView.Parent)
            {
                ViewGroup.LayoutParams parameters = croutonView.LayoutParameters;
                if (null == parameters)
                {
                    parameters = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                                  ViewGroup.LayoutParams.WrapContent);
                }
                // display Crouton in ViewGroup is it has been supplied
                if (null != crouton.GetViewGroup())
                {
                    ViewGroup croutonViewGroup = crouton.GetViewGroup();
                    if (ShouldAddViewWithoutPosition(croutonViewGroup))
                    {
                        croutonViewGroup.AddView(croutonView, parameters);
                    }
                    else
                    {
                        croutonViewGroup.AddView(croutonView, 0, parameters);
                    }
                }
                else
                {
                    Activity activity = crouton.GetActivity();
                    if (null == activity || activity.IsFinishing)
                    {
                        return;
                    }
                    HandleTranslucentActionBar((ViewGroup.MarginLayoutParams)parameters, activity);
                    HandleActionBarOverlay((ViewGroup.MarginLayoutParams)parameters, activity);

                    activity.AddContentView(croutonView, parameters);
                }
            }

            croutonView.RequestLayout(); // This is needed so the animation can use the measured with/height
            ViewTreeObserver observer = croutonView.ViewTreeObserver;

            if (null != observer)
            {
                CallOnGlobalLayout(crouton, croutonView);
            }
        }
        /**
         * Removes a {@link Crouton} immediately, even when it's currently being
         * displayed.
         *
         * @param crouton
         *     The {@link Crouton} that should be removed.
         */

        public void RemoveCroutonImmediately(Crouton crouton)
        {
            // if Crouton has already been displayed then it may not be in the queue (because it was popped).
            // This ensures the displayed Crouton is removed from its parent immediately, whether another instance
            // of it exists in the queue or not.
            // Note: crouton.IsShowing() is false here even if it really is showing, as croutonView object in
            // Crouton seems to be out of sync with reality!
            if (null != crouton.GetActivity() && null != crouton.GetView() && null != crouton.GetView().Parent)
            {
                ((ViewGroup)crouton.GetView().Parent).RemoveView(crouton.GetView());

                // remove any messages pending for the crouton
                RemoveAllMessagesForCrouton(crouton);
            }
            // remove any matching croutons from queue
            IIterator croutonIterator = croutonQueue.Iterator();

            while (croutonIterator.HasNext)
            {
                var c = croutonIterator.Next().JavaCast <Crouton>();
                if (c.Equals(crouton) && (null != c.GetActivity()))
                {
                    // remove the crouton from the content view
                    RemoveCroutonFromViewParent(crouton);

                    // remove any messages pending for the crouton
                    RemoveAllMessagesForCrouton(c);

                    // remove the crouton from the queue
                    croutonIterator.Remove();

                    // we have found our crouton so just break
                    break;
                }
            }
        }