// set starttime based on user location
        public async void ActivateLocationMode()
        {
            //ui
            StackPanelTimePicker.Visibility   = Visibility.Collapsed;
            TextBlockDark.Visibility          = Visibility.Collapsed;
            TextBlockLight.Visibility         = Visibility.Collapsed;
            StackPanelLocationTime.Visibility = Visibility.Visible;
            SetOffsetVisibility(Visibility.Visible);
            locationBlock.Visibility = Visibility.Visible;
            locationBlock.Text       = Properties.Resources.msgSearchLoc;//Searching your location...
            userFeedback.Text        = Properties.Resources.msgSearchLoc;

            LocationHandler locationHandler = new LocationHandler();
            var             accesStatus     = await Geolocator.RequestAccessAsync();

            switch (accesStatus)
            {
            case GeolocationAccessStatus.Allowed:
                //locate user + get sunrise & sunset times
                locationBlock.Text = Properties.Resources.lblCity + ": " + await locationHandler.GetCityName();

                int[] sundate = await locationHandler.CalculateSunTime(false);

                //apply settings
                ApplyTheme(sundate[2], sundate[3], sundate[0], sundate[1]);

                //show time in UI
                if (Properties.Settings.Default.AlterTime)
                {
                    sundate[2] -= 12;
                }

                TimeSpan TimeForUiLight = new TimeSpan(sundate[0], sundate[1], 0);
                TimeSpan TimeForUiDark  = new TimeSpan(sundate[2], sundate[3], 0);
                TextBlockLightTime.Text = Properties.Resources.lblLight + ": " + string.Format("{0:00}:{1:00}", TimeForUiLight.Hours, TimeForUiLight.Minutes); //textblock1
                TextBlockDarkTime.Text  = Properties.Resources.lblDark + ": " + string.Format("{0:00}:{1:00}", TimeForUiDark.Hours, TimeForUiDark.Minutes);    //textblock2

                // ui controls
                lightStartBox.IsEnabled        = false;
                LightStartMinutesBox.IsEnabled = false;
                darkStartBox.IsEnabled         = false;
                DarkStartMinutesBox.IsEnabled  = false;

                applyButton.Visibility = Visibility.Hidden;
                taskSchHandler.CreateLocationTask();
                break;

            case GeolocationAccessStatus.Denied:
                NoLocationAccess();
                break;

            case GeolocationAccessStatus.Unspecified:
                NoLocationAccess();
                break;
            }
            return;
        }
Ejemplo n.º 2
0
        public async void GetLocation()
        {
            SetOffsetVisibility(Visibility.Visible);
            locationBlock.Visibility = Visibility.Visible;
            locationBlock.Text       = Properties.Resources.msgSearchLoc;//Searching your location...
            LocationHandler locationHandler = new LocationHandler();

            var accesStatus = await Geolocator.RequestAccessAsync();

            switch (accesStatus)
            {
            case GeolocationAccessStatus.Allowed:
                //locate user + get sunrise & sunset times
                locationBlock.Text = Properties.Resources.lblCity + ": " + await locationHandler.GetCityName();

                int[] sundate = await locationHandler.CalculateSunTime(false);

                //apply settings & change UI
                lightStartBox.Text        = sundate[0].ToString();
                LightStartMinutesBox.Text = sundate[1].ToString();
                if (Properties.Settings.Default.AlterTime)
                {
                    sundate[2]       -= 12;
                    darkStartBox.Text = sundate[2].ToString();
                }
                else
                {
                    darkStartBox.Text = sundate[2].ToString();
                }
                DarkStartMinutesBox.Text       = sundate[3].ToString();
                lightStartBox.IsEnabled        = false;
                LightStartMinutesBox.IsEnabled = false;
                darkStartBox.IsEnabled         = false;
                DarkStartMinutesBox.IsEnabled  = false;
                applyButton.IsEnabled          = false;
                ApplyButton_Click(this, null);
                taskShedHandler.CreateLocationTask();
                break;

            case GeolocationAccessStatus.Denied:
                NoLocationAccess();
                break;

            case GeolocationAccessStatus.Unspecified:
                NoLocationAccess();
                break;
            }
            return;
        }