Beispiel #1
0
        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.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, DISPLAY_CROUTON, crouton.GetOutAnimation().Duration);
            }
        }
Beispiel #2
0
        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);
                }

                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);
            }
        }