Ejemplo n.º 1
0
        private void SendMessageDelayed(Crouton crouton, Int64 messageId, long delay)
        {
            Message message = ObtainMessage((int)messageId);

            message.Obj = crouton;
            SendMessageDelayed(message, delay);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        private void SendMessage(Crouton crouton, int messageId)
        {
            Message message = ObtainMessage(messageId);

            message.Obj = crouton;
            SendMessage(message);
        }
Ejemplo n.º 4
0
 private long CalculateCroutonDuration(Crouton crouton)
 {
     long croutonDuration = crouton.DurationInMilliseconds;
     croutonDuration += crouton.GetInAnimation().Duration;
     croutonDuration += crouton.GetOutAnimation().Duration;
     return croutonDuration;
 }
Ejemplo n.º 5
0
        private long CalculateCroutonDuration(Crouton crouton)
        {
            long croutonDuration = crouton.DurationInMilliseconds;

            croutonDuration += crouton.GetInAnimation().Duration;
            croutonDuration += crouton.GetOutAnimation().Duration;
            return(croutonDuration);
        }
        public Task<bool> Notify(ToastNotificationType type, string title, string description, TimeSpan duration, object context = null, bool clickable = true)
        {
            var taskCompletionSource = new TaskCompletionSource<bool>();
            
            Activity currentActivity = _context as Activity;
            if (currentActivity == null)
                return Task.FromResult(false);

            View view = _customRenderer.Render(currentActivity, type, title, description, context);
            Crouton crouton = new Crouton(currentActivity, view, (int)duration.TotalMilliseconds, 
                b =>
                {
                    if (clickable)
                    {
                        taskCompletionSource.TrySetResult(b);
                    }
                }, context);
            crouton.Show();
            return taskCompletionSource.Task;
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
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));
            }

            View view = _customRenderer.Render(_activity, type, title, description, context);

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

            crouton.Show();
            return(taskCompletionSource.Task);
        }
Ejemplo n.º 9
0
        private void CallOnGlobalLayout(Crouton crouton, View croutonView)
        {
            var layoutListener = new GlobalLayoutListener();

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

                if (crouton.GetInAnimation() != null)
                {
                    croutonView.StartAnimation(crouton.GetInAnimation());
                    AnnounceForAccessibilityCompat(crouton.GetActivity(), crouton.DataContext == null ? "NULL" : crouton.DataContext.ToString());
                    SendMessageDelayed(crouton, REMOVE_CROUTON,
                                       crouton.DurationInMilliseconds + crouton.GetInAnimation().Duration);
                }
            });
        }
Ejemplo n.º 10
0
 public void Add(Crouton crouton)
 {
     _croutonQueue.Add(crouton);
     DisplayCrouton();
 }
Ejemplo n.º 11
0
 private void SendMessageDelayed(Crouton crouton, Int64 messageId, long delay)
 {
     Message message = ObtainMessage((int) messageId);
     message.Obj = crouton;
     SendMessageDelayed(message, delay);
 }
Ejemplo n.º 12
0
 private void SendMessage(Crouton crouton, int messageId)
 {
     Message message = ObtainMessage(messageId);
     message.Obj = crouton;
     SendMessage(message);
 }
Ejemplo n.º 13
0
 public void Add(Crouton crouton)
 {
     _croutonQueue.Add(crouton);
     DisplayCrouton();
 }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
0
        private void CallOnGlobalLayout(Crouton crouton, View croutonView)
        {
            var layoutListener = new GlobalLayoutListener();
            layoutListener.OnGlobalLayout(delegate
            {
                if (Build.VERSION.SdkInt < BuildVersionCodes.JellyBean)
                {
                    croutonView.ViewTreeObserver.RemoveGlobalOnLayoutListener(layoutListener);
                }
                else
                {
                    croutonView.ViewTreeObserver.RemoveOnGlobalLayoutListener(layoutListener);
                }

                if (crouton.GetInAnimation() != null)
                {
                    croutonView.StartAnimation(crouton.GetInAnimation());
                    AnnounceForAccessibilityCompat(crouton.GetActivity(), crouton.DataContext == null ? "NULL" : crouton.DataContext.ToString());
                    SendMessageDelayed(crouton, REMOVE_CROUTON,
                    crouton.DurationInMilliseconds + crouton.GetInAnimation().Duration);
                }
            });
        }
Ejemplo n.º 16
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);
            }
        }