示例#1
0
        public static Canvas GetWeatherBackCanvas(LivetileData data)
        {
            SolidColorBrush foregroundBrush = new SolidColorBrush(Colors.White);
            Canvas          weatherCanvas   = new Canvas();

            weatherCanvas.Width  = data.AreaSize.Width;
            weatherCanvas.Height = data.AreaSize.Height;

            if (data.Forecasts != null)
            {
                Canvas                forecastCanvas   = new Canvas();
                DayNameConverter      dayNameConverter = new DayNameConverter();
                WeatherRangeConverter tempConverter    = new WeatherRangeConverter();
                short row = 0;
                short col = 0;

                if (data.Forecasts.Items.Count == 7)
                {
                    data.Forecasts.Items.RemoveAt(0);
                }

                for (int i = 0; i < data.Forecasts.Items.Count; i++)
                {
                    Forecast forecast = data.Forecasts.Items[i];

                    Canvas dayCanvas = new Canvas();
                    dayCanvas.Width  = (weatherCanvas.Width - 40) / 3;
                    dayCanvas.Height = (weatherCanvas.Height - 30) / 2;

                    TextBlock dayName = new TextBlock()
                    {
                        Text       = dayNameConverter.Convert(forecast.AltTitle, null, null, System.Globalization.CultureInfo.CurrentCulture) as string,
                        FontSize   = data.FontSizeMedium * 1.2,
                        Foreground = foregroundBrush,
                        FontWeight = data.FontWeight
                    };
                    dayCanvas.Children.Add(dayName);
                    Canvas.SetLeft(dayName, (dayCanvas.Width - dayName.ActualWidth) / 2);
                    Canvas.SetTop(dayName, 0);

                    WeatherIconType type              = WeatherIconMap.Instance.WeatherIconType;
                    string          forecastPath      = string.Format(WeatherBug.ICON_LOCAL_PATH.Substring(1), type.ToString().ToLower(), "80x67", WeatherImageIconConverter.GetIamgetName(forecast.ImageIcon));
                    WriteableBitmap forecastWeatherWb = BitmapFactory.New(0, 0).FromContent(forecastPath);

                    Image forecastImage = new Image()
                    {
                        Source = forecastWeatherWb,
                        Width  = forecastWeatherWb.PixelWidth,
                        Height = forecastWeatherWb.PixelHeight //0.84는 아이콘 이미지의 원본 비율임
                    };
                    dayCanvas.Children.Add(forecastImage);
                    Canvas.SetLeft(forecastImage, (dayCanvas.Width - forecastImage.Width) / 2);
                    Canvas.SetTop(forecastImage, dayName.ActualHeight + 5);

                    TextBlock tempRange = new TextBlock()
                    {
                        Text       = tempConverter.Convert(forecast.LowHigh, null, null, System.Globalization.CultureInfo.CurrentCulture) as string,
                        FontSize   = data.FontSizeMedium,
                        Foreground = foregroundBrush,
                        FontWeight = data.FontWeight
                    };
                    dayCanvas.Children.Add(tempRange);
                    Canvas.SetLeft(tempRange, (dayCanvas.Width - tempRange.ActualWidth) / 2);
                    Canvas.SetTop(tempRange, dayName.ActualHeight + 5 + forecastImage.Height + 5);

                    forecastCanvas.Children.Add(dayCanvas);

                    if (i == 3)
                    {
                        row++;
                        col = 0;
                    }

                    Canvas.SetLeft(dayCanvas, col++ *dayCanvas.Width + 20);
                    Canvas.SetTop(dayCanvas, row * dayCanvas.Height + 20);
                }

                weatherCanvas.Children.Add(forecastCanvas);
            }
            else
            {
                TextBlock TxtNoWeather = new TextBlock()
                {
                    Width        = weatherCanvas.Width * 0.85,
                    FontSize     = data.FontSizeMedium,
                    Foreground   = foregroundBrush,
                    FontWeight   = data.FontWeight,
                    TextWrapping = TextWrapping.Wrap,
                    Text         = AppResources.LockscreenNoWeatherBackData,
                };

                weatherCanvas.Children.Add(TxtNoWeather);
                Canvas.SetTop(TxtNoWeather, (weatherCanvas.Height - TxtNoWeather.ActualHeight) / 2);
                Canvas.SetLeft(TxtNoWeather, (weatherCanvas.Width - TxtNoWeather.ActualWidth) / 2);
            }

            return(weatherCanvas);
        }
示例#2
0
        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);
        }
示例#3
0
        public static Canvas GetWeatherCanvas(LivetileData data)
        {
            SolidColorBrush foregroundBrush = new SolidColorBrush(Colors.White);
            Canvas          weatherCanvas   = new Canvas();

            weatherCanvas.Width  = data.AreaSize.Width;
            weatherCanvas.Height = data.AreaSize.Height;

            if (data.LiveWeather != null)
            {
                double fontRatio = (double)(SettingHelper.Get(Constants.LIVETILE_WEATHER_FONT_SIZE) as PickerItem).Key;
                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 Location = new TextBlock()
                {
                    Text       = tmp,
                    FontSize   = data.FontSizeLarge * fontRatio,
                    Foreground = foregroundBrush,
                    FontWeight = data.FontWeight
                };

                if (Location.ActualWidth > weatherCanvas.Width)
                {
                    Location.Text = data.LiveWeather.Station.City;
                }

                //기온
                string[]        temp = data.LiveWeather.Temp.Value.Value.Split('.');
                WeatherIconType type = WeatherIconMap.Instance.WeatherIconType;
                string          path = string.Format(WeatherBug.ICON_LOCAL_PATH.Substring(1), type.ToString().ToLower(), "205x172", WeatherImageIconConverter.GetIamgetName(data.LiveWeather.CurrentConditionIcon));
                //string path = string.Format("Images/weather/205x172/cond170.png");
                WriteableBitmap weatherWb = BitmapFactory.New(0, 0).FromContent(path);

                //날씨 이미지
                Image MainImage = new Image()
                {
                    Source = weatherWb,
                    Width  = weatherCanvas.Width / 2,
                    Height = (double)weatherWb.PixelHeight / weatherWb.PixelWidth * weatherCanvas.Width / 2
                };

                TextBlock MainTemp = new TextBlock()
                {
                    Text       = temp[0],
                    FontSize   = data.FontSizeExtraExtraLarge * 1.4,
                    FontWeight = FontWeights.SemiBold,
                    Foreground = foregroundBrush
                };

                TextBlock MainTempDesc = new TextBlock()
                {
                    FontSize   = data.FontSizeLarge * fontRatio,
                    FontWeight = data.FontWeight,
                    Text       = data.LiveWeather.CurrentCondition,
                    //Text = "40% Chance Rain Shower",
                    Foreground = foregroundBrush,
                    Margin     = new Thickness(5, 0, 5, 0)
                };

                double tempTopMargin = 0;
                if (MainTempDesc.ActualWidth > weatherCanvas.Width)
                {
                    tempTopMargin             = MainTempDesc.ActualHeight / 2;
                    MainTempDesc.TextWrapping = TextWrapping.Wrap;
                    MainTempDesc.Width        = weatherCanvas.Width;
                    MainTempDesc.Height       = weatherCanvas.Height;
                }

                double totalWidth = MainTemp.ActualWidth + 10 + MainImage.Width;

                Canvas.SetLeft(Location, 20);
                Canvas.SetTop(Location, 20);

                Canvas.SetLeft(MainImage, (weatherCanvas.Width - totalWidth) / 2);
                Canvas.SetTop(MainImage, (weatherCanvas.Height - MainImage.Height) / 2 - tempTopMargin);

                Canvas.SetLeft(MainTemp, (weatherCanvas.Width - totalWidth) / 2 + MainImage.Width);
                Canvas.SetTop(MainTemp, (weatherCanvas.Height - MainImage.Height) / 2 + (MainImage.Height - MainTemp.ActualHeight) / 2 + 5 /*- tempTopMargin*/);

                Canvas.SetLeft(MainTempDesc, (weatherCanvas.Width - MainTempDesc.ActualWidth) / 2);
                Canvas.SetTop(MainTempDesc, (weatherCanvas.Height - MainImage.Height) / 2 + MainImage.Height + 20 - tempTopMargin);

                weatherCanvas.Children.Add(Location);
                weatherCanvas.Children.Add(MainImage);
                weatherCanvas.Children.Add(MainTemp);
                weatherCanvas.Children.Add(MainTempDesc);
            }
            else
            {
                TextBlock TxtNoWeather = new TextBlock()
                {
                    Width        = weatherCanvas.Width * 0.85,
                    FontSize     = data.FontSizeMedium,
                    Foreground   = foregroundBrush,
                    FontWeight   = data.FontWeight,
                    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);
        }