コード例 #1
0
        public async void SetAlert(StationFeature selectedFeature)
        {
            string err = string.Empty;

            try
            {
                //set CurrentReminder
                if (this.CurrentStation != null)
                {
                    ReminderStation    newAlert = new ReminderStation();
                    List <StationInfo> infoList = new List <StationInfo>();
                    foreach (StationFeature feature in this.CurrentStation.response.resultSet.busLine.stationData.StationFeatures)
                    {
                        if (feature.type.StartsWith("L"))
                        {
                            continue;
                        }
                        StationInfo info = new StationInfo();
                        info.stationId = feature.stationId;
                        info.caption   = feature.caption;
                        string[] points = feature.points.txt.Split(',');
                        info.longitude = double.Parse(points[0]);
                        info.latitude  = double.Parse(points[1]);
                        if (selectedFeature.stationId.Equals(feature.stationId))
                        {
                            info.isReminder   = true;
                            info.displayText  = info.caption + "                     (到站提醒)";
                            info.displayStyle = "ReminderTextStyle";
                        }
                        else
                        {
                            info.isReminder   = false;
                            info.displayText  = info.caption;
                            info.displayStyle = "BasicTextStyle";
                        }
                        infoList.Add(info);
                    }
                    newAlert.name            = this.CurrentStation.response.resultSet.busLine.name;
                    newAlert.StationInfos    = infoList.ToArray();
                    newAlert.alertResponse   = false;
                    newAlert.alertDisplaying = false;

                    this.ResetReminder(newAlert);
                    loadView(typeof(ReminderPage));
                }
                else
                {
                    this.ShowStationChoose();
                    var messageDialog = new MessageDialog("请先选择线路!");
                    await messageDialog.ShowAsync();
                }
            }
            catch (Exception e)
            {
                err = e.Message;
            }
            if (err != null && err != string.Empty)
            {
                this.ShowStationChoose();
                var messageDialog = new MessageDialog("线路数据有误,请重新选择");
                await messageDialog.ShowAsync();
            }
        }
コード例 #2
0
        public async void CheckReminder()
        {
            lock (reminderLock)
            {
                if (this.CurrentReminderStation != null)
                {
                    bool        needAlert    = false;
                    StationInfo neareastInfo = null;
                    double      distance     = double.MaxValue;

                    foreach (StationInfo info in this.CurrentReminderStation.StationInfos)
                    {
                        double len = (info.longitude - this.CurrentSogoLongitude) * (info.longitude - this.CurrentSogoLongitude) +
                                     (info.latitude - this.CurrentSogoLatitude) * (info.latitude - this.CurrentSogoLatitude);
                        if (info.isReminder && len < MinDistanceToAlert)
                        {
                            needAlert    = true;
                            neareastInfo = info;
                            distance     = len;
                            break;
                        }

                        if (len < distance)
                        {
                            distance     = len;
                            neareastInfo = info;
                        }
                    }

                    if (neareastInfo != null)
                    {
                        this.CurrentReminderStation.status = "靠近站点" + neareastInfo.caption;
                    }

                    if (needAlert && !this.CurrentReminderStation.alertResponse)
                    {
                        if (this.notification != null && this.CurrentReminderStation.alertDisplaying)
                        {
                            return;
                        }
                        this.CurrentReminderStation.needAlert = true;
                        this.CurrentReminderStation.status    = "即将到站!!!" + this.CurrentReminderStation.status;
                        IToastText02 toastContent = ToastContentFactory.CreateToastText02();

                        // Set the launch activation context parameter on the toast.
                        // The context can be recovered through the app Activation event
                        toastContent.Launch = "reminder";

                        toastContent.TextHeading.Text  = "即将到站提醒";
                        toastContent.TextBodyWrap.Text = neareastInfo.caption + " 就要到了,请准备下车,以免坐过站";

                        this.notification            = toastContent.CreateNotification();
                        this.notification.Dismissed += toast_Dismissed;

                        ToastNotificationManager.CreateToastNotifier().Show(this.notification);
                        this.CurrentReminderStation.alertDisplaying = true;
                        this.loadView(typeof(ReminderPage));
                    }
                }
            }
        }