public void IssueNotificationAsync(string title, string message, string id, string protocolId, bool alertUser, DisplayPage displayPage, TimeSpan delay, NSMutableDictionary info, Action <UNNotificationRequest> requestCreated = null)
        {
            if (info == null)
            {
                info = new NSMutableDictionary();
            }

            info.SetValueForKey(new NSString(id), new NSString(NOTIFICATION_ID_KEY));
            info.SetValueForKey(new NSString(displayPage.ToString()), new NSString(DISPLAY_PAGE_KEY));

            UNMutableNotificationContent content = new UNMutableNotificationContent
            {
                UserInfo = info
            };

            // the following properties are allowed to be null, but they cannot be set to null.

            if (!string.IsNullOrWhiteSpace(title))
            {
                content.Title = title;
            }

            if (!string.IsNullOrWhiteSpace(message))
            {
                content.Body = message;
            }

            // the following calculation isn't perfect because we use DateTime.Now and then use it again in the subsequent call to IssueNotificationAsync.
            // these two values will be slightly different due to execution time, but the risk is small:  the user might hear or not hear the notification
            // when it comes through, and it's very unlikely that the result will be incorrect.
            if (alertUser && !Protocol.TimeIsWithinAlertExclusionWindow(protocolId, (DateTime.Now + delay).TimeOfDay))
            {
                content.Sound = UNNotificationSound.Default;
            }

            IssueNotificationAsync(id, content, delay, requestCreated);
        }
示例#2
0
        public override void IssueNotificationAsync(string title, string message, string id, bool playSound, DisplayPage displayPage)
        {
            if (_notificationManager == null)
            {
                return;
            }

            Task.Run(() =>
            {
                if (message == null)
                {
                    CancelNotification(id);
                }
                else
                {
                    Intent notificationIntent = new Intent(_service, typeof(AndroidSensusService));
                    notificationIntent.PutExtra(DISPLAY_PAGE_KEY, displayPage.ToString());

                    PendingIntent notificationPendingIntent = PendingIntent.GetService(_service, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);

                    Notification.Builder notificationBuilder = new Notification.Builder(_service)
                                                               .SetContentTitle(title)
                                                               .SetContentText(message)
                                                               .SetSmallIcon(Resource.Drawable.ic_launcher)
                                                               .SetContentIntent(notificationPendingIntent)
                                                               .SetAutoCancel(true)
                                                               .SetOngoing(false);

                    if (playSound)
                    {
                        notificationBuilder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
                        notificationBuilder.SetVibrate(new long[] { 0, 250, 50, 250 });
                    }

                    _notificationManager.Notify(id, 0, notificationBuilder.Build());
                }
            });
        }
示例#3
0
 private void DisplayPage_Initialized(object sender, EventArgs e)
 {
     DisplayPage.Navigate(new Home());
 }
 public override void IssueNotificationAsync(string title, string message, string id, string protocolId, bool alertUser, DisplayPage displayPage)
 {
     IssueNotificationAsync(title, message, id, protocolId, alertUser, displayPage, TimeSpan.Zero, null, null);
 }
示例#5
0
 private void ItemAddAppointment_Click(object sender, RoutedEventArgs e)
 {
     DisplayPage.Navigate(new AddAppointment());
 }
示例#6
0
 private void ItemListAppointments_Click(object sender, RoutedEventArgs e)
 {
     DisplayPage.Navigate(new AppointmentList());
 }
示例#7
0
 private void ItemAddBroker_Click(object sender, RoutedEventArgs e)
 {
     DisplayPage.Navigate(new AddBroker());
 }
        public void IssueNotificationAsync(string title, string message, string id, Protocol protocol, bool alertUser, DisplayPage displayPage, DateTime fireDateTime, NSMutableDictionary notificationInfo, Action <UILocalNotification> notificationCreated = null)
        {
            SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() =>
            {
                CancelNotification(id);

                if (notificationInfo == null)
                {
                    notificationInfo = new NSMutableDictionary();
                }

                notificationInfo.SetValueForKey(new NSString(id), new NSString(NOTIFICATION_ID_KEY));
                notificationInfo.SetValueForKey(new NSString(displayPage.ToString()), new NSString(DISPLAY_PAGE_KEY));

                // all properties below were introduced in iOS 8.0. we currently target 9.0 and above, so these should be safe to set.
                UILocalNotification notification = new UILocalNotification
                {
                    AlertBody = message,
                    TimeZone  = null, // null for UTC interpretation of FireDate
                    FireDate  = fireDateTime.ToUniversalTime().ToNSDate(),
                    UserInfo  = notificationInfo
                };

                // introduced in 8.0...protocol might be null when issuing the pending surveys notification.
                if (alertUser && (protocol == null || !protocol.TimeIsWithinAlertExclusionWindow(fireDateTime.TimeOfDay)))
                {
                    notification.SoundName = UILocalNotification.DefaultSoundName;
                }

                // introduced in iOS 8.2:  https://developer.apple.com/reference/uikit/uilocalnotification/1616647-alerttitle
                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 2) && !string.IsNullOrWhiteSpace(title))
                {
                    notification.AlertTitle = title;
                }

                notificationCreated?.Invoke(notification);

                IssueNotificationAsync(notification);
            });
        }
示例#9
0
 public override void IssueNotificationAsync(string title, string message, string id, Protocol protocol, bool alertUser, DisplayPage displayPage)
 {
     IssueNotificationAsync(title, message, id, protocol, alertUser, displayPage, DateTime.Now, null, null);
 }
示例#10
0
        public void IssueNotificationAsync(string title, string message, string id, Protocol protocol, bool alertUser, DisplayPage displayPage, DateTime triggerDateTime, NSMutableDictionary info, Action <UNNotificationRequest> requestCreated = null)
        {
            if (info == null)
            {
                info = new NSMutableDictionary();
            }

            info.SetValueForKey(new NSString(id), new NSString(NOTIFICATION_ID_KEY));
            info.SetValueForKey(new NSString(displayPage.ToString()), new NSString(DISPLAY_PAGE_KEY));

            UNMutableNotificationContent content = new UNMutableNotificationContent
            {
                UserInfo = info
            };

            // the following properties are allowed to be null, but they cannot be set to null.

            if (!string.IsNullOrWhiteSpace(title))
            {
                content.Title = title;
            }

            if (!string.IsNullOrWhiteSpace(message))
            {
                content.Body = message;
            }

            // protocol might be null when issuing the pending surveys notification.
            if (alertUser && (protocol == null || !protocol.TimeIsWithinAlertExclusionWindow(triggerDateTime.TimeOfDay)))
            {
                content.Sound = UNNotificationSound.Default;
            }

            IssueNotificationAsync(id, content, triggerDateTime, requestCreated);
        }
示例#11
0
 public abstract void IssueNotificationAsync(string title, string message, string id, Protocol protocol, bool alertUser, DisplayPage displayPage);
示例#12
0
 protected void BindDisplayPage()
 {
     DisplayPage.DataSource = WebpageDataSource.LoadForWebpageType(WebpageType.CategoryDisplay);
     DisplayPage.DataBind();
 }
示例#13
0
        public void IssueNotificationAsync(string title, string message, string id, bool playSound, DisplayPage displayPage, int delayMS, NSMutableDictionary info, Action <UNNotificationRequest> requestCreated = null)
        {
            if (info == null)
            {
                info = new NSMutableDictionary();
            }

            info.SetValueForKey(new NSString(id), new NSString(NOTIFICATION_ID_KEY));
            info.SetValueForKey(new NSString(displayPage.ToString()), new NSString(DISPLAY_PAGE_KEY));

            UNMutableNotificationContent content = new UNMutableNotificationContent
            {
                UserInfo = info
            };

            // the following properties are allowed to be null, but they cannot be set to null.

            if (!string.IsNullOrWhiteSpace(title))
            {
                content.Title = title;
            }

            if (!string.IsNullOrWhiteSpace(message))
            {
                content.Body = message;
            }

            if (playSound)
            {
                content.Sound = UNNotificationSound.Default;
            }

            IssueNotificationAsync(id, content, delayMS, requestCreated);
        }
示例#14
0
        /// <summary>
        /// Issues the notification.
        /// </summary>
        /// <param name="title">Title.</param>
        /// <param name="message">Message.</param>
        /// <param name="id">Identifier of notification.</param>
        /// <param name="protocol">Protocol to check for alert exclusion time windows.</param>
        /// <param name="alertUser">If set to <c>true</c> alert user.</param>
        /// <param name="displayPage">Display page.</param>
        public override void IssueNotificationAsync(string title, string message, string id, Protocol protocol, bool alertUser, DisplayPage displayPage)
        {
            if (_notificationManager == null)
            {
                return;
            }

            Task.Run(() =>
            {
                if (message == null)
                {
                    CancelNotification(id);
                }
                else
                {
                    Intent notificationIntent = new Intent(_service, typeof(AndroidMainActivity));
                    notificationIntent.PutExtra(DISPLAY_PAGE_KEY, displayPage.ToString());
                    PendingIntent notificationPendingIntent = PendingIntent.GetActivity(_service, 0, notificationIntent, PendingIntentFlags.OneShot);

                    SensusNotificationChannel notificationChannel = SensusNotificationChannel.Default;

                    if (displayPage == DisplayPage.PendingSurveys)
                    {
                        notificationChannel = SensusNotificationChannel.Survey;
                    }

                    // reset channel to silent if we're not alerting or if we're in an exclusion window
                    if (!alertUser || (protocol != null && protocol.TimeIsWithinAlertExclusionWindow(DateTime.Now.TimeOfDay)))
                    {
                        notificationChannel = SensusNotificationChannel.Silent;
                    }

                    Notification.Builder notificationBuilder = CreateNotificationBuilder(_service, notificationChannel)
                                                               .SetContentTitle(title)
                                                               .SetContentText(message)
                                                               .SetSmallIcon(Resource.Drawable.ic_launcher)
                                                               .SetContentIntent(notificationPendingIntent)
                                                               .SetAutoCancel(true)
                                                               .SetOngoing(false);

                    _notificationManager.Notify(id, 0, notificationBuilder.Build());
                }
            });
        }
示例#15
0
 private void ItemListBrokers_Click(object sender, RoutedEventArgs e)
 {
     DisplayPage.Navigate(new BrokersList());
 }
示例#16
0
 public override void IssueNotificationAsync(string title, string message, string id, bool playSound, DisplayPage displayPage)
 {
     IssueNotificationAsync(title, message, id, playSound, displayPage, 0, null);
 }
示例#17
0
 public void OpenDisplayPage(DisplayPage displayPage)
 {
 }