private void ShowForecastDescriptionMarquee(string marquee) { if ((PanoramaMainView.SelectedItem as PanoramaItem).Name == PIWeather.Name) { TxtForecastDescription.Text = WeatherUnitsConverter.ConvertDeg(marquee); Canvas canvas = TxtForecastDescription.Parent as Canvas; if (canvas.Clip == null) { canvas.Clip = new RectangleGeometry(); (canvas.Clip as RectangleGeometry).Rect = new Rect(0, 0, PIWeather.ActualWidth, TxtForecastDescription.ActualHeight); } if (sbWeatherForecastDesc.GetCurrentState() != ClockState.Stopped) { sbWeatherForecastDesc.Stop(); } sbWeatherForecastDesc.Children.Clear(); sbWeatherForecastDesc.Children.Add(GetForecastDescriptionAnimation()); sbWeatherForecastDesc.Completed += new EventHandler((object obj, EventArgs ev) => { TxtForecastDescription.Text = string.Empty; TxtForecastDescription.Visibility = System.Windows.Visibility.Collapsed; }); sbWeatherForecastDesc.Begin(); } }
public static Canvas GetWeatherCanvas(double width, double height, LockscreenData data) { Canvas weatherCanvas = new Canvas(); weatherCanvas.Width = width; weatherCanvas.Height = height; Thickness margin = new Thickness(10 * data.FontRatio); if (data.LiveWeather != null) { WeatherIconType type = WeatherIconMap.Instance.WeatherIconType; string path = string.Format(WeatherBug.ICON_LOCAL_PATH.Substring(1), type.ToString().ToLower(), "125x105", WeatherImageIconConverter.GetIamgetName(data.LiveWeather.CurrentConditionIcon)); //string path = string.Format(WeatherBug.ICON_LOCAL_PATH.Substring(1), "125x105", WeatherImageIconConverter.GetIamgetName(data.LiveWeather.CurrentConditionIcon)); WriteableBitmap weatherWb = BitmapFactory.New(0, 0).FromContent(path); //날씨 이미지 Image ImgLiveWeather = new Image() { Margin = new Thickness(margin.Left, 0, 0, 0), Source = weatherWb, Height = 140 * data.FontRatio, Width = weatherCanvas.Width / 2 }; string tmp = System.Globalization.CultureInfo.CurrentCulture.Name.Split('-')[0]; if (tmp == "ko" || tmp == "ja" || tmp == "zh") { tmp = (string.IsNullOrEmpty(data.LiveWeather.Station.State) ? string.Empty : data.LiveWeather.Station.State + " ") + data.LiveWeather.Station.City; } else { tmp = data.LiveWeather.Station.City + (string.IsNullOrEmpty(data.LiveWeather.Station.State) ? string.Empty : " ," + data.LiveWeather.Station.State); } //지역 TextBlock TxtLocation = new TextBlock() { Text = tmp, FontSize = data.FontSizeLarge, Foreground = data.ForegroundBrush, Width = ImgLiveWeather.Width * 2.1, FontWeight = data.FontWeight }; if (TxtLocation.ActualWidth > weatherCanvas.Width) { TxtLocation.Text = data.LiveWeather.Station.City; } Canvas tempImageCanvas = new Canvas() { Width = ImgLiveWeather.Width, Height = ImgLiveWeather.Height }; Canvas tempTextCanvas = new Canvas() { Width = tempImageCanvas.Width, Height = tempImageCanvas.Height }; Canvas etcWeaterCanvas = new Canvas() { Width = weatherCanvas.Width, Height = 32 * data.FontRatio }; Canvas.SetLeft(TxtLocation, margin.Left); Canvas.SetTop(TxtLocation, margin.Top); Canvas.SetLeft(tempTextCanvas, margin.Left); Canvas.SetTop(tempTextCanvas, margin.Top + TxtLocation.ActualHeight); Canvas.SetLeft(tempImageCanvas, tempTextCanvas.Width - margin.Left); Canvas.SetTop(tempImageCanvas, margin.Top + TxtLocation.ActualHeight); Canvas.SetLeft(etcWeaterCanvas, margin.Left); Canvas.SetTop(etcWeaterCanvas, margin.Top + TxtLocation.ActualHeight + tempImageCanvas.Height); weatherCanvas.Children.Add(TxtLocation); weatherCanvas.Children.Add(tempTextCanvas); weatherCanvas.Children.Add(tempImageCanvas); weatherCanvas.Children.Add(etcWeaterCanvas); //기온 string[] temp = data.LiveWeather.Temp.Value.Value.Split('.'); TextBlock TxtLiveWeatherTemp = new TextBlock() { Text = temp[0], FontSize = data.FontSizeExtraExtraLarge * 1.2, Foreground = data.ForegroundBrush, FontWeight = data.FontWeight }; TextBlock TxtLiveWeatherTempFloat = new TextBlock() { Text = (temp.Length > 1) ? string.Format(".{0}", temp[1]) : ".0", FontSize = data.FontSizeMedium * 1.25, Foreground = data.ForegroundBrush, FontWeight = data.FontWeight }; TextBlock TxtLiveWeatherTempUnits = new TextBlock() { Text = (WeatherUnitsConverter.ConvertOnlyUnit(data.LiveWeather.Temp.Value) as ValueUnits).Units, FontSize = data.FontSizeMedium * 1.15, Foreground = data.ForegroundBrush, FontWeight = data.FontWeight }; double tempCanvasTopMargin = (ImgLiveWeather.Height - TxtLiveWeatherTemp.ActualHeight) / 2; double tempCanvasLeftMargin = (tempTextCanvas.Width - TxtLiveWeatherTemp.ActualWidth) / 2 - TxtLiveWeatherTempUnits.ActualWidth; Canvas.SetLeft(TxtLiveWeatherTemp, tempCanvasLeftMargin); Canvas.SetTop(TxtLiveWeatherTemp, tempCanvasTopMargin); Canvas.SetLeft(TxtLiveWeatherTempUnits, tempCanvasLeftMargin + TxtLiveWeatherTemp.ActualWidth); Canvas.SetTop(TxtLiveWeatherTempUnits, tempCanvasTopMargin + (TxtLiveWeatherTempUnits.ActualHeight / 2) - 5); Canvas.SetLeft(TxtLiveWeatherTempFloat, tempCanvasLeftMargin + TxtLiveWeatherTemp.ActualWidth + TxtLiveWeatherTempFloat.ActualWidth / 9); Canvas.SetTop(TxtLiveWeatherTempFloat, tempCanvasTopMargin + (TxtLiveWeatherTempUnits.ActualHeight / 2) + TxtLiveWeatherTempUnits.ActualHeight + 5); tempTextCanvas.Children.Add(TxtLiveWeatherTemp); tempTextCanvas.Children.Add(TxtLiveWeatherTempFloat); tempTextCanvas.Children.Add(TxtLiveWeatherTempUnits); Canvas.SetLeft(ImgLiveWeather, 0); Canvas.SetTop(ImgLiveWeather, 0); tempImageCanvas.Children.Add(ImgLiveWeather); Image imageWater = new Image() { Width = 20 * data.FontRatio, Height = 20 * data.FontRatio, Source = BitmapFactory.New(0, 0).FromContent("Images/lockscreen/water.png") }; Image imageWind = new Image() { Width = 32 * data.FontRatio, Height = 32 * data.FontRatio, Source = BitmapFactory.New(0, 0).FromContent("Images/lockscreen/wind.png") }; //습도 TextBlock TxtLiveWeatherHumidity = new TextBlock() { Text = data.LiveWeather.Humidity.Value.Value + data.LiveWeather.Humidity.Value.Units, FontSize = data.FontSizeMedium * 1.1, Foreground = data.ForegroundBrush, FontWeight = data.FontWeight }; //바람 TextBlock TxtLiveWeatherWind = new TextBlock() { Text = data.LiveWeather.WindSpeed.Value + data.LiveWeather.WindSpeed.Units, FontSize = data.FontSizeMedium * 1.1, Foreground = data.ForegroundBrush, FontWeight = data.FontWeight }; Canvas.SetLeft(imageWater, tempCanvasLeftMargin); Canvas.SetTop(imageWater, (imageWind.Height - imageWater.Height) / 2); Canvas.SetLeft(TxtLiveWeatherHumidity, tempCanvasLeftMargin + imageWater.Width + margin.Left / 2); Canvas.SetTop(TxtLiveWeatherHumidity, (imageWind.Height - TxtLiveWeatherHumidity.ActualHeight) / 2); Canvas.SetLeft(imageWind, tempCanvasLeftMargin + imageWater.Width + TxtLiveWeatherHumidity.ActualWidth + 20 + margin.Left); Canvas.SetLeft(TxtLiveWeatherWind, tempCanvasLeftMargin + imageWater.Width + TxtLiveWeatherHumidity.ActualWidth + 20 + imageWind.Width + margin.Left * 3 / 2); Canvas.SetTop(TxtLiveWeatherWind, (imageWind.Height - TxtLiveWeatherWind.ActualHeight) / 2); etcWeaterCanvas.Children.Add(imageWater); etcWeaterCanvas.Children.Add(TxtLiveWeatherHumidity); etcWeaterCanvas.Children.Add(imageWind); etcWeaterCanvas.Children.Add(TxtLiveWeatherWind); //주간일보 if (data.Forecasts != null) { Canvas forecastCanvas = new Canvas(); DayNameConverter dayNameConverter = new DayNameConverter(); WeatherRangeConverter tempConverter = new WeatherRangeConverter(); for (int i = 0; i < 3; i++) { Forecast forecast = data.Forecasts.Items[i]; Canvas dayCanvas = new Canvas(); dayCanvas.Width = etcWeaterCanvas.Width / 3; TextBlock dayName = new TextBlock() { Text = dayNameConverter.Convert(forecast.AltTitle, null, null, System.Globalization.CultureInfo.CurrentCulture) as string, FontSize = data.FontSizeMedium * 0.85, Foreground = data.ForegroundBrush, FontWeight = data.FontWeight }; dayCanvas.Children.Add(dayName); Canvas.SetLeft(dayName, (dayCanvas.Width - dayName.ActualWidth) / 2); Canvas.SetTop(dayName, margin.Top * 2); WeatherIconType iconType = WeatherIconMap.Instance.WeatherIconType; string forecastPath = string.Format(WeatherBug.ICON_LOCAL_PATH.Substring(1), iconType.ToString().ToLower(), "80x67", WeatherImageIconConverter.GetIamgetName(forecast.ImageIcon)); WriteableBitmap forecastWeatherWb = BitmapFactory.New(0, 0).FromContent(forecastPath); Image forecastImage = new Image() { Source = forecastWeatherWb, Width = dayCanvas.Width * 0.7, Height = dayCanvas.Width * 0.7 * 0.84 //0.84는 아이콘 이미지의 원본 비율임 }; dayCanvas.Children.Add(forecastImage); Canvas.SetLeft(forecastImage, (dayCanvas.Width - forecastImage.Width) / 2); Canvas.SetTop(forecastImage, dayName.ActualHeight + margin.Top + margin.Top / 2); TextBlock tempRange = new TextBlock() { Text = tempConverter.Convert(forecast.LowHigh, null, null, System.Globalization.CultureInfo.CurrentCulture) as string, FontSize = data.FontSizeMedium * 0.8, Foreground = data.ForegroundBrush, FontWeight = data.FontWeight }; dayCanvas.Children.Add(tempRange); Canvas.SetLeft(tempRange, (dayCanvas.Width - tempRange.ActualWidth) / 2); Canvas.SetTop(tempRange, dayName.ActualHeight + forecastImage.Height + margin.Top + margin.Top / 2); forecastCanvas.Children.Add(dayCanvas); Canvas.SetLeft(dayCanvas, i * dayCanvas.Width); } weatherCanvas.Children.Add(forecastCanvas); Canvas.SetTop(forecastCanvas, TxtLocation.ActualHeight + tempTextCanvas.Height + etcWeaterCanvas.Height); Canvas.SetLeft(forecastCanvas, 0); } } else { TextBlock TxtNoWeather = new TextBlock() { Width = weatherCanvas.Width * 0.85, FontSize = data.FontSizeMedium, Foreground = data.ForegroundBrush, TextWrapping = TextWrapping.Wrap, Text = AppResources.LockscreenNoWeatherData }; weatherCanvas.Children.Add(TxtNoWeather); Canvas.SetTop(TxtNoWeather, (weatherCanvas.Height - TxtNoWeather.ActualHeight) / 2); Canvas.SetLeft(TxtNoWeather, (weatherCanvas.Width - TxtNoWeather.ActualWidth) / 2); } return(weatherCanvas); }
private void RenderLiveWeather(LiveWeather result) { WeatherCity city = SettingHelper.Get(Constants.WEATHER_MAIN_CITY) as WeatherCity; TxtWeatherNoCity.Visibility = System.Windows.Visibility.Collapsed; GridLiveWeather.Visibility = System.Windows.Visibility.Visible; SystemTray.SetIsVisible(this, false); if (SystemTray.ProgressIndicator != null) { SystemTray.ProgressIndicator.IsVisible = false; } BitmapImage imageSource = new BitmapImage(); imageSource.UriSource = new WeatherImageIconConverter().Convert(result.CurrentConditionIcon, null, "205x172", null) as Uri; //업데이트 시간 System.DateTime dateTime = GetDateTime(result.ObDate); //지역 string[] langs = CultureInfo.CurrentCulture.Name.Split('-'); if (langs[0] == "ko" || langs[0] == "ja" || langs[1] == "zh") { PIWeather.Header = (string.IsNullOrEmpty(result.Station.State) ? string.Empty : result.Station.State + " ") + result.Station.City; } else { PIWeather.Header = result.Station.City + (string.IsNullOrEmpty(result.Station.State) ? string.Empty : " ," + result.Station.State); } //업데이트 시간 TxtLiveWeatherDtUpdated.Text = dateTime.ToString(CultureInfo.CurrentUICulture.DateTimeFormat.LongDatePattern); TxtLiveWeatherTmUpdated.Text = string.Format(AppResources.WeatherUpdatedTime, dateTime.ToString(CultureInfo.CurrentUICulture.DateTimeFormat.ShortTimePattern)); //날씨 이미지 ImgLiveWeatherIcon.Source = imageSource; //날씨 텍스트 TxtLiveWeatherCondition.Text = result.CurrentCondition; //기온 string[] temp = result.Temp.Value.Value.Split('.'); TxtLiveWeatherTemp.Text = temp[0]; //TxtLiveWeatherTemp.Text = "-50"; double orgFontSize = TxtLiveWeatherTemp.FontSize; //온도 표시 문자열의 길이에 따라 폰트 사이즈 변경 while (TxtLiveWeatherTemp.Width < TxtLiveWeatherTemp.ActualWidth) { TxtLiveWeatherTemp.FontSize--; } if (temp.Length > 1) { TxtLiveWeatherTempFloat.Text = "." + temp[1]; } TxtLiveWeatherTempUnits.Text = (WeatherUnitsConverter.ConvertOnlyUnit(result.Temp.Value) as ValueUnits).Units; //체감온도 string feelsLikeLabel = string.IsNullOrEmpty(result.FeelsLikeLabel) ? AppResources.WeatherLiveFeelsLike : result.FeelsLikeLabel + " {0}"; TxtLiveWeatherFeelTemp.Text = string.Format(feelsLikeLabel, WeatherUnitsConverter.Convert(result.FeelsLike)); //습도 TxtLiveWeatherHumidity.Text = string.Format(AppResources.WeatherLiveHumidity, result.Humidity.Value.Value, result.Humidity.Value.Units); //바람 TxtLiveWeatherWind.Text = string.Format(AppResources.WeatherLiveWind, result.WindDirection, result.WindSpeed.Value, result.WindSpeed.Units); //최고/최저 기온 TxtLiveWeatherTempRange.Text = WeatherRangeConverter.RangeText( new ValueUnits[2] { result.Temp.Low, result.Temp.High }, true); double dTemp = 0; double dFeel = 0; try { dTemp = Double.Parse(result.Temp.Value.Value); dFeel = Double.Parse(result.FeelsLike.Value); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("온도 파싱 에러" + e.Message); } if (string.IsNullOrEmpty(result.FeelsLike.Value) || string.Format("{0:F1}", dTemp) == string.Format("{0:F1}", dFeel)) { BrdLiveWeatherFeelTemp.Visibility = System.Windows.Visibility.Collapsed; } //현재 기온의 텍스트 크기가 변경이 되었다면... 단위와 소수점 크기도 변경 double rt = TxtLiveWeatherTemp.FontSize / orgFontSize; Thickness margin = GrdTempSub.Margin; margin.Top *= rt; GrdTempSub.Margin = margin; GrdTempSub.Height *= rt; TxtLiveWeatherTempUnits.FontSize *= rt; TxtLiveWeatherTempFloat.FontSize *= rt; }