Пример #1
0
        public static void CheckAndCreateNotification(Context context, user_page userPage, int HR)
        {
            // In case the user ask to ignore and the ignore counter is still counting we will not do anything
            if (ignore)
            {
                return;
            }

            // Extracting the current HB status
            HRStatus heartStatus = calcCurrentStatus(userPage, HR);

            // Create NotifyItem item and put it in the
            statusHistoryList.Add(new NotifyItem(heartStatus, HR));

            // Creating notifications for heach one of the cases
            if (heartStatus != HRStatus.Normal)
            {
                NotifyHeartRate(context, userPage, HR, heartStatus);
            }
        }
Пример #2
0
        private static void NotifyHeartRate(Context context, user_page userPage, int HR, HRStatus status)
        {
            // When the user clicks the notification, SecondActivity will start up.
            Intent resultIntent = new Intent(userPage, typeof(NotificationActivity));

            // Passing HR and HRStatus to notification activity
            Bundle valuesForActivity = new Bundle();

            valuesForActivity.PutInt("status", (int)status);
            valuesForActivity.PutInt("HR", HR);
            resultIntent.PutExtras(valuesForActivity);

            // Construct a back stack for cross-task navigation:
            TaskStackBuilder stackBuilder = TaskStackBuilder.Create(context);

            stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(NotificationActivity)));
            stackBuilder.AddNextIntent(resultIntent);

            // Create the PendingIntent with the back stack:
            PendingIntent resultPendingIntent =
                stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent | (int)PendingIntentFlags.OneShot);

            // Build the notification:
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                                                 .SetAutoCancel(true)                              // Dismiss from the notif. area when clicked
                                                 .SetContentIntent(resultPendingIntent)            // Start 2nd activity when the intent is clicked.
                                                 .SetContentTitle("Is everything OK?")             // Set its title
                                                 .SetNumber(HR)                                    // Display the HR in the Content Info
                                                 .SetSmallIcon(Resource.Drawable.emptyheart_white) // Display this icon
                                                 .SetContentText(string.Format(
                                                                     "Your heart beat {0} to {1} bpm.",
                                                                     status == HRStatus.Hypo ? "decreased dramaticaly" :
                                                                     status == HRStatus.Hyper ? "increased dramaticaly" :
                                                                     "is not stable and changed dramatically", HR)); // The message to display.

            // Finally, publish the notification:
            NotificationManager notificationManager =
                (NotificationManager)context.GetSystemService(Context.NotificationService);

            notificationManager.Notify(ButtonClickNotificationId, builder.Build());
        }
Пример #3
0
        private static HRStatus calcCurrentStatus(user_page userPage, int HR)
        {
            HRStatus last;
            HRStatus retStatus = HRStatus.Normal;
            DateTime now       = DateTime.Now;
            var      lastItem  = statusHistoryList.LastOrDefault();

            last = lastItem.Equals(default(NotifyItem)) ? HRStatus.Normal : lastItem.heartStatus;

            // Fixme: there is a period of time inwhich no matter how "normal" your heart rate you are still in
            // abnormal condition - maybe we should add a counter or some thing that will tell us until when the
            // status is still abnormal.
            // Meanwhile - when the current status is the normal range we will consider it as normal condition
            // REGARDLESS the previous condition.

            switch (last)
            {
            case HRStatus.Hyper:
                // Hypo
                if (HR < minHRBound || HR <= (userPage.avg - 2 * System.Math.Sqrt(userPage.variance))) // or less than HR < |avg -2*std|
                {
                    retStatus = HRStatus.NotStable;
                }
                // Hyper
                if (HR > maxHRBound || HR >= (userPage.avg + 2 * System.Math.Sqrt(userPage.variance)))     // or more than HR > |avg +2*std|
                {
                    retStatus = HRStatus.Hyper;
                }
                break;

            case HRStatus.Hypo:
                // Hypo
                if (HR < minHRBound || HR <= (userPage.avg - 2 * System.Math.Sqrt(userPage.variance)))     // or less than HR < |avg -2*std|
                {
                    retStatus = HRStatus.Hypo;
                }
                // Hyper
                if (HR > maxHRBound || HR >= (userPage.avg + 2 * System.Math.Sqrt(userPage.variance)))     // or more than HR > |avg +2*std|
                {
                    retStatus = HRStatus.NotStable;
                }
                break;

            case HRStatus.NotStable:
                // Check if the limit time of none regular HB time is passed
                if (now.Subtract(notStableTime) < lastItem.time)
                {
                    retStatus = HRStatus.NotStable;
                }
                // Hypo
                if (HR < minHRBound || HR <= (userPage.avg - 2 * System.Math.Sqrt(userPage.variance)))     // or less than HR < |avg -2*std|
                {
                    retStatus = HRStatus.Hypo;
                }
                // Hyper
                if (HR > maxHRBound || HR >= (userPage.avg + 2 * System.Math.Sqrt(userPage.variance)))     // or more than HR > |avg +2*std|
                {
                    retStatus = HRStatus.Hyper;
                }
                break;

            case HRStatus.Normal:
                if (HR < minHRBound || HR <= (userPage.avg - 2 * System.Math.Sqrt(userPage.variance)))     // or less than HR < |avg -2*std|
                {
                    retStatus = HRStatus.Hypo;
                }
                // Hyper
                if (HR > maxHRBound || HR >= (userPage.avg + 2 * System.Math.Sqrt(userPage.variance)))     // or more than HR > |avg +2*std|
                {
                    retStatus = HRStatus.Hyper;
                }
                break;
            }
            // In case of ublormal HR we will remove far history items from statusHistoryList
            if (retStatus != HRStatus.Normal)
            {
                statusHistoryList.RemoveAll(x => now.Subtract(historyTime) >= x.time);
            }

            // In case the status OK
            return(retStatus);
        }
Пример #4
0
 public DisplayRangeOfEntries(user_page o) { o_ = o; }
Пример #5
0
 public RetrieveSingleTableEntry(user_page o) { o_ = o; }
Пример #6
0
 public HeartRateSubscriptionTask(user_page o) { o_ = o; }
Пример #7
0
 public HeartRateConsentTask(user_page o) { o_ = o; }
Пример #8
0
 public HeartRateEventListener(user_page o) { o_ = o; }
Пример #9
0
 public ConsentListener(user_page o) { o_ = o; }