Ejemplo n.º 1
0
        public DestinationPickPage(string navigationGraphName, CategoryType category)
        {
            InitializeComponent();

            const string resourceId = "IndoorNavigation.Resources.AppResources";

            _resourceManager = new ResourceManager(resourceId, typeof(TranslateExtension).GetTypeInfo().Assembly);

            _destinationItems = new ObservableCollection <DestinationItem>();

            _navigationGraphName = navigationGraphName;

            _navigationGraph = NavigraphStorage.LoadNavigationGraphXML(navigationGraphName);
            if (CrossMultilingual.Current.CurrentCultureInfo.ToString() == "en" || CrossMultilingual.Current.CurrentCultureInfo.ToString() == "en-US")
            {
                _nameInformation = NavigraphStorage.LoadInformationML(navigationGraphName + "_info_en-US.xml");
            }
            else if (CrossMultilingual.Current.CurrentCultureInfo.ToString() == "zh" || CrossMultilingual.Current.CurrentCultureInfo.ToString() == "zh-TW")
            {
                _nameInformation = NavigraphStorage.LoadInformationML(navigationGraphName + "_info_zh.xml");
            }

            NavigationPage.SetBackButtonTitle(this, _resourceManager.GetString("BACK_STRING", CrossMultilingual.Current.CurrentCultureInfo));

            foreach (KeyValuePair <Guid, IndoorNavigation.Models.Region> pairRegion in _navigationGraph.GetRegions())
            {
                string floorName = _nameInformation.GiveRegionName(pairRegion.Value._id);
                if (pairRegion.Value._waypointsByCategory.ContainsKey(category))
                {
                    foreach (Waypoint waypoint in pairRegion.Value._waypointsByCategory[category])
                    {
                        string waypointName = waypoint._name;
                        waypointName = _nameInformation.GiveWaypointName(waypoint._id);
                        if (waypoint._type.ToString() == "terminal" || waypoint._type.ToString() == "landmark")
                        {
                            Console.WriteLine("check type : " + waypoint._type.ToString());
                            _destinationItems.Add(new DestinationItem
                            {
                                _regionID     = pairRegion.Key,
                                _waypointID   = waypoint._id,
                                _waypointName = waypointName,
                                _floor        = floorName
                            });
                        }
                        else
                        {
                            Console.WriteLine("Portal, No need to add!!");
                        }
                    }
                }
            }

            MyListView.ItemsSource = from waypoint in _destinationItems
                                     group waypoint by waypoint._floor into waypointGroup
                                     orderby waypointGroup.Key
                                     select new Grouping <string, DestinationItem>(waypointGroup.Key,
                                                                                   waypointGroup);
        }
        /// <summary>
        /// According to each navigation status displays the text and image instructions in UI.
        /// </summary>
        /// <param name="args">Arguments.</param>
        private void DisplayInstructions(EventArgs args)
        {
            Console.WriteLine(">> DisplayInstructions");
            NavigationInstruction instruction = (args as Session.NavigationEventArgs)._nextInstruction;
            var    currentLanguage            = CrossMultilingual.Current.CurrentCultureInfo;
            string currentStepImage;
            string currentStepLabel;
            //string currentWaypointName;
            string firstDirectionPicture = null;
            int    rotationValue         = 0;
            int    locationValue         = _originalInstructionLocation;
            int    instructionScale      = _originalInstructionScale;

            switch ((args as Session.NavigationEventArgs)._result)
            {
            case NavigationResult.Run:
                SetInstruction(instruction, out currentStepLabel, out currentStepImage, out firstDirectionPicture, out rotationValue, out locationValue, out instructionScale);
                CurrentStepLabel         = currentStepLabel;
                CurrentStepImage         = currentStepImage;
                FirstDirectionPicture    = firstDirectionPicture;
                InstructionLocationValue = locationValue;
                RotationValue            = rotationValue;
                InstructionScaleValue    = instructionScale;
                CurrentWaypointName      = _xmlInformation.GiveWaypointName(instruction._currentWaypointGuid);
                NavigationProgress       = instruction._progress;

                Utility._textToSpeech.Speak(
                    CurrentStepLabel,
                    _resourceManager.GetString("CULTURE_VERSION_STRING", currentLanguage));
                //System.Threading.Thread.Sleep(_millisecondsTimeoutForOneSecond);
                break;

            case NavigationResult.AdjustRoute:
                CurrentStepLabel =
                    _resourceManager.GetString("DIRECTION_WRONG_WAY_STRING", currentLanguage);
                CurrentStepImage = "Waiting";

                Utility._textToSpeech.Speak(
                    CurrentStepLabel,
                    _resourceManager.GetString("CULTURE_VERSION_STRING", currentLanguage));
                //System.Threading.Thread.Sleep(_millisecondsTimeoutForTwoSecond);
                break;

            case NavigationResult.Arrival:
                CurrentWaypointName = _xmlInformation.GiveWaypointName(_destinationID);
                CurrentStepLabel    =
                    _resourceManager.GetString("DIRECTION_ARRIVED_STRING", currentLanguage);
                CurrentStepImage   = "Arrived";
                NavigationProgress = 100;

                Utility._textToSpeech.Speak(
                    CurrentStepLabel,
                    _resourceManager.GetString("CULTURE_VERSION_STRING", currentLanguage));
                Stop();
                break;

            case NavigationResult.NoRoute:
                Console.WriteLine("No Route");
                GoAdjustAvoidType();
                Stop();
                break;

            case NavigationResult.ArriveVirtualPoint:
                SetInstruction(instruction, out currentStepLabel, out currentStepImage, out firstDirectionPicture, out rotationValue, out locationValue, out instructionScale);
                CurrentStepLabel         = currentStepLabel;
                CurrentStepImage         = "Arrived";
                NavigationProgress       = 100;
                CurrentWaypointName      = _xmlInformation.GiveWaypointName(instruction._currentWaypointGuid);
                FirstDirectionPicture    = firstDirectionPicture;
                InstructionLocationValue = locationValue;
                RotationValue            = rotationValue;
                Utility._textToSpeech.Speak(
                    CurrentStepLabel,
                    _resourceManager.GetString("CULTURE_VERSION_STRING", currentLanguage));

                Stop();
                break;
            }
        }