Esempio n. 1
0
        public void OnNotificationRemoved(OpenNotification sbn)
        {
            if (sbn.GetPackage() == "android" && sbn.GetTag() == "com.android.server.wm.AlertWindowNotification - com.underground.livedisplay")
            {
                return;
            }

            if (sbn.IsSummary())
            {
                return; //Ignore the summary notification.
            }
            int position = GetNotificationPosition(sbn);
            OpenNotification notificationToBeRemoved = null;

            if (position >= 0)
            {
                //if found, then use the Notification to be removed instead.
                //the reason is that the 'sbn' coming from this method has less data.
                //then it makes data that I need from the notification unavailable.
                notificationToBeRemoved = StatusBarNotifications[position];

                StatusBarNotifications.RemoveAt(position);
                using (var h = new Handler(Looper.MainLooper))
                    h.Post(() =>
                    {
                        //When removing a summary notification it causes a IndexOutOfBoundsException...
                        //notificationAdapter.NotifyItemRemoved(position);
                        //This has to be fixed, anyway, because this change makes the adapter to lose  the animations when removing a item
                        notificationAdapter.NotifyDataSetChanged();
                    });
            }
            OnNotificationListSizeChanged(new NotificationListSizeChangedEventArgs
            {
                ThereAreNotifications = !(StatusBarNotifications.Where(n => n.IsRemovable()).ToList().Count == 0)
            });
            NotificationRemoved?.Invoke(this, new NotificationRemovedEventArgs()
            {
                OpenNotification = notificationToBeRemoved ?? sbn, //avoid nulls.
            });
        }
Esempio n. 2
0
        private void RaiseNotificationEvent(NotificationAttributeCollection attributes)
        {
            NotificationSourceData sourceData = Notifications[attributes.NotificationUID];

            switch (sourceData.EventId)
            {
            case EventID.NotificationAdded:
                NotificationAdded?.Invoke(this, new AppleNotificationEventArgs(sourceData, attributes));
                break;

            case EventID.NotificationModified:
                NotificationModified?.Invoke(this, new AppleNotificationEventArgs(sourceData, attributes));
                break;

            case EventID.NotificationRemoved:
                // Has been handled, but just in case..
                NotificationRemoved?.Invoke(this, sourceData);
                break;
            }

            // Remove the notification from the list
            Notifications.Remove(sourceData.NotificationUID);
        }
Esempio n. 3
0
        /// <summary>
        /// When the value is changed a new notification ha arrived. We need to send a query about notification
        /// to the ControlPoint to get the actual notification message.
        /// </summary>
        /// <param name="obj"></param>
        private async void NotificationSource_ValueChanged(NotificationSourceData obj)
        {
            // TODO: Check this out. Not sure why but sometime I get a Notification UID = 0
            //       which breaks everything.
            if (obj.NotificationUID == 0)
            {
                return;
            }

            // We don't care about old notifications
            if (obj.EventFlags.HasFlag(EventFlags.EventFlagPreExisting))
            {
                return;
            }

            // Remove notifications don't need more data
            if (obj.EventId == EventID.NotificationRemoved)
            {
                if (Notifications.ContainsKey(obj.NotificationUID))
                {
                    Notifications.Remove(obj.NotificationUID);
                }

                NotificationRemoved?.Invoke(this, obj);
                return;
            }

            // Store the notification
            if (Notifications.ContainsKey(obj.NotificationUID))
            {
                Notifications[obj.NotificationUID] = obj;
            }
            else
            {
                Notifications.Add(obj.NotificationUID, obj);
            }

            // Build the attributes list for the GetNotificationAttributtes command.
            List <NotificationAttributeID> attributes = new List <NotificationAttributeID>();

            attributes.Add(NotificationAttributeID.AppIdentifier);
            attributes.Add(NotificationAttributeID.Title);
            attributes.Add(NotificationAttributeID.Message);

            if (obj.EventFlags.HasFlag(EventFlags.EventFlagPositiveAction))
            {
                attributes.Add(NotificationAttributeID.PositiveActionLabel);
            }

            if (obj.EventFlags.HasFlag(EventFlags.EventFlagNegativeAction))
            {
                attributes.Add(NotificationAttributeID.NegativeActionLabel);
            }

            try
            {
                var communicationStatus = await ControlPoint.GetNotificationAttributesAsync(obj.NotificationUID, attributes);
            }
            catch (Exception ex)
            {
                // Simply log the exception to output console
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 4
0
 private void OnNotificationRemoved()
 {
     NotificationRemoved?.Invoke(this, EventArgs.Empty); //Just notify the subscribers the notification was removed.
 }