예제 #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)
        {
            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;
                    }
                }
            }
        }
예제 #3
0
        public void OnSensorChanged(SensorEvent e)
        {
            switch (e.Sensor.Type)
            {
            case SensorType.Accelerometer:

                //Detect phone on plain surface:
                //Z axis must have the following value:
                //>10 m/s2;
                //Y axis must be less than 3m/s2 so, the device can be slightly tilted and still being
                //in a Plain surface.

                if (e.Values[2] > 9 && e.Values[1] < 3)
                {
                    if (layDownTime == 0)
                    {
                        layDownTime = e.Timestamp;
                    }

                    if (e.Timestamp > (sleepTime + layDownTime))
                    {
                        isLaidDown = true;
                        Log.Info("SENSOR", "Is Laid down");
                        if (isSensorBlocked)
                        {
                            isInPocket = true;
                            Log.Info("SENSOR", "Is in Pocket (horizontal)");
                        }
                        else
                        {
                            Log.Info("SENSOR", "Is not in Pocket (horizontal)");

                            isInPocket = false;
                        }
                    }
                    phoneInVerticalTime = 0;
                }
                if (e.Values[1] > 3 && isInPocket == false)
                {
                    if (isLaidDown == true)
                    {
                        if (phoneInVerticalTime == 0)
                        {
                            phoneInVerticalTime = e.Timestamp;
                        }
                        if (e.Timestamp > (wakeUpWaitTime + phoneInVerticalTime))
                        {
                            if (ScreenOnOffReceiver.IsScreenOn == false)
                            {
                                Log.Info("SENSOR", "Should turn on screen");
                                if (configurationManager.RetrieveAValue(ConfigurationParameters.TurnOnUserMovement))
                                {
                                    AwakeHelper.TurnOnScreen();
                                }
                            }
                            isLaidDown  = false;
                            layDownTime = 0;
                        }
                    }
                    else if (isLaidDown == false && e.Timestamp > (phoneInVerticalTime + sleepTime) && isSensorBlocked)
                    {
                        isInPocket = true;
                        Log.Info("SENSOR", "Is In Pocket (vertical) I guess");
                    }
                }

                //The less Z axis m/s2 value is, and the more Y axis m/s2 value is, the phone more vertically is.

                //Notes:
                //X axis is not necessary as I don't need to know if the phone is being moved Horizontally.

                break;

            case SensorType.Proximity:
                Log.Info("Livedisplay", "value 1 " + e.Values[0]);
                if (e.Values[0] == 0)
                {
                    proxSensorBlockedTime = e.Timestamp;
                    isSensorBlocked       = true;
                }
                else
                {
                    proxSensorBlockedTime = 0;
                    isSensorBlocked       = false;
                }

                break;

            default:
                break;
            }
            //Kind of works. :/
            //If you turn off the screen when the phone is vertical then okay, the screen won't turn on, but if you lay down your phone
            //and get it back up it won't turn on the screen again.
            //Because the code doesn't recognize that I wan't to turn on the screen and that the phone is no longer vertical.
            //if I remove the third argument then when I turn off the Screen it will immediately turn on the screen
            //because it recognizes is vertical and also it isn't inside a pocket
            //TODO: Fix this behavior

            //if (isInPocket == false && isLaidDown == false && ScreenOnOffReceiver.ScreenTurnedOffWhileInVertical==false)
            //{
            //    if (configurationManager.RetrieveAValue(ConfigurationParameters.TurnOnUserMovement) == true)
            //    {
            //        AwakeHelper.TurnOnScreen();
            //    }
            //}
        }