コード例 #1
0
        public ItemViewModel(
            Item item,
            ICommandResult <double> closestPlacesCommand,
            ILocalNotification localNotification,
            ICommand deleteCommand,
            ICategoriesService categoryService,
            IApplicationState applicationState)
        {
            this.closestPlacesCommand    = closestPlacesCommand;
            this.applicationState        = applicationState;
            this.cancellationTokenSource = new CancellationTokenSource();
            this.categoryService         = categoryService;
            this.localNotification       = localNotification;
            this.position      = null;
            this.item          = item;
            this.deleteCommand = deleteCommand;

            this.closestPlacesCommand.Executed += (sender, e) => {
                this.Distance = this.closestPlacesCommand.Result;

                var distanceForNotification = 100;

#if DEBUG
                distanceForNotification = 1000;
#endif

                if (this.Distance <= distanceForNotification && !this.applicationState.GetState())
                {
                    this.localNotification.Notify("Close-by", "Don't forget about your item " + this.Name, this.item.Id);
                }
            };
        }
        public override void PresentLocalNotificationNow
            (string id
            , ILocalNotification notification)
        {
            var notificationObject = PrepareNotificationObject(id, DateTime.Now, notification);

            UnityEngine.iOS.NotificationServices.PresentLocalNotificationNow(notificationObject);
        }
 public static void PresentLocalNotificationNow
     (string id
     , ILocalNotification notification)
 {
     if (manager != null)
     {
         manager.PresentLocalNotificationNow(id, notification);
     }
 }
コード例 #4
0
    /// <summary>
    /// Initialize this instance.
    /// </summary>
    public static void Initialize()
    {
#if UNITY_EDITOR
        notification = new EditorLocalNotification();
#elif UNITY_ANDROID
        notification = new AndroidLocalNotification();
#elif UNITY_IOS
        notification = new IOSLocalNotification();
#endif
        notification.Initialize();
    }
 public static void ScheduleLocalNotification
     (string id
     , DateTime when
     , ILocalNotification notification
     , bool cancelPrevious = false)
 {
     if (manager != null)
     {
         manager.ScheduleLocalNotification(id, when, notification, cancelPrevious);
     }
 }
コード例 #6
0
    public void Initialize()
    {
        ILocalNotification notification = new LocalNotificationForAndroid();

        notification.SmallIcon = "ic_stat_notify_small";
        notification.LargeIcon = "ic_stat_notify_large";

        notification.CreateChannel("sample0916", "sampleName", "sampleDescription");

        Notification = notification;
    }
コード例 #7
0
        public TimerPage()
        {
            InitializeComponent();
            teaTimer.Clear();
            timerViewModel      = new TimerViewModel(StartTimer, ClearTimer, PlusInfTemp, SubInfTemp, ResetInfTemp);
            notificationService = DependencyService.Get <ILocalNotification>();

            var assembly = typeof(App).GetTypeInfo().Assembly;
            var stream   = assembly.GetManifestResourceStream($"GongFuTimer.Audio." + "Alarm.wav");

            alarmPlayer.Load(stream);

            BindingContext = timerViewModel;

            // update loop
            Device.BeginInvokeOnMainThread(MainLoop);
        }
        public override void ScheduleLocalNotification
            (string id
            , DateTime when
            , ILocalNotification notification
            , bool cancelPrevious)
        {
            if (cancelPrevious)
            {
                var scheduledNotification = FindScheduledNotificationById(id);
                if (scheduledNotification != null)
                {
                    UnityEngine.iOS.NotificationServices.CancelLocalNotification(scheduledNotification);
                }
            }

            var notificationObject = PrepareNotificationObject(id, when, notification);

            UnityEngine.iOS.NotificationServices.ScheduleLocalNotification(notificationObject);
        }
コード例 #9
0
        protected async void CheckForClosestNewMark(double currentLatitude, double currentLongitude)
        {
            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>
                {
                    { "latitude", currentLatitude.ToString() },
                    { "longitude", currentLongitude.ToString() }
                };

                Mark closestMark = await AzureWebApi.MobileService.InvokeApiAsync <Mark>("ClosestMark", HttpMethod.Get, parameters);

                if (closestMark != null)
                {
                    ILocalNotification localNotification = CreateLocalNotification();
                    localNotification.Show("mARkIt", "A new mark is closeby!");
                }
            }

            catch (Exception e)
            {
                LogScanningException(e);
            }
        }
コード例 #10
0
ファイル: ItemsViewModel.cs プロジェクト: sebcc/SmartList
        public ItemsViewModel(
            IGeolocatorService geolocator,
            ILocalNotification localNotification,
            ICommandResult <List <Item> > loadItemsCommand,
            ICommandResult <Item> deleteCommand)
        {
            this.loadItemsCommand        = loadItemsCommand;
            this.deleteCommand           = deleteCommand;
            this.cancellationTokenSource = new CancellationTokenSource();

            this.deleteCommand.Executed += (sender, e) => {
                var itemFromList = this.Items.First(i => i.Id == this.deleteCommand.Result.Id);
                this.Items.Remove(itemFromList);
            };

            this.Items = new ObservableCollection <ItemViewModel> ();
            this.loadItemsCommand.Executed += (sender, e) => {
                this.IsRefreshing = false;
                this.Items.Clear();

                var placeApi = new GooglePlacesApi();
                foreach (var item in this.loadItemsCommand.Result)
                {
                    var itemViewModel = new ItemViewModel(
                        item,
                        new FindClosestPlacesCommand(placeApi, geolocator, new CategoriesService(), this.cancellationTokenSource.Token),
                        localNotification,
                        deleteCommand,
                        new CategoriesService(),
                        new ApplicationState());

                    this.Items.Add(itemViewModel);
                    itemViewModel.LoadClosestPlace.Execute(item);
                }
            };
        }
        private UnityEngine.iOS.LocalNotification PrepareNotificationObject(string id, DateTime when, ILocalNotification notification)
        {
            UnityEngine.iOS.LocalNotification notificationObject = new UnityEngine.iOS.LocalNotification();

            notificationObject.userInfo.Add("id", id);

            notificationObject.fireDate    = when;
            notificationObject.alertAction = notification.message;
            notificationObject.alertBody   = notification.message;

            if (notification.useSound)
            {
                if (notification.customSoundName != null)
                {
                    notificationObject.soundName = notification.customSoundName;
                }
                else
                {
                    notificationObject.soundName = UnityEngine.iOS.LocalNotification.defaultSoundName;
                }
            }

            var iosExtension = notification.GetExtension <INotificationExtensionIOS>(false);

            if (iosExtension != null)
            {
                notificationObject.hasAction = iosExtension.hasAction;
                notificationObject.applicationIconBadgeNumber = iosExtension.applicationIconBadgeNumber;


                if (iosExtension.repeatInterval != RepeatInterval.None)
                {
                    switch (iosExtension.repeatInterval)
                    {
                    case RepeatInterval.Era:                notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Era;               break;

                    case RepeatInterval.Year:               notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Year;              break;

                    case RepeatInterval.Month:              notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Month;             break;

                    case RepeatInterval.Day:                notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Day;               break;

                    case RepeatInterval.Hour:               notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Hour;              break;

                    case RepeatInterval.Minute:             notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Minute;            break;

                    case RepeatInterval.Second:             notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Second;            break;

                    case RepeatInterval.Week:               notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Week;              break;

                    case RepeatInterval.Weekday:            notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Weekday;           break;

                    case RepeatInterval.WeekdayOrdinal:     notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.WeekdayOrdinal;    break;

                    case RepeatInterval.Quarter:            notificationObject.repeatInterval = UnityEngine.iOS.CalendarUnit.Quarter;           break;
                    }

                    switch (iosExtension.repeatCalendar)
                    {
                    case CalendarIdentifier.GregorianCalendar:          notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.GregorianCalendar;       break;

                    case CalendarIdentifier.BuddhistCalendar:           notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.BuddhistCalendar;        break;

                    case CalendarIdentifier.ChineseCalendar:            notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ChineseCalendar;         break;

                    case CalendarIdentifier.HebrewCalendar:             notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.HebrewCalendar;          break;

                    case CalendarIdentifier.IslamicCalendar:            notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.IslamicCalendar;         break;

                    case CalendarIdentifier.IslamicCivilCalendar:       notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.IslamicCivilCalendar;    break;

                    case CalendarIdentifier.JapaneseCalendar:           notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.JapaneseCalendar;        break;

                    case CalendarIdentifier.RepublicOfChinaCalendar:    notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.RepublicOfChinaCalendar; break;

                    case CalendarIdentifier.PersianCalendar:            notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.PersianCalendar;         break;

                    case CalendarIdentifier.IndianCalendar:             notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.IndianCalendar;          break;

                    case CalendarIdentifier.ISO8601Calendar:            notificationObject.repeatCalendar = UnityEngine.iOS.CalendarIdentifier.ISO8601Calendar;         break;
                    }
                }
            }

            return(notificationObject);
        }
コード例 #12
0
        public LocalNotificationPage()
        {
            InitializeComponent();

            localNotification = DependencyService.Get <ILocalNotification>();
        }
 public abstract void PresentLocalNotificationNow
     (string id
     , ILocalNotification notification);
 public abstract void ScheduleLocalNotification
     (string id
     , DateTime when
     , ILocalNotification notification
     , bool cancelPrevious);
コード例 #15
0
 public override void PresentLocalNotificationNow
     (string id
     , ILocalNotification notification)
 {
     ScheduleLocalNotification(id, DateTime.UtcNow, notification, true);
 }
コード例 #16
0
        public override void ScheduleLocalNotification
            (string id
            , DateTime when
            , ILocalNotification notification
            , bool cancelPrevious)
        {
            ScheduleMode scheduleMode   = ScheduleMode.None;
            TimeSpan     repeatInterval = TimeSpan.Zero;

            Android.LocalNotifications.NotificationData notificationObject = new Android.LocalNotifications.NotificationData(notification.title, notification.message);

            notificationObject.SetUseSound(notification.useSound);
            notificationObject.SetCustomSoundName(notification.customSoundName);

            var androidExtension = notification.GetExtension <INotificationExtensionAndroid>(false);

            if (androidExtension != null)
            {
                scheduleMode   = androidExtension.scheduleMode;
                repeatInterval = androidExtension.repeatInterval;

                notificationObject.SetTicker(androidExtension.ticker);

                notificationObject.SetSubText(androidExtension.subText);
                notificationObject.SetProgressMax(androidExtension.progressMax);

                notificationObject.SetProgressMax(androidExtension.progressMax);
                notificationObject.SetProgress(androidExtension.progress);
                notificationObject.SetProgressIndeterminate(androidExtension.progressIndeterminate);

                notificationObject.SetGroup(androidExtension.group);
                notificationObject.SetIsGroupSummary(androidExtension.isGroupSummary);
                notificationObject.SetCategory((Android.LocalNotifications.NotificationData.Category)androidExtension.category);

                notificationObject.SetAutoCancel(androidExtension.autoCancel);
                notificationObject.SetLocalOnly(androidExtension.localOnly);
                notificationObject.SetOngoing(androidExtension.ongoing);
                notificationObject.SetOnlyAlertOnce(androidExtension.onlyAlertOnce);
                notificationObject.SetPriority((Android.LocalNotifications.NotificationData.Priority)androidExtension.priority);

                notificationObject.SetShowWhen(androidExtension.showWhen);
                notificationObject.SetWhenIsChronometer(androidExtension.whenIsChronometer);
                notificationObject.SetChronometerCountdown(androidExtension.chronometerCountdown);
                notificationObject.SetCustomWhenDate(androidExtension.customWhenDate);
                notificationObject.SetCustomWhenChronometer(androidExtension.customWhenChronometer);

                notificationObject.SetColor(androidExtension.color);

                notificationObject.SetUseVibration(notificationObject.useVibration);
                notificationObject.SetVibrationPattern(androidExtension.vibrationPattern);

                notificationObject.SetUseLights(androidExtension.useLights);
                notificationObject.SetLightsColor(androidExtension.lightsColor);
                notificationObject.SetLightsOn(androidExtension.lightsOn);
                notificationObject.SetLightsOff(androidExtension.lightsOff);

                notificationObject.SetSmallIconResource(androidExtension.smallIconResource);
                notificationObject.SetLargeIconResource(androidExtension.largeIconResource);

                notificationObject.SetPerson(androidExtension.person);
            }

            if (repeatInterval > TimeSpan.Zero)
            {
                Android.LocalNotifications.LocalNotification.SendNotification
                    (id, when, notificationObject, cancelPrevious, (Android.LocalNotifications.LocalNotification.ScheduleMode)scheduleMode);
            }
            else
            {
                Android.LocalNotifications.LocalNotification.SendNotification
                    (id, when, repeatInterval, notificationObject, cancelPrevious, (Android.LocalNotifications.LocalNotification.ScheduleMode)scheduleMode);
            }
        }