}// end of method UpdateClock /// <summary> /// Update the widget to use the selected icon set. /// </summary> private void UpdateIconSet() { string ico = WeatherLionMain.storedPreferences.StoredPreferences.IconSet; WeatherLionMain.iconSet = ico != null && ico.Equals("default") ? WeatherLionMain.DEFAULT_ICON_SET : ico; // indicate that the icons are being changed iconSetSwtich = true; // update based on time of day CheckAstronomy(); StringBuilder wxImage = null; // Update five day weather icons for (int i = 1; i < 6; i++) { wxImage = new StringBuilder( $"{WEATHER_IMAGE_PATH_PREFIX}{WeatherLionMain.iconSet}/weather_" + UtilityMethod.weatherImages[ UtilityMethod.controlTip.GetToolTip((PictureBox)Controls.Find($"picDay{i}Image", true)[0]).ToLower()]); Image fxImage = UtilityMethod.ResizeImage(Image.FromFile(wxImage.ToString()), 40, 40); ((PictureBox)Controls.Find($"picDay{i}Image", true)[0]).Image = fxImage; }// end of for loop // Refresh the widget UI Refresh(); }// end of method UpdateIconSet
}// end of method LoadFont #endregion #region Action Methods /// <summary> /// Determines the time of day to ensure correct icons are displayed. /// </summary> public void CheckAstronomy() { btnSunrise.Text = WidgetUpdateService.sunriseTime.ToString(); btnSunset.Text = WidgetUpdateService.sunsetTime.ToString(); Image wxImage = null; // update icons based on the time of day in relation to sunrise and sunset times if (WidgetUpdateService.sunriseTime != null && WidgetUpdateService.sunsetTime != null) { DateTime rightNow = DateTime.Now; DateTime rn = DateTime.Now; // date time right now (rn) DateTime?nf = null; // date time night fall (nf) DateTime?su = null; // date time sun up (su) try { string sunsetTwenty4HourTime = $"{rightNow.ToString("yyyy-MM-dd")} " + $"{UtilityMethod.Get24HourTime(WidgetUpdateService.sunsetTime.ToString())}"; string sunriseTwenty4HourTime = $"{rightNow.ToString("yyyy-MM-dd")} " + $"{UtilityMethod.Get24HourTime(WidgetUpdateService.sunriseTime.ToString())}"; nf = Convert.ToDateTime(sunsetTwenty4HourTime); su = Convert.ToDateTime(sunriseTwenty4HourTime); } // end of try block catch (FormatException e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"{TAG}::CheckAstronomy [line: {UtilityMethod.GetExceptionLineNumber(e)}]"); }// end of catch block StringBuilder currentConditionIcon = new StringBuilder(); string currentCondition = UtilityMethod.ValidateCondition( WidgetUpdateService.currentCondition.ToString()); if (rn == nf || rn > nf || rn < su) { if (currentCondition.ToLower().Contains("(night)")) { currentConditionIcon.Clear(); currentConditionIcon.Append( (string)UtilityMethod.weatherImages[currentCondition.ToLower()] ); }// end of if block else { // Yahoo has a habit of having sunny nights if (WidgetUpdateService.currentCondition.ToString().ToLower().Equals("sunny")) { WidgetUpdateService.currentCondition.Clear(); WidgetUpdateService.currentCondition.Append("Clear"); lblWeatherCondition.Text = UtilityMethod.ToProperCase( WidgetUpdateService.currentCondition.ToString()); }// end of if block if (UtilityMethod.weatherImages.ContainsKey($"{currentCondition.ToLower()} (night)")) { currentConditionIcon.Clear(); currentConditionIcon.Append((string)UtilityMethod.weatherImages[$"{currentCondition.ToLower()} (night)"]); }// end of if block else { currentConditionIcon.Clear(); currentConditionIcon.Append((string)UtilityMethod.weatherImages[currentCondition.ToLower()]); } // end of else block } // end of else block if (!sunsetUpdatedPerformed && !sunsetIconsInUse) { // Set image tooltip to current condition string UtilityMethod.AddControlToolTip(picCurrentConditions, WidgetUpdateService.currentCondition.ToString().ToProperCase()); sunsetIconsInUse = true; sunriseIconsInUse = false; sunsetUpdatedPerformed = true; sunriseUpdatedPerformed = false; }// end of if block else if (iconSetSwtich) { // reset the flag after switch is made iconSetSwtich = false; } // end of else if block } // end of if block else if (iconSetSwtich) { currentConditionIcon.Clear(); currentConditionIcon.Append((string)UtilityMethod.weatherImages[currentCondition.ToLower()]); // reset the flag after switch is made iconSetSwtich = false; }// end of else if block else { currentConditionIcon.Clear(); currentConditionIcon.Append((string)UtilityMethod.weatherImages[currentCondition.ToLower()]); if (!sunriseUpdatedPerformed && !sunriseIconsInUse) { // Set image tooltip to current condition string UtilityMethod.AddControlToolTip(picCurrentConditions, WidgetUpdateService.currentCondition.ToString().ToProperCase()); sunriseUpdatedPerformed = true; sunsetUpdatedPerformed = false; }// end of if block else if (iconSetSwtich) { // Set image tooltip to current condition string UtilityMethod.AddControlToolTip(picCurrentConditions, WidgetUpdateService.currentCondition.ToString().ToProperCase()); // reset the flag after switch is made iconSetSwtich = false; }// end of else if block else { sunriseIconsInUse = true; sunsetIconsInUse = false; } // end of else block } // end of else block if (currentConditionIcon.Length == 0) { currentConditionIcon.Append("na.png"); }// end of if block string imagePath = $"{WEATHER_IMAGE_PATH_PREFIX}" + $"{WeatherLionMain.storedPreferences.StoredPreferences.IconSet}" + $"/weather_{currentConditionIcon}"; wxImage = Image.FromFile(imagePath); if (imagePath.Contains("google now") || imagePath.Contains("miui") || imagePath.Contains("weezle")) { picCurrentConditions.Image = UtilityMethod.ResizeImage(wxImage, 120, 120); }// end of if block else { picCurrentConditions.Image = UtilityMethod.ResizeImage(wxImage, 140, 140); } // end of else block } // end of if block } // end of method CheckAstronomy