コード例 #1
0
        public void OnNotificationPosted(OpenNotification sbn)
        {
            if (sbn == null)
            {
                return;
            }
            //This is the notification of 'LiveDisplay is showing above other apps'
            //Simply let's ignore it, because it's annoying. (Anyway, the user couldn't care less about this notification tbh)
            if (sbn.GetPackage() == "android" && sbn.GetTag() == "com.android.server.wm.AlertWindowNotification - com.underground.livedisplay")
            {
                return;
            }

            if (sbn.IsSummary())
            {
                return; //Ignore the summary notification. (it causes redundancy) anyway, In an ideal scenario I should hide this notification instead
            }
            //of ignoring it.

            var blockingstatus = Blacklist.ReturnBlockLevel(sbn.GetPackage());

            if (!blockingstatus.HasFlag(LevelsOfAppBlocking.Blacklisted))
            {
                if (!blockingstatus.HasFlag(LevelsOfAppBlocking.BlockInAppOnly))
                {
                    bool causesWakeUp = false;
                    if (sbn.GetNotificationPriority() >= (int)NotificationPriority.Default) //Solves a issue where non important notifications also turn on screen.
                    //anyway this is a hotfix, a better method shoudl be used to improve the blacklist/the importance of notifications.
                    {
                        causesWakeUp = true;
                    }
                    else
                    {
                        causesWakeUp = false;
                    }

                    int index = GetNotificationPosition(sbn); //Tries to get the index of a possible already existing notification in the list of notif.
                    if (index >= 0)
                    {
                        //It exists within the list.
                        //SO it should be updated.

                        StatusBarNotifications.RemoveAt(index);
                        StatusBarNotifications.Add(sbn);
                        using (var h = new Handler(Looper.MainLooper))
                            h.Post(() => { notificationAdapter.NotifyItemChanged(index); });

                        OnNotificationPosted(false, sbn, true);
                    }
                    else
                    {
                        StatusBarNotifications.Add(sbn);

                        using (var h = new Handler(Looper.MainLooper))
                            h.Post(() => { notificationAdapter.NotifyItemInserted(StatusBarNotifications.Count); });
                        OnNotificationPosted(causesWakeUp, sbn, false);
                    }
                }
            }
            else
            {
                var notificationSlave = NotificationSlave.NotificationSlaveInstance();
                if (Build.VERSION.SdkInt > BuildVersionCodes.KitkatWatch)
                {
                    notificationSlave.CancelNotification(sbn.GetKey());
                }
                else
                {
                    notificationSlave.CancelNotification(sbn.GetPackage(), sbn.GetTag(), sbn.GetId());
                }
            }

            OnNotificationListSizeChanged(new NotificationListSizeChangedEventArgs
            {
                ThereAreNotifications = StatusBarNotifications.Count > 0
            });
        }
コード例 #2
0
 private static int GetNotificationPosition(OpenNotification sbn)
 {
     return(StatusBarNotifications.IndexOf(StatusBarNotifications.FirstOrDefault
                                               (o => o.GetId() == sbn.GetId() && o.GetPackage() == sbn.GetPackage() && o.GetTag() == sbn.GetTag() &&
                                               o.IsSummary() == sbn.IsSummary())));
 }