コード例 #1
0
 private void RemoveCroutonFromViewParent(Crouton crouton)
 {
     if (crouton.IsShowing())
     {
         var parent = (ViewGroup)crouton.GetView().Parent;
         if (null != parent)
         {
             parent.RemoveView(crouton.GetView());
         }
     }
 }
コード例 #2
0
        /**
         * Removes the {@link Crouton}'s view after it's display
         * DurationInMilliseconds.
         *
         * @param crouton
         *     The {@link Crouton} added to a {@link ViewGroup} and should be
         *     removed.
         */

        public void RemoveCrouton(Crouton crouton)
        {
            View croutonView       = crouton.GetView();
            var  croutonParentView = (ViewGroup)croutonView.Parent;

            if (null != croutonParentView)
            {
                croutonView.StartAnimation(crouton.GetOutAnimation());

                // Remove the Crouton from the queue.
                var removed = (Crouton)croutonQueue.Poll();

                // Remove the crouton from the view's parent.
                croutonParentView.RemoveView(croutonView);
                if (null != removed)
                {
                    removed.DetachActivity();
                    removed.DetachViewGroup();
                    if (null != removed.GetLifecycleCallback())
                    {
                        removed.GetLifecycleCallback().OnRemoved();
                    }
                    removed.DetachLifecycleCallback();
                }

                // Send a message to display the next crouton but delay it by the out
                // animation duration to Make sure it finishes
                SendMessageDelayed(crouton, Messages.DISPLAY_CROUTON, crouton.GetOutAnimation().Duration);
            }
        }
コード例 #3
0
        /**
         * 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);
            }
        }
コード例 #4
0
        /**
         * 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;
                }
            }
        }