Example #1
0
        private void CreateBatteryLivetileImage()
        {
            LivetileTemplateItem batteryItem = LivetileSelector.ItemsSource[2] as LivetileTemplateItem;

            batteryItem.Background = new SolidColorBrush((SettingHelper.Get(Constants.LIVETILE_BATTERY_BACKGROUND_COLOR) as ColorItem).Color);
            batteryItem.BackTitle  = AppResources.ApplicationTitle;

            LivetileData data = new LivetileData();

            //배터리 이미지 로드
            LivetileHelper.CreateLivetileImage(data, LiveItems.Battery);
            LoadLivetileImage(batteryItem);
            //배터리 백타일 내용
            batteryItem.LiveBackTileContent = LivetileHelper.GetBatteryBackTextContent();
            batteryItem.Visibility          = System.Windows.Visibility.Visible;
            if (ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("battery")) != null)
            {
                batteryItem.PinIconOpacity = 1;
                GetAppBarButton(AppResources.PinBatteryLivetile).IsEnabled = false;
                UpdateLiveTile(batteryItem, 0);
            }
            else
            {
                batteryItem.PinIconOpacity = 0.3;
                GetAppBarButton(AppResources.PinBatteryLivetile).IsEnabled = true;
            }
        }
Example #2
0
        private void CreateWeatherLivetileImage()
        {
            LivetileTemplateItem weatherItem = LivetileSelector.ItemsSource[0] as LivetileTemplateItem;
            //날씨 데이타
            LivetileData data = new LivetileData()
            {
                LiveWeather = SettingHelper.Get(Constants.WEATHER_LIVE_RESULT) as LiveWeather,
                Forecasts   = SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT) as Forecasts
            };

            //날씨 이미지 로드
            LivetileHelper.CreateLivetileImage(data, LiveItems.Weather);
            LoadLivetileImage(weatherItem);
            weatherItem.Visibility = System.Windows.Visibility.Visible;
            if (ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("weather")) != null)
            {
                weatherItem.PinIconOpacity = 1;
                GetAppBarButton(AppResources.PinWeatherLivetile).IsEnabled = false;
                UpdateLiveTile(weatherItem, 0);
            }
            else
            {
                weatherItem.PinIconOpacity = 0.3;
                GetAppBarButton(AppResources.PinWeatherLivetile).IsEnabled = true;
            }
        }
Example #3
0
        private void SetLivetileImage(ScheduledTask task, LivetileData data)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine("타일 전 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);

                for (int i = 0; i < ShellTile.ActiveTiles.Count(); i++)
                {
                    ShellTile tile = ShellTile.ActiveTiles.ElementAt(i);

                    if (tile.NavigationUri.ToString().Contains("calendar"))
                    {
                        List <Appointment> appList = data.DayList.Find(x => x.DateTime.ToLongDateString() == DateTime.Today.ToLongDateString()).AppointmentList;
                        int count = appList == null ? 0 : appList.Count;

                        LivetileHelper.CreateLivetileImage(data, LiveItems.Calendar);
                        tile.Update(LivetileHelper.GetCalendarLivetileData(count));
                    }
                    else if (tile.NavigationUri.ToString().Contains("weather"))
                    {
                        LivetileHelper.CreateLivetileImage(data, LiveItems.Weather);
                        tile.Update(LivetileHelper.GetWeatherLivetileData());
                    }
                    else if (tile.NavigationUri.ToString().Contains("battery"))
                    {
                        LivetileHelper.CreateLivetileImage(data, LiveItems.Battery);
                        tile.Update(LivetileHelper.GetBatteryLivetileData());
                    }
                }

                System.Diagnostics.Debug.WriteLine("타일 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                //배터리 잠금화면 업데이트
                UpdateBatteryStatus();
                System.Diagnostics.Debug.WriteLine("배터리 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
#if DEBUG_AGENT
            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(30));
            System.Diagnostics.Debug.WriteLine(Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
#else
            IsolatedStorageSettings.ApplicationSettings[Constants.LAST_RUN_LIVETILE] = DateTime.Now;
            IsolatedStorageSettings.ApplicationSettings.Save();
#endif
        }
Example #4
0
        /// <summary>
        /// 예약된 작업을 실행하는 에이전트입니다.
        /// </summary>
        /// <param name="task">
        /// 호출한 작업입니다.
        /// </param>
        /// <remarks>
        /// 이 메서드는 정기적 작업 또는 리소스를 많이 사용하는 작업이 호출될 때 호출됩니다.
        /// </remarks>
        protected override void OnInvoke(ScheduledTask task)
        {
            bool isLiveTileTurn = true;

            scheduleSettings = MutexedIsoStorageFile.Read <ScheduleSettings>("ScheduleSettings", Constants.MUTEX_DATA);

            //스케쥴러는 30분마다 들어온다.
            //이번이 누구 차례인가를 생성해야 한다.
            //라이브타일과 락스크린은 각각의 인터벌이 있고, 그 인터벌은 어느 순간 중복될 수 있다.
            //중복되면 라이브타일에 우선권을 부여하여 실행하며, 락스크린은 그 이후 스케줄로 밀린다.
            //판별에 사용될 변수는 1.인터벌, 2.실행대상, 3.실행대상의 최종 실행시간
#if !DEBUG_AGENT
            {
                DateTime LastRunForLivetile, LastRunForLockscreen;
                IsolatedStorageSettings.ApplicationSettings.TryGetValue <DateTime>(Constants.LAST_RUN_LIVETILE, out LastRunForLivetile);
                IsolatedStorageSettings.ApplicationSettings.TryGetValue <DateTime>(Constants.LAST_RUN_LOCKSCREEN, out LastRunForLockscreen);
                bool useLockscreenRotator;
                IsolatedStorageSettings.ApplicationSettings.TryGetValue <bool>(Constants.LOCKSCREEN_USE_ROTATOR, out useLockscreenRotator);

                double lockscreenTerm = DateTime.Now.Subtract(LastRunForLockscreen).TotalMinutes - scheduleSettings.LockscreenUpdateInterval;
                //한번도 락스크린 스케쥴러를 실행한적이 없고 락스크린이 스케쥴에서 사용되지 않는 경우는 -1로 설정하여 락스크린으로 분기되지 않도록 처리
                if (LastRunForLockscreen.Year == 1 && LastRunForLockscreen.Month == 1 && LastRunForLockscreen.Day == 1 && !useLockscreenRotator)
                {
                    lockscreenTerm = -1;
                }

                if (DateTime.Now.Subtract(LastRunForLivetile).TotalMinutes < scheduleSettings.LivetileUpdateInterval &&
                    lockscreenTerm < 0)
                {
                    System.Diagnostics.Debug.WriteLine("Too soon, stopping.");
                    NotifyComplete();
                    return;
                }
                else if (lockscreenTerm >= 0)
                {
                    isLiveTileTurn = false;
                }
            }
#else
            isLiveTileTurn = false;
#endif
            if (isLiveTileTurn)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    System.Diagnostics.Debug.WriteLine("1 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    LivetileData data = new LivetileData()
                    {
                        DayList = VsCalendar.GetCalendarOfMonth(DateTime.Now, DateTime.Now, true, true),
                    };

                    try
                    {
                        System.Diagnostics.Debug.WriteLine("타일 전 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);

                        bool hasWeather  = ShellTile.ActiveTiles.Any(x => x.NavigationUri.ToString().Contains("weather"));
                        bool hasCalendar = ShellTile.ActiveTiles.Any(x => x.NavigationUri.ToString().Contains("calendar"));

                        if (hasWeather)
                        {
                            //1. 날씨 타일이 핀되어 있다.
                            WeatherCity city   = SettingHelper.Get(Constants.WEATHER_MAIN_CITY) as WeatherCity;
                            DisplayUnit unit   = (DisplayUnit)SettingHelper.Get(Constants.WEATHER_UNIT_TYPE);
                            WeatherBug weather = new WeatherBug();
                            weather.LiveWeatherCompletedLoad += (s, r, f) =>
                            {
                                //조회된 데이터를 셋팅(없으면 저장된 날씨를 사용함)
                                SetWeatherResult(data, r, f);
                                //달력 적용 또는 직접 렌더링
                                DelegateUpdateProcess(task, data, hasCalendar);
                            };
                            weather.RequestFailed += (s, r) =>
                            {
                                //데이터를 얻는데 실패 한 경우 네트워크가 연결되지 않았다면, 이전 저장된 데이터를 사용
                                if (!DeviceNetworkInformation.IsNetworkAvailable)
                                {
                                    data.LiveWeather = (LiveWeather)SettingHelper.Get(Constants.WEATHER_LIVE_RESULT);
                                    data.Forecasts   = (Forecasts)SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT);
                                }

                                //달력 적용 또는 직접 렌더링
                                DelegateUpdateProcess(task, data, hasCalendar);
                            };

                            if (city != null)
                            {
                                weather.LiveWeather(city, unit);
                            }
                            else
                            {
                                //달력 적용 또는 직접 렌더링
                                DelegateUpdateProcess(task, data, hasCalendar);
                            }
                        }
                        else
                        {
                            //달력 적용 또는 직접 렌더링
                            DelegateUpdateProcess(task, data, hasCalendar);
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Message);
                    }
                });
            }
            else
            {
                if (!LockScreenManager.IsProvidedByCurrentApplication)
                {
                    System.Diagnostics.Debug.WriteLine("잠금화면 제공앱이 아니므로 변경할수 없음.");
                    NotifyComplete();
                    return;
                }

                if (!IsolatedStorageSettings.ApplicationSettings.Contains(Constants.LOCKSCREEN_USE_ROTATOR) ||
                    !(bool)IsolatedStorageSettings.ApplicationSettings[Constants.LOCKSCREEN_USE_ROTATOR])
                {
                    System.Diagnostics.Debug.WriteLine("로테이터 사용안함.");
                    NotifyComplete();
                    return;
                }

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    System.Diagnostics.Debug.WriteLine("1 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    LockscreenData data = new LockscreenData(true)
                    {
                        DayList = VsCalendar.GetCalendarOfMonth(DateTime.Now, DateTime.Now, true, true),
                    };

                    bool hasWeather  = false;
                    bool hasCalendar = false;

                    LockscreenItemInfo[] items = data.Items;

                    for (int i = 0; i < items.Length; i++)
                    {
                        switch (items[i].LockscreenItem)
                        {
                        case LiveItems.Weather:
                        case LiveItems.NoForecast:
                            hasWeather = true;
                            break;

                        case LiveItems.Calendar:
                            hasCalendar = true;
                            break;
                        }
                    }

                    if (hasWeather)
                    {
                        WeatherBug weather = new WeatherBug();
                        WeatherCity city   = SettingHelper.Get(Constants.WEATHER_MAIN_CITY) as WeatherCity;
                        DisplayUnit unit   = (DisplayUnit)SettingHelper.Get(Constants.WEATHER_UNIT_TYPE);

                        weather.LiveWeatherCompletedLoad += (s, r, f) =>
                        {
                            //조회된 데이터를 셋팅(없으면 저장된 날씨를 사용함)
                            SetWeatherResult(data, r, f);
                            //달력 적용 또는 직접 렌더링
                            DelegateUpdateProcess(task, data, hasCalendar);
                        };

                        weather.RequestFailed += (s, r) =>
                        {
                            if (!DeviceNetworkInformation.IsNetworkAvailable)
                            {
                                data.LiveWeather = (LiveWeather)SettingHelper.Get(Constants.WEATHER_LIVE_RESULT);
                                data.Forecasts   = (Forecasts)SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT);
                            }
                            //달력 적용 또는 직접 렌더링
                            DelegateUpdateProcess(task, data, hasCalendar);
                        };

                        if (city != null)
                        {
                            weather.LiveWeather(city, unit);
                        }
                        else
                        {
                            //달력 적용 또는 직접 렌더링
                            DelegateUpdateProcess(task, data, hasCalendar);
                        }
                    }
                    else
                    {
                        //달력 적용 또는 직접 렌더링
                        DelegateUpdateProcess(task, data, hasCalendar);
                    }
                });
            }
        }
Example #5
0
        public static Canvas GetCalendarCanvas(LivetileData data)
        {
            Canvas calendarCanvas = new Canvas();

            calendarCanvas.Width  = data.AreaSize.Width;
            calendarCanvas.Height = data.AreaSize.Height;

            int rowNum = -1, colNum = 0;;

            for (int i = 0; i < data.DayList.Count; i++)
            {
                if (i % 7 == 0)
                {
                    rowNum++;
                    colNum = 0;
                }
                ChameleonLib.Api.Calendar.Model.Day day = data.DayList[i];

                Canvas dayPanel = new Canvas()
                {
                    Width  = calendarCanvas.Width / 7 - 1,
                    Height = calendarCanvas.Height / 7 - 1,
                    //Background = day.BackgroundBrush,
                };
                dayPanel.Margin = new Thickness((colNum++) * dayPanel.Width + 1, rowNum * dayPanel.Height, 0, 0);

                TextBlock dayTxt = new TextBlock()
                {
                    Text       = day.DayName,
                    FontSize   = day.FontSize * (day.DateTime.Year == 1 ? 1.1 : 1.2),
                    Foreground = day.ForegroundBrush,
                    FontWeight = data.FontWeight
                };

                if (day.DateTime.ToLongDateString() == DateTime.Today.ToLongDateString())
                {
                    Ellipse ellipse = new Ellipse()
                    {
                        Width  = dayTxt.ActualHeight * 1.08,
                        Height = dayTxt.ActualHeight * 1.08,
                        Fill   = day.BackgroundBrush
                    };

                    dayPanel.Children.Add(ellipse);
                    Canvas.SetLeft(ellipse, (dayPanel.Width - ellipse.Width) / 2);
                    Canvas.SetTop(ellipse, (dayPanel.Height - ellipse.Width) / 2 - 0.5);
                }

                if (data.DayList[i].AppointmentList != null && data.DayList[i].AppointmentList.Count > 0)
                {
                    TextBlock appCnt = new TextBlock()
                    {
                        Text       = data.DayList[i].AppointmentList.Count.ToString(),
                        FontSize   = 13,
                        Foreground = day.DateTime.ToLongDateString() == DateTime.Now.ToLongDateString() ? day.BackgroundBrush : day.ForegroundBrush,
                        FontWeight = FontWeights.ExtraBold
                    };
                    dayPanel.Children.Add(appCnt);
                    Canvas.SetLeft(appCnt, (dayPanel.Width - appCnt.ActualWidth));
                    Canvas.SetTop(appCnt, -appCnt.ActualHeight / 3);
                }

                dayPanel.Children.Add(dayTxt);
                Canvas.SetLeft(dayTxt, (dayPanel.Width - dayTxt.ActualWidth) / 2);
                Canvas.SetTop(dayTxt, (dayPanel.Height - dayTxt.ActualHeight) / 2);
                calendarCanvas.Children.Add(dayPanel);
            }
            return(calendarCanvas);
        }
Example #6
0
        public static void CreateLivetileImage(LivetileData data, LiveItems liveItem)
        {
            Canvas          panel = null;
            WriteableBitmap wb    = null;

            switch (liveItem)
            {
            case LiveItems.Calendar:
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    panel            = GetCalendarCanvas(data);
                    panel.Background = data.GetBackgroundBrush(LiveItems.Calendar);

                    System.Diagnostics.Debug.WriteLine("달력 전 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    using (IsolatedStorageFileStream targetStream = isoStore.OpenFile("Shared/ShellContent/livetile.calendar.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        wb = new WriteableBitmap(panel, null);
                        //wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        pngEncoder.Encode(wb.ToImage(), targetStream);
                    }

                    System.Diagnostics.Debug.WriteLine("달력 저장 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    wb = wb.Resize(159, 159, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
                    System.Diagnostics.Debug.WriteLine("달력 줄임 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    using (IsolatedStorageFileStream targetStream = isoStore.OpenFile("Shared/ShellContent/livetile.calendar.small.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        //wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        pngEncoder.Encode(wb.ToImage(), targetStream);
                    }
                    System.Diagnostics.Debug.WriteLine("작은 달력 저장 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);

                    using (IsolatedStorageFileStream targetStream = isoStore.OpenFile("Shared/ShellContent/livetile.calendar.back.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        panel.Children.Clear();
                        panel.Width  = 1;
                        panel.Height = 1;
                        wb           = new WriteableBitmap(panel, null);
                        //System.Diagnostics.Debug.WriteLine("###########달력 이미지 저장전 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                        //wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        pngEncoder.Encode(wb.ToImage(), targetStream);
                        //System.Diagnostics.Debug.WriteLine("###########달력 이미지 저장후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    }
                    System.Diagnostics.Debug.WriteLine("타일 뒷면 저장 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                }
                break;

            case LiveItems.Weather:
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    SolidColorBrush backBrush = data.GetBackgroundBrush(LiveItems.Weather);
                    panel            = GetWeatherCanvas(data);
                    panel.Background = backBrush;

                    System.Diagnostics.Debug.WriteLine("날씨 전 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    using (IsolatedStorageFileStream targetStream = isoStore.OpenFile("Shared/ShellContent/livetile.weather.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        wb = new WriteableBitmap(panel, null);
                        //wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        pngEncoder.Encode(wb.ToImage(), targetStream);
                    }
                    System.Diagnostics.Debug.WriteLine("날씨 저장 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    wb = wb.Resize(159, 159, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
                    System.Diagnostics.Debug.WriteLine("날씨 줄임 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    using (IsolatedStorageFileStream targetStream = isoStore.OpenFile("Shared/ShellContent/livetile.weather.small.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        //wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        pngEncoder.Encode(wb.ToImage(), targetStream);
                    }
                    System.Diagnostics.Debug.WriteLine("작은 날씨 저장 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);

                    //날씨 백타일 (주간 일보)
                    panel            = GetWeatherBackCanvas(data);
                    panel.Background = backBrush;

                    System.Diagnostics.Debug.WriteLine("주간 날씨 전 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    using (IsolatedStorageFileStream targetStream = isoStore.OpenFile("Shared/ShellContent/livetile.weather.back.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        wb = new WriteableBitmap(panel, null);
                        //wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        pngEncoder.Encode(wb.ToImage(), targetStream);
                    }
                    System.Diagnostics.Debug.WriteLine("주간 날씨 저장 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                }
                break;

            case LiveItems.Battery:
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    panel            = GetBatteryCanvas(data);
                    panel.Background = data.GetBackgroundBrush(LiveItems.Battery);

                    System.Diagnostics.Debug.WriteLine("배터리 전 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    using (IsolatedStorageFileStream targetStream = isoStore.OpenFile("Shared/ShellContent/livetile.battery.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        wb = new WriteableBitmap(panel, null);
                        //wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        pngEncoder.Encode(wb.ToImage(), targetStream);
                    }
                    System.Diagnostics.Debug.WriteLine("배터리 저장 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    wb = wb.Resize(159, 159, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
                    System.Diagnostics.Debug.WriteLine("배터리 줄임 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                    using (IsolatedStorageFileStream targetStream = isoStore.OpenFile("Shared/ShellContent/livetile.battery.small.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        //wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        pngEncoder.Encode(wb.ToImage(), targetStream);
                    }
                    System.Diagnostics.Debug.WriteLine("작은 배터리 저장 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);


                    using (IsolatedStorageFileStream targetStream = isoStore.OpenFile("Shared/ShellContent/livetile.battery.back.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        panel.Children.Clear();
                        panel.Width  = 1;
                        panel.Height = 1;
                        wb           = new WriteableBitmap(panel, null);
                        //wb.SaveJpeg(targetStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        pngEncoder.Encode(wb.ToImage(), targetStream);
                    }
                    System.Diagnostics.Debug.WriteLine("배터리 뒷면 저장 후 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage);
                }
                break;
            }

            wb = null;
            GC.Collect();
        }
Example #7
0
        public static Canvas GetBatteryCanvas(LivetileData data)
        {
            Canvas batteryCanvas = new Canvas();

            batteryCanvas.Width  = data.AreaSize.Width;
            batteryCanvas.Height = data.AreaSize.Height;

            WriteableBitmap batteryWb = BitmapFactory.New(0, 0).FromContent("Images/livetile/battery.png");
            WriteableBitmap flashWb   = BitmapFactory.New(0, 0).FromContent("Images/livetile/flash.png");

            Image batteryImage = new Image()
            {
                Source = batteryWb
            };

            Image flashImage = new Image()
            {
                Source = flashWb
            };

            TextBlock batteryPercent = new TextBlock()
            {
                FontSize   = data.FontSizeExtraExtraLarge * 1.5,
                Foreground = new SolidColorBrush(Colors.White),
                FontWeight = FontWeights.SemiBold,
                Text       = BatteryHelper.BateryLevel.ToString()
            };

            if (BatteryHelper.BateryLevel == 100)
            {
                int batteryFullIndicatoion = (Int32)(SettingHelper.Get(Constants.LIVETILE_BATTERY_FULL_INDICATION) as PickerItem).Key;
                if (batteryFullIndicatoion == 100)
                {
                    batteryPercent.Text = AppResources.BatteryFull;
                }
                else
                {
                    batteryPercent.Text = "99";
                }
            }

            System.Windows.Shapes.Rectangle batterySolid = new System.Windows.Shapes.Rectangle()
            {
                Fill   = batteryPercent.Foreground,
                Width  = batteryWb.PixelWidth * 0.49,
                Height = batteryWb.PixelHeight * 0.6 * BatteryHelper.BateryLevel / 100
            };

            Canvas.SetLeft(flashImage, batteryCanvas.Width - flashWb.PixelWidth - 20);
            Canvas.SetTop(flashImage, 30);

            double totalWidth = batteryWb.PixelWidth + batteryPercent.ActualWidth;

            Canvas.SetLeft(batteryImage, (batteryCanvas.Width - totalWidth) / 2 - 10);
            Canvas.SetTop(batteryImage, (batteryCanvas.Height - batteryWb.PixelHeight) / 2);

            Canvas.SetLeft(batterySolid, (batteryCanvas.Width - totalWidth) / 2 + batteryWb.PixelWidth * 0.1);
            Canvas.SetTop(batterySolid, (batteryCanvas.Height - batteryWb.PixelHeight) / 2 + batteryWb.PixelHeight * 0.265 + (batteryWb.PixelHeight * 0.6) - batterySolid.Height);

            Canvas.SetLeft(batteryPercent, (batteryCanvas.Width - totalWidth) / 2 + batteryWb.PixelWidth + 10);
            Canvas.SetTop(batteryPercent, (batteryCanvas.Height - batteryPercent.ActualHeight) / 2 + 10);

            batteryCanvas.Children.Add(flashImage);
            batteryCanvas.Children.Add(batteryImage);
            batteryCanvas.Children.Add(batterySolid);
            batteryCanvas.Children.Add(batteryPercent);

            return(batteryCanvas);
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
0
        private void CreateCalendarLivetileImage()
        {
            LivetileTemplateItem calendarItem = LivetileSelector.ItemsSource[1] as LivetileTemplateItem;

            calendarItem.Background = new SolidColorBrush((SettingHelper.Get(Constants.LIVETILE_CALENDAR_BACKGROUND_COLOR) as ColorItem).Color);
            calendarItem.BackTitle  = AppResources.ApplicationTitle;

            //달력이미지를 무조건 새로 생성해서 화면 업데이트
            LivetileData data = new LivetileData()
            {
                DayList = VsCalendar.GetCalendarOfMonth(DateTime.Now, DateTime.Now, true, true)
            };

            if ((bool)SettingHelper.Get(Constants.CALENDAR_SHOW_APPOINTMENT))
            {
                Appointments appointments = new Appointments();
                appointments.SearchCompleted += (s, se) =>
                {
                    //달력 데이타
                    VsCalendar.MergeCalendar(data.DayList, se.Results);

                    LivetileHelper.CreateLivetileImage(data, LiveItems.Calendar);
                    LoadLivetileImage(calendarItem);
                    //일정이 몇개 있는지를 백타일에 표시
                    List <Appointment> appList = data.DayList.Find(x => x.DateTime.ToLongDateString() == DateTime.Today.ToLongDateString()).AppointmentList;
                    int count = appList == null ? 0 : appList.Count;
                    calendarItem.LiveBackTileContent = LivetileHelper.GetCalendarBackTextContent(count);
                    calendarItem.Visibility          = System.Windows.Visibility.Visible;
                    if (ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("calendar")) != null)
                    {
                        calendarItem.PinIconOpacity = 1;
                        GetAppBarButton(AppResources.PinCalendarLivetile).IsEnabled = false;
                        UpdateLiveTile(calendarItem, count);
                    }
                    else
                    {
                        calendarItem.PinIconOpacity = 0.3;
                        GetAppBarButton(AppResources.PinCalendarLivetile).IsEnabled = true;
                    }
                };
                appointments.SearchAsync(data.DayList[7].DateTime, data.DayList[data.DayList.Count - 1].DateTime.AddDays(1), null);
            }
            else
            {
                //전체 타일 이미지 생성
                LivetileHelper.CreateLivetileImage(data, LiveItems.Calendar);
                //달력 이미지 로드
                LoadLivetileImage(calendarItem);
                //백타일에 일정 표시하지 않음
                calendarItem.LiveBackTileContent = LivetileHelper.GetCalendarBackTextContent(-1);
                calendarItem.Visibility          = System.Windows.Visibility.Visible;
                if (ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("calendar")) != null)
                {
                    calendarItem.PinIconOpacity = 1;
                    GetAppBarButton(AppResources.PinCalendarLivetile).IsEnabled = false;
                    UpdateLiveTile(calendarItem, -1);
                }
                else
                {
                    calendarItem.PinIconOpacity = 0.3;
                    GetAppBarButton(AppResources.PinCalendarLivetile).IsEnabled = true;
                }
            }
        }