コード例 #1
0
        private void CatcherHelper_NotificationRemoved(object sender, NotificationRemovedEventArgs e)
        {
            Activity?.RunOnUiThread(() =>
            {
                if (configurationManager.RetrieveAValue(ConfigurationParameters.MusicWidgetMethod, "0") == "1")
                {
                    if (e.OpenNotification.RepresentsMediaPlaying())
                    {
                        ThreadPool.QueueUserWorkItem(m =>
                        {
                            MusicController.StopPlayback(e.OpenNotification.GetMediaSessionToken());
                        } //Returns true if the Playback was stopped succesfully (Sometimes it wont work)
                                                     );

                        //In any case, order MusicWidget to stop.
                        WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
                            Show = false, WidgetName = "MusicFragment", Active = false
                        });
                    }
                }

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

                maincontainer.Visibility = ViewStates.Gone;
                //Remove tag, notification removed
                _openNotification = null;
                maincontainer?.SetTag(Resource.String.defaulttag, null);
            });
        }
コード例 #2
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;
                }
            }
        }
コード例 #3
0
 private void LlNotification_Click(object sender, EventArgs e)
 {
     Activity?.RunOnUiThread(() =>
     {
         try
         {
             if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
             {
                 if (KeyguardHelper.IsDeviceCurrentlyLocked())
                 {
                     KeyguardHelper.RequestDismissKeyguard(Activity);
                 }
             }
             Activity?.RunOnUiThread(() => _openNotification.ClickNotification());
             if (_openNotification.IsAutoCancellable())
             {
                 WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
                     Show = false, WidgetName = "NotificationFragment"
                 });
                 maincontainer.Visibility = ViewStates.Invisible;
             }
         }
         catch
         {
             Log.Wtf("OnNotificationClicked", "Metodo falla porque no existe una notificacion con esta acción");
         }
     });
 }
コード例 #4
0
 public void OnActiveSessionsChanged(IList <MediaController> controllers)
 {
     if (new ConfigurationManager(AppPreferences.Default).RetrieveAValue(ConfigurationParameters.MusicWidgetMethod, "0") == "0")
     {//0 equals 'Media Session'
         //Pick the best mediacontroller.
         if (controllers.Count > 0)
         {
             foreach (var mediacontroller in controllers)
             {
                 if (mediacontroller?.GetTransportControls() != null)//Ensure that this session has transport controls we can control
                 {
                     try
                     {
                         MusicController.StartPlayback(mediacontroller.SessionToken, null);
                         WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
                             Show = true, WidgetName = "MusicFragment", Active = true
                         });
                     }
                     catch
                     {
                         MusicController.StopPlayback(mediacontroller?.SessionToken);
                     }
                     break;
                 }
             }
         }
     }
 }
コード例 #5
0
        public void OnPlaybackStateChanged(RemoteControlPlayState state)
        {
            PlaybackState = state;
            MusicStatus   = state;
            Log.Info("LiveDisplay", "Music state is" + state);
            OnMediaPlaybackChanged(new MediaPlaybackStateChangedKitkatEventArgs
            {
                PlaybackState = state
            });
            switch (state)
            {
            case RemoteControlPlayState.Playing:
                if (requestedWidgetStart == false)
                {
                    WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
                        Show = true, WidgetName = "MusicFragment", Active = true
                    });
                    requestedWidgetStart = true;
                }
                break;

            case RemoteControlPlayState.Paused:
                break;
            }
        }
コード例 #6
0
 private void ItemLongClicked(object sender, NotificationItemClickedEventArgs e)
 {
     e.StatusBarNotification.Cancel();
     WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
         Show = false, WidgetName = "NotificationFragment"
     });
     maincontainer.Visibility = ViewStates.Invisible;
 }
コード例 #7
0
        public void ShowNotification(OpenNotification openNotification)
        {
            _openNotification = openNotification;

            Activity.RunOnUiThread(() =>
            {
                if (configurationManager.RetrieveAValue(ConfigurationParameters.TestEnabled))
                {
                    Toast.MakeText(Application.Context, "Progress Indeterminate?: " + _openNotification.IsProgressIndeterminate().ToString() + "\n"
                                   + "Current Progress: " + _openNotification.GetProgress().ToString() + "\n"
                                   + "Max Progress: " + _openNotification.GetProgressMax().ToString() + "\n"
                                   + _openNotification.GetGroupInfo()
                                   , ToastLength.Short).Show();
                }
                switch (_openNotification.Style())
                {
                case BigPictureStyle:
                    new BigPictureStyleNotification(_openNotification, ref maincontainer, this).ApplyStyle();
                    break;

                case MessagingStyle:
                    new MessagingStyleNotification(_openNotification, ref maincontainer, this).ApplyStyle();
                    break;

                case InboxStyle:
                    new InboxStyleNotification(_openNotification, ref maincontainer, this).ApplyStyle();
                    break;

                case BigTextStyle:
                    new BigTextStyleNotification(_openNotification, ref maincontainer, this).ApplyStyle();
                    break;

                case MediaStyle:
                    new MediaStyleNotification(_openNotification, ref maincontainer, this).ApplyStyle();
                    break;

                default:
                    new DefaultStyleNotification(_openNotification, ref maincontainer, this).ApplyStyle();
                    break;
                }

                StartTimeout(false);

                //Now we check if the current showing widget is this, if not, ask for us to be the current showing widget.
                if (WidgetStatusPublisher.CurrentActiveWidget != "NotificationFragment")
                {
                    WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
                        Show = true, WidgetName = "NotificationFragment"
                    });
                    maincontainer.Visibility = ViewStates.Visible; //we make ourselves visible when we are the current showing widget.
                }
                else if (maincontainer.Visibility != ViewStates.Visible)
                {
                    maincontainer.Visibility = ViewStates.Visible;
                }
            });
        }
コード例 #8
0
 public override void OnResume()
 {
     if (WidgetStatusPublisher.CurrentActiveWidget == "MusicFragment" && initForFirstTime == true)
     {
         WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
             Show = true, WidgetName = "MusicFragment", Active = true
         });
     }
     base.OnResume();
 }
コード例 #9
0
        private void WidgetStatusPublisher_OnWidgetStatusChanged(object sender, WidgetStatusEventArgs e)
        {
            if (e.WidgetName == "NotificationFragment")
            {
                if (e.Show)
                {
                    if (maincontainer != null)
                    {
                        maincontainer.Visibility = ViewStates.Invisible;
                    }
                }
                else
                {
                    if (WidgetStatusPublisher.CurrentActiveWidget == string.Empty) //If clock has a chance to show itself!
                    {
                        if (maincontainer != null)
                        {
                            maincontainer.Visibility = ViewStates.Visible;
                        }
                    }
                    else
                    {
                        WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs
                        {
                            WidgetName = WidgetStatusPublisher.CurrentActiveWidget,
                            Active     = true, //Having a Current Active Widget means it should be active by def.
                            Show       = true
                        });

                        if (maincontainer != null)
                        {
                            maincontainer.Visibility = ViewStates.Invisible;
                        }
                    }
                }
            }
            else if (e.WidgetName == "MusicFragment")
            {
                if (e.Show)
                {
                    if (maincontainer != null)
                    {
                        maincontainer.Visibility = ViewStates.Invisible;
                    }
                }
                else
                {
                    if (maincontainer != null)
                    {
                        maincontainer.Visibility = ViewStates.Visible;
                    }
                }
            }
        }
コード例 #10
0
 private void HideNotification()
 {
     if (maincontainer != null)
     {
         maincontainer.Visibility = ViewStates.Gone;
         timeoutStarted           = false;
         WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
             Show = false, WidgetName = "NotificationFragment"
         });
     }
 }
コード例 #11
0
        protected virtual void CloseNotification_Click(object sender, EventArgs e)
        {
            ImageButton      closenotificationbutton = sender as ImageButton;
            OpenNotification openNotification        = closenotificationbutton.GetTag(DefaultActionIdentificator) as OpenNotification;

            openNotification?.Cancel();
            NotificationView.SetTag(Resource.String.defaulttag, openNotification.GetCustomId());
            WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
                Show = false, WidgetName = "NotificationFragment"
            });
            NotificationView.Visibility = ViewStates.Invisible;
        }
コード例 #12
0
 private void HideMusicWidget()
 {
     if (maincontainer != null)
     {
         Activity.RunOnUiThread(() =>
         {
             maincontainer.Visibility = ViewStates.Gone;
         });
         timeoutStarted = false;
         WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
             Show = false, WidgetName = "MusicFragment", Active = false
         });
     }
 }
コード例 #13
0
        public override void OnDestroy()
        {
            WidgetStatusPublisher.OnWidgetStatusChanged -= WidgetStatusPublisher_OnWidgetStatusChanged;
            tvAlbum         = null;
            tvArtist        = null;
            tvTitle         = null;
            skbSeekSongTime = null;
            bool isWidgetActive = WidgetStatusPublisher.CurrentActiveWidget == "MusicFragment";

            WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs {
                Show = false, WidgetName = "MusicFragment", Active = isWidgetActive
            });
            initForFirstTime = false;
            base.OnDestroy();
        }
コード例 #14
0
 private void BtnLaunchNotification_Click(object sender, EventArgs e)
 {
     if (configurationManager.RetrieveAValue(ConfigurationParameters.LaunchNotification))
     {
         KeyguardHelper.RequestDismissKeyguard(Activity);
         CatcherHelper.GetOpenNotification(openNotificationId)?.ClickNotification();
     }
     else
     {
         if (MusicController.MediaSessionAssociatedWThisNotification(openNotificationId))
         {
             WidgetStatusPublisher.RequestShow(new WidgetStatusEventArgs
             {
                 Active                 = false,
                 Show                   = true,
                 WidgetName             = "NotificationFragment",
                 WidgetAskingForShowing = "MusicFragment",
                 AdditionalInfo         = openNotificationId
             });
         }
     }
 }