Exemplo n.º 1
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            AppSettingsService.Initialize();

            App.Current.RequestedTheme =
                (int)AppSettingsService.GetSetting(AppSettingsService.THEME_SETTINGS) == 0 ? ApplicationTheme.Dark : ApplicationTheme.Light;
        }
Exemplo n.º 2
0
 public Temperature()
 {
     try
     {
         TemperatureUnit = (bool)AppSettingsService.GetSetting(AppSettingsService.TEMPERATURE_UNIT);
     }
     catch
     {
         TemperatureUnit = true;
     }
 }
Exemplo n.º 3
0
        public SettingsViewModel()
        {
            IsLoading           = false;
            DefaultLocationMode = (int)AppSettingsService.GetSetting(AppSettingsService.DEFAULT_LOCATION_MODE);

            var temp_dl = AppSettingsService.GetSetting(AppSettingsService.DEFAULT_LOCATION);

            DefaultLocation = temp_dl == null ? null : temp_dl.ToString();

            var temp_dlfn = AppSettingsService.GetSetting(AppSettingsService.DEFAULT_LOCATION_FULL_NAME);

            DefaultLocationFullName = temp_dlfn == null ? "Specific location" : temp_dlfn.ToString();
        }
Exemplo n.º 4
0
        public MainViewModel()
        {
            RegionCollection   = new RegionCollection();
            _SelectedRegion    = RegionCollection.GetRegion(AppSettingsService.GetSetting(AppSettingsService.REGION_SETTINGS).ToString());
            _NumberOfImageLoad = (double)AppSettingsService.GetSetting(AppSettingsService.NUMBER_OF_IMAGE_LOAD_SETTINGS);

            DefaultSave             = (bool)AppSettingsService.GetSetting(AppSettingsService.DEFAULT_SAVE_SETTINGS);
            DefaultSaveLocationPath = AppSettingsService.GetSetting(AppSettingsService.DEFAULT_SAVE_LOCATION_SETTINGS).ToString();

            AutoWallpaper              = (bool)AppSettingsService.GetSetting(AppSettingsService.AUTO_WALLPAPER_SETTINGS);
            AutoWallpaper_Wifi         = (bool)AppSettingsService.GetSetting(AppSettingsService.AUTO_WALLPAPER_WIFI_SETTINGS);
            IsAutoWallpaperTaskLoading = false;

            LiveTile      = (bool)AppSettingsService.GetSetting(AppSettingsService.LIVE_TILE_SETTINGS);
            LiveTile_Wifi = (bool)AppSettingsService.GetSetting(AppSettingsService.LIVE_TILE_WIFI_SETTINGS);
            IsLiveTileBackgroundTaskLoading = false;

            AutoSave                        = (bool)AppSettingsService.GetSetting(AppSettingsService.AUTO_SAVE_SETTINGS);
            AutoSaveLocationPath            = AppSettingsService.GetSetting(AppSettingsService.AUTO_SAVE_LOCATION_SETTINGS).ToString();
            AutoSave_Wifi                   = (bool)AppSettingsService.GetSetting(AppSettingsService.AUTO_SAVE_WIFI_SETTINGS);
            IsAutoSaveBackgroundTaskLoading = false;

            Theme = (int)AppSettingsService.GetSetting(AppSettingsService.THEME_SETTINGS);
        }
Exemplo n.º 5
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var _deferral = taskInstance.GetDeferral();

            try
            {
                taskInstance.Canceled += TaskInstance_Canceled;

                if (cts == null)
                {
                    cts = new CancellationTokenSource();
                }

                bool   canRun = true;
                double lat = 0, lon = 0;

                #region Get Coord
                if ((int)AppSettingsService.GetSetting("default_location_mode") == 0)
                {
                    Geolocator geo = new Geolocator();
                    var        pos = await geo.GetGeopositionAsync().AsTask(cts.Token);

                    lat = pos.Coordinate.Point.Position.Latitude;
                    lon = pos.Coordinate.Point.Position.Longitude;
                }
                else
                {
                    string[] temp = AppSettingsService.GetSetting("default_location").ToString().Split('|');
                    lat = double.Parse(temp[0]);
                    lon = double.Parse(temp[1]);
                }
                #endregion

                if (canRun)
                {
                    var    http      = new HttpClient();
                    string xmlString = await http.GetStringAsync(new Uri($"http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&units=metric&mode=xml&appid={APIKEY}")).AsTask(cts.Token);

                    XmlSerializer  serializer = new XmlSerializer(typeof(OpenWeatherObj));
                    OpenWeatherObj obj;
                    using (TextReader reader = new StringReader(xmlString))
                    {
                        obj = (OpenWeatherObj)serializer.Deserialize(reader);
                    }

                    var liveTile = TileUpdateManager.CreateTileUpdaterForApplication();

                    string temperature = obj.temperature.TemperatureUnit ? $"{obj.temperature.temp_c}C" : $"{obj.temperature.temp_f}F";
                    string time        = DateTime.Now.ToString("ddd h:mm tt");

                    //tile template
                    string tileXMLString = $@"<tile>
                                                <visual baseUri=""Assets/Weather/"">
                                              
                                                  <binding template=""TileSmall"" hint-textStacking=""center"">
                                                    <text hint-style=""body"" hint-align=""center"">{temperature}</text>
                                                  </binding>
                                              
                                                  <binding displayName=""{obj.city.name}"" template=""TileMedium"" hint-textStacking=""center"">
                                                    <text hint-style=""body"" hint-align=""center"">{obj.weather.value}</text>
                                                    <text hint-style=""titleSubtle"" hint-align=""center"">{temperature}</text>
                                                    <text hint-style=""captionSubtle"" hint-align=""center"">{time}</text>
                                                  </binding>
                                              
                                                  <binding displayName=""{obj.city.name}"" template=""TileWide"" branding=""nameAndLogo"" hint-textStacking=""center"">
                                                    <group>
                                                      <subgroup hint-weight=""44"">
                                                        <image src=""{obj.weather.iconUrl}"" hint-removeMargin=""false""/>
                                                      </subgroup>
                                                      <subgroup>
                                                        <text hint-style=""body"">{obj.weather.value}</text>
                                                        <text hint-style=""titleSubtle"">{temperature}</text>
                                                        <text hint-style=""captionSubtle"">{time}</text>
                                                      </subgroup>
                                                    </group>
                                                  </binding>
                                              
                                                  <binding displayName=""{obj.city.name}"" template=""TileLarge"" branding=""nameAndLogo"" hint-textStacking=""center"">
                                                    <group>
                                                      <subgroup hint-weight=""1""/>
                                                      <subgroup hint-weight=""2"">
                                                        <image src=""{obj.weather.iconUrl}""/>
                                                      </subgroup>
                                                      <subgroup hint-weight=""1""/>
                                                    </group>
                                                    <text hint-style=""body"" hint-align=""center"">{obj.weather.value}</text>
                                                    <text hint-style=""titleSubtle"" hint-align=""center"">{temperature}</text>
                                                    <text hint-style=""captionSubtle"" hint-align=""center"">{time}</text>
                                                  </binding>
                                              
                                                </visual>
                                              </tile>";

                    XmlDocument tileXML = new XmlDocument();
                    tileXML.LoadXml(tileXMLString);
                    liveTile.Update(new TileNotification(tileXML));
                }
            }
            catch (Exception) { }
            finally
            {
                _deferral.Complete();
            }
        }
Exemplo n.º 6
0
        public async Task LoadCurrentWeatherAsync()
        {
            IsLoading      = true;
            Status         = 0;
            CurrentWeather = null;

            //get coordinate
            double lat = 0, lon = 0;

            if ((int)AppSettingsService.GetSetting(AppSettingsService.DEFAULT_LOCATION_MODE) == 0)
            {
                var accessStatus = await Geolocator.RequestAccessAsync();

                switch (accessStatus)
                {
                case GeolocationAccessStatus.Allowed:
                    Geolocator  geolocator = new Geolocator();
                    Geoposition pos        = await geolocator.GetGeopositionAsync();

                    lat = pos.Coordinate.Point.Position.Latitude;
                    lon = pos.Coordinate.Point.Position.Longitude;
                    break;

                case GeolocationAccessStatus.Unspecified:
                case GeolocationAccessStatus.Denied:
                    Status = 1;
                    break;
                }
            }
            else
            {
                string[] temp = AppSettingsService.GetSetting(AppSettingsService.DEFAULT_LOCATION).ToString().Split('|');
                lat = double.Parse(temp[0]);
                lon = double.Parse(temp[1]);
            }

            //http call
            if (Status == 0)
            {
                if (IsInternetAvailable())
                {
                    try
                    {
                        CurrentWeather = await OpenWeatherService.GetWeatherByCoordinateAsync(lat, lon);

                        #region Update live tile
                        var liveTile = TileUpdateManager.CreateTileUpdaterForApplication();

                        string temperature = CurrentWeather.temperature.TemperatureUnit ? $"{CurrentWeather.temperature.temp_c}C" : $"{CurrentWeather.temperature.temp_f}F";
                        string time        = DateTime.Now.ToString("ddd h:mm tt");

                        //tile template
                        string tileXMLString = $@"<tile>
                                                    <visual baseUri=""Assets/Weather/"">
                                                  
                                                      <binding template=""TileSmall"" hint-textStacking=""center"">
                                                        <text hint-style=""body"" hint-align=""center"">{temperature}</text>
                                                      </binding>
                                                  
                                                      <binding displayName=""{CurrentWeather.city.name}"" template=""TileMedium"" hint-textStacking=""center"">
                                                        <text hint-style=""body"" hint-align=""center"">{CurrentWeather.weather.value}</text>
                                                        <text hint-style=""titleSubtle"" hint-align=""center"">{temperature}</text>
                                                        <text hint-style=""captionSubtle"" hint-align=""center"">{time}</text>
                                                      </binding>
                                                  
                                                      <binding displayName=""{CurrentWeather.city.name}"" template=""TileWide"" branding=""nameAndLogo"" hint-textStacking=""center"">
                                                        <group>
                                                          <subgroup hint-weight=""44"">
                                                            <image src=""{CurrentWeather.weather.iconUrl}"" hint-removeMargin=""false""/>
                                                          </subgroup>
                                                          <subgroup>
                                                            <text hint-style=""body"">{CurrentWeather.weather.value}</text>
                                                            <text hint-style=""titleSubtle"">{temperature}</text>
                                                            <text hint-style=""captionSubtle"">{time}</text>
                                                          </subgroup>
                                                        </group>
                                                      </binding>
                                                  
                                                      <binding displayName=""{CurrentWeather.city.name}"" template=""TileLarge"" branding=""nameAndLogo"" hint-textStacking=""center"">
                                                        <group>
                                                          <subgroup hint-weight=""1""/>
                                                          <subgroup hint-weight=""2"">
                                                            <image src=""{CurrentWeather.weather.iconUrl}""/>
                                                          </subgroup>
                                                          <subgroup hint-weight=""1""/>
                                                        </group>
                                                        <text hint-style=""body"" hint-align=""center"">{CurrentWeather.weather.value}</text>
                                                        <text hint-style=""titleSubtle"" hint-align=""center"">{temperature}</text>
                                                        <text hint-style=""captionSubtle"" hint-align=""center"">{time}</text>
                                                      </binding>
                                                  
                                                    </visual>
                                                  </tile>";

                        XmlDocument tileXML = new XmlDocument();
                        tileXML.LoadXml(tileXMLString);
                        liveTile.Update(new TileNotification(tileXML));
                        #endregion
                    }
                    catch
                    {
                        Status = 2;
                    }
                }
                else
                {
                    Status = 2;
                }
            }

            IsLoading = false;
        }
 public Temperature()
 {
     TemperatureUnit = (bool)AppSettingsService.GetSetting("temperature_unit");
 }