Exemplo n.º 1
0
        private void CatcherHelper_NotificationPosted(object sender, NotificationPostedEventArgs e)
        {
            //if the incoming notification updates a previous notification, then verify if the current notification SHOWING is the same as the one
            //we are trying to update, because if this check is not done, the updated notification will show even if the user is seeing another notification.
            //the other case is simply when the notification is a new one.
            if (e.UpdatesPreviousNotification && e.OpenNotification.GetCustomId() == _openNotification?.GetCustomId() ||
                e.UpdatesPreviousNotification == false)
            {
                ShowNotification(e.OpenNotification);
            }

            if (e.ShouldCauseWakeUp && configurationManager.RetrieveAValue(ConfigurationParameters.TurnOnNewNotification))
            {
                AwakeHelper.TurnOnScreen();
            }

            if (configurationManager.RetrieveAValue(ConfigurationParameters.MusicWidgetMethod, "0") == "1") //1:"Use a notification to spawn the Music Widget"
            {
                if (e.OpenNotification.RepresentsMediaPlaying())
                {
                    MusicController.StartPlayback(e.OpenNotification.GetMediaSessionToken(), e.OpenNotification.GetCustomId());

                    maincontainer.Visibility = ViewStates.Invisible;
                    WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
                        Show = false, WidgetName = "NotificationFragment"
                    });

                    //Also start the Widget to control the playback.
                    WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
                        Show = true, WidgetName = "MusicFragment", Active = true
                    });
                    return;
                }
            }
        }
 private void CatcherHelper_NotificationPosted(object sender, NotificationPostedEventArgs e)
 {
     if (e.ShouldCauseWakeUp == true)
     {
         Awake.WakeUpScreen();
     }
 }
        private void CatcherHelper_NotificationPosted(object sender, NotificationPostedEventArgs e)
        {
            openNotification = e.OpenNotification;
            if (e.ShouldCauseWakeUp)
            {
                AwakeHelper.TurnOnScreen();
            }

            //if the current floating notification widget does not have a tag, let's set it.

            if (floatingNotificationView.GetTag(Resource.String.defaulttag) == null)
            {
                floatingNotificationView.SetTag(Resource.String.defaulttag, openNotification.GetCustomId());
            }

            if (configurationManager.RetrieveAValue(ConfigurationParameters.TestEnabled))
            {
                Toast.MakeText(floatingNotificationView.Context, "Progress Indeterminate?: " + openNotification.IsProgressIndeterminate().ToString() + "\n"
                               + "Current Progress: " + openNotification.GetProgress().ToString() + "\n"
                               + "Max Progress: " + openNotification.GetProgressMax().ToString() + "\n"
                               + openNotification.GetGroupInfo()
                               , ToastLength.Short).Show();
            }

            if (e.UpdatesPreviousNotification)
            {
                if ((string)floatingNotificationView.GetTag(Resource.String.defaulttag) == openNotification.GetCustomId())
                {
                    floatingNotificationView.SetTag(Resource.String.defaulttag, openNotification.GetCustomId());
                }
            }
            else
            {
                //Is a new notification, so set a new tag.
                floatingNotificationView.SetTag(Resource.String.defaulttag, openNotification.GetCustomId());

                if (floatingNotificationView.Visibility != ViewStates.Visible)
                {
                    if (currentActivityState == ActivityStates.Resumed) //most of the times it won't work, when the Screen turns on then it gets here too quickly
                    //before the lockscreen is in a Resumed state, causing the floating notification not being showed when the screen turns on, TODO.
                    {
                        floatingNotificationView.Visibility = ViewStates.Visible;
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void CatcherHelper_NotificationPosted(object sender, NotificationPostedEventArgs e)
        {
            openNotification = new OpenNotification(e.StatusBarNotification);

            //if the current floating notification widget does not have a tag, let's set it.

            if (floatingNotificationView.GetTag(Resource.String.defaulttag) == null)
            {
                floatingNotificationView.SetTag(Resource.String.defaulttag, openNotification.GetCustomId());
            }

            if (configurationManager.RetrieveAValue(ConfigurationParameters.TestEnabled))
            {
                Toast.MakeText(floatingNotificationView.Context, "Progress Indeterminate?: " + openNotification.IsProgressIndeterminate().ToString() + "\n"
                               + "Current Progress: " + openNotification.GetProgress().ToString() + "\n"
                               + "Max Progress: " + openNotification.GetProgressMax().ToString() + "\n"
                               + openNotification.GetGroupInfo()
                               , ToastLength.Short).Show();
            }

            if (e.UpdatesPreviousNotification)
            {
                if ((string)floatingNotificationView.GetTag(Resource.String.defaulttag) == openNotification.GetCustomId())
                {
                    floatingNotificationAppName.Text = openNotification.AppName();
                    floatingNotificationWhen.Text    = openNotification.When();
                    floatingNotificationTitle.Text   = openNotification.Title();
                    floatingNotificationText.Text    = openNotification.Text();
                    floatingNotificationActionsContainer.RemoveAllViews();

                    if (openNotification.HasActions() == true)
                    {
                        var actions = openNotification.RetrieveActions();
                        foreach (var a in actions)
                        {
                            OpenAction openAction = new OpenAction(a);
                            float      weight     = (float)1 / actions.Count;

                            Button anActionButton = new Button(Application.Context)
                            {
                                LayoutParameters = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, weight),
                                Text             = openAction.Title(),
                            };
                            anActionButton.SetTypeface(Typeface.Create("sans-serif-condensed", TypefaceStyle.Normal), TypefaceStyle.Normal);
                            anActionButton.SetMaxLines(1);
                            anActionButton.SetTextColor(Color.Black);
                            anActionButton.Click += (o, eventargs) =>
                            {
                                openAction.ClickAction();
                            };
                            anActionButton.Gravity = GravityFlags.CenterVertical;
                            TypedValue outValue = new TypedValue();
                            Application.Context.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackgroundBorderless, outValue, true);
                            anActionButton.SetBackgroundResource(outValue.ResourceId);
                            //anActionButton.SetCompoundDrawablesRelativeWithIntrinsicBounds(openAction.GetActionIcon(), null, null, null);
                            floatingNotificationActionsContainer.AddView(anActionButton);
                        }
                        ;
                    }
                }
            }
            else
            {
                //Is a new notification, so set a new tag.
                floatingNotificationView.SetTag(Resource.String.defaulttag, openNotification.GetCustomId());

                floatingNotificationAppName.Text = openNotification.AppName();
                floatingNotificationWhen.Text    = openNotification.When();
                floatingNotificationTitle.Text   = openNotification.Title();
                floatingNotificationText.Text    = openNotification.Text();
                floatingNotificationActionsContainer.RemoveAllViews();

                if (openNotification.HasActions() == true)
                {
                    var actions = openNotification.RetrieveActions();
                    foreach (var a in actions)
                    {
                        OpenAction openAction = new OpenAction(a);
                        float      weight     = (float)1 / actions.Count;

                        Button anActionButton = new Button(Application.Context)
                        {
                            LayoutParameters = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, weight),
                            Text             = openAction.Title(),
                        };
                        anActionButton.SetTypeface(Typeface.Create("sans-serif-condensed", TypefaceStyle.Normal), TypefaceStyle.Normal);
                        anActionButton.SetMaxLines(1);
                        anActionButton.SetTextColor(Color.Black);
                        anActionButton.Click += (o, eventargs) =>
                        {
                            openAction.ClickAction();
                        };
                        anActionButton.Gravity = GravityFlags.CenterVertical;
                        TypedValue outValue = new TypedValue();
                        Application.Context.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackgroundBorderless, outValue, true);
                        anActionButton.SetBackgroundResource(outValue.ResourceId);
                        //anActionButton.SetCompoundDrawablesRelativeWithIntrinsicBounds(openAction.GetActionIcon(), null, null, null);
                        floatingNotificationActionsContainer.AddView(anActionButton);
                    }
                    ;
                }

                if (floatingNotificationView.Visibility != ViewStates.Visible)
                {
                    if (currentActivityState == ActivityStates.Resumed)
                    {
                        floatingNotificationView.Visibility = ViewStates.Visible;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void CatcherHelper_NotificationPosted(object sender, NotificationPostedEventArgs e)
        {
            openNotification = new OpenNotification(e.StatusBarNotification);

            //if the current notification widget does not have a tag, let's set it.

            if (notification.GetTag(Resource.String.defaulttag) == null)
            {
                notification.SetTag(Resource.String.defaulttag, openNotification.GetCustomId());
            }

            if (configurationManager.RetrieveAValue(ConfigurationParameters.TestEnabled))
            {
                Toast.MakeText(Activity, "Progress Indeterminate?: " + openNotification.IsProgressIndeterminate().ToString() + "\n"
                               + "Current Progress: " + openNotification.GetProgress().ToString() + "\n"
                               + "Max Progress: " + openNotification.GetProgressMax().ToString() + "\n"
                               + openNotification.GetGroupInfo()
                               , ToastLength.Short).Show();
            }

            if (e.UpdatesPreviousNotification)
            {
                Activity.RunOnUiThread(() =>
                {
                    //if updates a previous notification, let's see if first of all the notification
                    //to be updated is the same that's currently being displayed in the Notification Widget.
                    if ((string)notification.GetTag(Resource.String.defaulttag) == openNotification.GetCustomId())
                    {
                        //Watch out for possible memory leaks here.
                        styleApplier?.ApplyStyle(openNotification);

                        //let's attach a tag to the fragment in order to know which notification is this fragment showing.
                        notification.SetTag(Resource.String.defaulttag, openNotification.GetCustomId());

                        if (notification.Visibility != ViewStates.Visible)
                        {
                            notification.Visibility = ViewStates.Visible;
                            StartTimeout(false);
                        }
                    }
                    else
                    {
                        //they are not the same so, the notification widget won't get updated(because that'll cause the
                        //notification the user is viewing to be replaced)
                    }
                });
            }
            else
            {
                Activity.RunOnUiThread(() =>
                {
                    styleApplier?.ApplyStyle(openNotification);
                    notification.SetTag(Resource.String.defaulttag, openNotification.GetCustomId());
                    if (notification.Visibility != ViewStates.Visible)
                    {
                        notification.Visibility = ViewStates.Visible;
                        StartTimeout(false);
                    }
                });
            }
        }