Esempio n. 1
0
        public void OnNotificationPosted(StatusBarNotification sbn)
        {
            //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.PackageName == "android" && sbn.Tag == "com.android.server.wm.AlertWindowNotification - com.underground.livedisplay")
            {
                return;
            }

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

            if (!blockingstatus.HasFlag(LevelsOfAppBlocking.Blacklisted))
            {
                if (!blockingstatus.HasFlag(LevelsOfAppBlocking.BlockInAppOnly))
                {
                    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(blockingstatus.HasFlag(LevelsOfAppBlocking.None), sbn, true);
                    }
                    else
                    {
                        StatusBarNotifications.Add(sbn);

                        using (var h = new Handler(Looper.MainLooper))
                            h.Post(() => { notificationAdapter.NotifyItemInserted(StatusBarNotifications.Count); });
                        OnNotificationPosted(blockingstatus.HasFlag(LevelsOfAppBlocking.None), sbn, false);
                    }
                }
            }
            else
            {
                var notificationSlave = NotificationSlave.NotificationSlaveInstance();
                if (Build.VERSION.SdkInt > BuildVersionCodes.KitkatWatch)
                {
                    notificationSlave.CancelNotification(sbn.Key);
                }
                else
                {
                    notificationSlave.CancelNotification(sbn.PackageName, sbn.Tag, sbn.Id);
                }
            }

            if (StatusBarNotifications.Count > 0)
            {
                OnNotificationListSizeChanged(new NotificationListSizeChangedEventArgs
                {
                    ThereAreNotifications = true
                });
            }
        }
Esempio n. 2
0
        private bool UpdateNotification(StatusBarNotification sbn)
        {
            int indice = GetNotificationPosition(sbn);

            if (indice >= 0 /*&& Blacklist.IsAppBlacklisted(sbn.PackageName) == false*/)
            {
                statusBarNotifications.RemoveAt(indice);
                statusBarNotifications.Add(sbn);
                using (var h = new Handler(Looper.MainLooper))
                    h.Post(() => { notificationAdapter.NotifyItemChanged(indice); });

                OnNotificationUpdated(indice);
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        public override void OnNotificationPosted(StatusBarNotification sbn)
        {
            //Kitkat Dirty ListenerConnected.
            //No funciona si no hay una notificación nueva
            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop && isConnected == false)
            {
                catcherInstance     = this;
                listaNotificaciones = GetActiveNotifications().ToList();
                adapter             = new NotificationAdapter(listaNotificaciones);
                isConnected         = true;
                Log.Info("Kitkat Listener connected, list: ", listaNotificaciones.Count.ToString());
            }

            int id     = sbn.Id;
            int indice = listaNotificaciones.IndexOf(listaNotificaciones.FirstOrDefault(o => o.Id == sbn.Id));

            //Condicional debido a que Play Store causa que algun item se pierda #wontfix ?
            if (indice >= 0)
            {
                listaNotificaciones.RemoveAt(indice);
                listaNotificaciones.Add(sbn);
                if (LockScreenActivity.lockScreenInstance != null)
                {
                    LockScreenActivity.lockScreenInstance.RunOnUiThread(() => adapter.NotifyItemChanged(indice));
                }

                Log.Info("Elemento actualizado", "Tamaño lista: " + listaNotificaciones.Count);
            }
            else
            {
                listaNotificaciones.Add(sbn);
                if (LockScreenActivity.lockScreenInstance != null)
                {
                    LockScreenActivity.lockScreenInstance.RunOnUiThread(() => adapter.NotifyItemInserted(listaNotificaciones.Count));
                }
                Log.Info("Elemento insertado", "Tamaño lista: " + listaNotificaciones.Count);
            }
        }
Esempio n. 4
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
            });
        }