Exemplo n.º 1
0
        private void sendMessageDelayed(Crouton crouton, Int64 messageId, long delay)
        {
            var message = ObtainMessage((int)messageId);

            message.Obj = crouton;
            SendMessageDelayed(message, delay);
        }
Exemplo n.º 2
0
        public void RemoveCrouton(Crouton crouton)
        {
            var croutonView       = crouton.GetView();
            var croutonParentView = (ViewGroup)croutonView.Parent;

            if (null == croutonParentView)
            {
                return;
            }
            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);
        }
Exemplo n.º 3
0
        private void sendMessage(Crouton crouton, int messageId)
        {
            var message = ObtainMessage(messageId);

            message.Obj = crouton;
            SendMessage(message);
        }
Exemplo n.º 4
0
        private void callOnGlobalLayout(Crouton crouton, View croutonView)
        {
            var layoutListener = new GlobalLayoutListener();

            layoutListener.OnGlobalLayout(delegate
            {
                if (Build.VERSION.SdkInt < BuildVersionCodes.JellyBean)
                {
#pragma warning disable 618
                    croutonView?.ViewTreeObserver?.RemoveGlobalOnLayoutListener(layoutListener);
#pragma warning restore 618
                }
                else
                {
                    croutonView?.ViewTreeObserver?.RemoveOnGlobalLayoutListener(layoutListener);
                }

                if (crouton.GetInAnimation() == null)
                {
                    return;
                }
                croutonView?.StartAnimation(crouton.GetInAnimation());
                AnnounceForAccessibilityCompat(crouton.GetActivity(), crouton.DataContext?.ToString() ?? "NULL");
                sendMessageDelayed(crouton, REMOVE_CROUTON,
                                   crouton.DurationInMilliseconds + crouton.GetInAnimation().Duration);
            });
        }
Exemplo n.º 5
0
        private void addCroutonToView(Crouton crouton)
        {
            // don't Add if it is already showing
            if (crouton.IsShowing())
            {
                return;
            }

            var croutonView = crouton.GetView();

            if (null == croutonView.Parent)
            {
                var parameters = croutonView.LayoutParameters ?? new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                                                                  ViewGroup.LayoutParams.WrapContent);

                var 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
            var observer = croutonView.ViewTreeObserver;

            if (null != observer)
            {
                callOnGlobalLayout(crouton, croutonView);
            }
        }
Exemplo n.º 6
0
        private long CalculateCroutonDuration(Crouton crouton)
        {
            long croutonDuration = crouton.DurationInMilliseconds;

            croutonDuration += crouton.GetInAnimation().Duration;
            croutonDuration += crouton.GetOutAnimation().Duration;
            return(croutonDuration);
        }
Exemplo n.º 7
0
        public Task <bool> Notify(ToastNotificationType type, string title, string description, TimeSpan duration, object context = null, bool clickable = true)
        {
            var taskCompletionSource = new TaskCompletionSource <bool>();

            if (activity == null)
            {
                return(Task.FromResult(false));
            }

            var view = customRenderer.Render(activity, type, title, description, context);

            var crouton = new Crouton(activity, view, (int)duration.TotalMilliseconds,
                                      b =>
            {
                if (clickable)
                {
                    taskCompletionSource.TrySetResult(b);
                }
            }, context);

            crouton.Show();
            return(taskCompletionSource.Task);
        }
Exemplo n.º 8
0
 public void Add(Crouton crouton)
 {
     croutonQueue.Add(crouton);
     displayCrouton();
 }