public SettingPage() { InitializeComponent(); PageTitle = string.Format("{0} - {1}", AppResources.ApplicationTitle, AppResources.Settings); scheduleSettings = MutexedIsoStorageFile.Read <ScheduleSettings>("ScheduleSettings", Constants.MUTEX_DATA); //초기 락스크린 컬러 피커값 저장 loadOrgColorPickerValue(); }
// 생성자 public MainPage() { InitializeComponent(); //업그레이드 관련 작업 UpgradeVersion(); DateTime LastRunForLivetile, LastRunForLockscreen; IsolatedStorageSettings.ApplicationSettings.TryGetValue <DateTime>(Constants.LAST_RUN_LIVETILE, out LastRunForLivetile); IsolatedStorageSettings.ApplicationSettings.TryGetValue <DateTime>(Constants.LAST_RUN_LOCKSCREEN, out LastRunForLockscreen); //스케줄러 복구 모드 scheduleSettings = MutexedIsoStorageFile.Read <ScheduleSettings>("ScheduleSettings", Constants.MUTEX_DATA); if (DateTime.Now.Subtract(LastRunForLivetile).TotalMinutes > scheduleSettings.LivetileUpdateInterval + 60 && //원래 업데이트 시간보다 60분 초과 DateTime.Now.Subtract(LastRunForLockscreen).TotalMinutes > scheduleSettings.LockscreenUpdateInterval + 60) { //스케줄러 초기화 RemoveAgent(Constants.PERIODIC_TASK_NAME); } //위치 고정 InitializeSystemTray(); //보호색 설정 InitializeProtectiveColor(); //락스크린 초기화 MainPageLockscreen(); //라이브타일 초기화 MainPageLivetile(); //날씨 초기화 MainPageWeather(); //달력 초기화 MainPageCalendar(); //앱바 기본설정 설정 BuildLocalizedApplicationBar(); #if (DEBUG_AGENT) RemoveAgent(Constants.PERIODIC_TASK_NAME); StartPeriodicAgent(); ScheduledActionService.LaunchForTest(Constants.PERIODIC_TASK_NAME, TimeSpan.FromSeconds(30)); //MessageBox.Show("스케줄러가 강제 시작됨"); #endif }
public static void CreateDefaultValues() { ScheduleSettings scheduleSetting = MutexedIsoStorageFile.Read <ScheduleSettings>("ScheduleSettings", Constants.MUTEX_DATA); //락스크린의 템플릿 SetDefaultSetting(Constants.LOCKSCREEN_BACKGROUND_TEMPLATE, new LockscreenTemplateItem() { LockscreenItemInfos = new LockscreenItemInfo[] { new LockscreenItemInfo { LockscreenItem = LiveItems.Weather, Column = 0, Row = 0, ColSpan = 1, RowSpan = 3 }, new LockscreenItemInfo { LockscreenItem = LiveItems.Calendar, Column = 1, Row = 0, ColSpan = 1, RowSpan = 3 } } }); //락스크린의 뒷배경 분할 SetDefaultSetting(Constants.LOCKSCREEN_BACKGROUND_USE_SEPARATION, false); //락스크린의 배경 색상 SetDefaultSetting(Constants.LOCKSCREEN_BACKGROUND_COLOR, new ColorItem() { Text = AppResources.ColorChrome, Color = ColorItem.ConvertColor(0xFF1F1F1F) }); //락스크린의 배경 투명도 SetDefaultSetting(Constants.LOCKSCREEN_BACKGROUND_OPACITY, Constants.LOCKSCREEN_BACKGROUND_DEFAULT_OPACITY); //락스크린의 글자 굵기 SetDefaultSetting(Constants.LOCKSCREEN_FONT_WEIGHT, FontWeights.Bold.ToString()); //락스크린의 업데이트 주기 if (scheduleSetting.LockscreenUpdateInterval == 0) { scheduleSetting.LockscreenUpdateInterval = 180; MutexedIsoStorageFile.Write <ScheduleSettings>(scheduleSetting, "ScheduleSettings", Constants.MUTEX_DATA); } //라이브타일 랜덤색상 사용여부 SetDefaultSetting(Constants.LIVETILE_RANDOM_BACKGROUND_COLOR, true); ColorItem accentColorItem = new ColorItem() { Color = (Color)Application.Current.Resources["PhoneAccentColor"] }; if (string.IsNullOrEmpty(accentColorItem.Text)) { accentColorItem.Text = AppResources.AccentColor; } //메인 라이브타일의 배경색상 SetDefaultSetting(Constants.LIVETILE_CALENDAR_BACKGROUND_COLOR, accentColorItem); //보조 라이브타일의 템플릿... SetDefaultSetting(Constants.LIVETILE_WEATHER_BACKGROUND_COLOR, accentColorItem); //배터리 라이브타일의 템플릿... SetDefaultSetting(Constants.LIVETILE_BATTERY_BACKGROUND_COLOR, accentColorItem); //날씨 타일 폰트 크기 SetDefaultSetting(Constants.LIVETILE_WEATHER_FONT_SIZE, new PickerItem() { Key = 1.1, Name = string.Format(AppResources.Percent, 1.1 * 100) }); //날씨 및 달력의 글자 굵기 SetDefaultSetting(Constants.LIVETILE_FONT_WEIGHT, FontWeights.SemiBold.ToString()); //배터리 완충 상태 표시 SetDefaultSetting(Constants.LIVETILE_BATTERY_FULL_INDICATION, new PickerItem() { Key = 100, Name = AppResources.BatteryFull }); //라이브타일의 업데이트 주기 if (scheduleSetting.LivetileUpdateInterval == 0) { scheduleSetting.LivetileUpdateInterval = 60; MutexedIsoStorageFile.Write <ScheduleSettings>(scheduleSetting, "ScheduleSettings", Constants.MUTEX_DATA); } //보호색 사용여부 SetDefaultSetting(Constants.CHAMELEON_USE_PROTECTIVE_COLOR, true); //보호이미지 사용여부 SetDefaultSetting(Constants.CHAMELEON_USE_PROTECTIVE_IMAGE, false); SetDefaultSetting(Constants.CHAMELEON_SKIN_BACKGROUND_COLOR, new ColorItem() { Color = ColorItem.GetColorByName("Green") }); //날씨 위치 서비스 if (!SettingHelper.ContainsKey(Constants.WEATHER_USE_LOCATION_SERVICES)) { SettingHelper.Set(Constants.WEATHER_USE_LOCATION_SERVICES, true, false); } //날씨 표시 단위 if (!SettingHelper.ContainsKey(Constants.WEATHER_UNIT_TYPE)) { if (System.Globalization.CultureInfo.CurrentUICulture.Name == "en-US") { SettingHelper.Set(Constants.WEATHER_UNIT_TYPE, DisplayUnit.Fahrenheit, false); } else { SettingHelper.Set(Constants.WEATHER_UNIT_TYPE, DisplayUnit.Celsius, false); } } //날씨 기본 아이콘 설정 if (!SettingHelper.ContainsKey(Constants.WEATHER_ICON_TYPE)) { SettingHelper.Set(Constants.WEATHER_ICON_TYPE, WeatherIconType.Simple01, false); } //달력의 첫요일 SetDefaultSetting(Constants.CALENDAR_FIRST_DAY_OF_WEEK, DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek); //달력 약속 표시 SetDefaultSetting(Constants.CALENDAR_SHOW_APPOINTMENT, true); //시작 페이지 설정 SetDefaultSetting(Constants.COMMON_FIRST_PAGE_ITEM, 0); //기본 빙마켓 설정 SetDefaultSetting(Constants.BING_LANGUAGE_MARKET, System.Globalization.CultureInfo.CurrentUICulture.Name); SetDefaultSetting(Constants.BING_SEARCH_ASPECT, "Tall"); SetDefaultSetting(Constants.BING_SEARCH_OPTIONS, "None"); SetDefaultSetting(Constants.BING_SEARCH_SIZE, "Large"); SetDefaultSetting(Constants.BING_SEARCH_SIZE_WIDTH, "" + (int)ResolutionHelper.CurrentResolution.Width); SetDefaultSetting(Constants.BING_SEARCH_SIZE_HEIGHT, "" + (int)ResolutionHelper.CurrentResolution.Height); SetDefaultSetting(Constants.BING_SEARCH_COLOR, "Color"); SetDefaultSetting(Constants.BING_SEARCH_STYLE, "Photo"); SetDefaultSetting(Constants.BING_SEARCH_FACE, "Other"); SetDefaultSetting(Constants.BING_SEARCH_COUNT, "40"); SetDefaultSetting(Constants.BING_SEARCH_ADULT, "Strict"); //손전등 - 토글버튼 사용 설정 SetDefaultSetting(Constants.FLASHLIGHT_USE_TOGGLE_SWITCH, true); SettingHelper.Save(); }
/// <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); } }); } }
// ViewModel 항목에 대한 데이터를 로드합니다. protected override void OnNavigatedTo(NavigationEventArgs e) { string from; NavigationContext.QueryString.TryGetValue("from", out from); if (from == "flashlight") { NavigationService.RemoveBackEntry(); } //네비게이션 모드 bool isChangedSettings = e.NavigationMode == NavigationMode.Back && PhoneApplicationService.Current.State.ContainsKey(Constants.CHANGED_SETTINGS); //스케쥴 데이터 로드 scheduleSettings = MutexedIsoStorageFile.Read <ScheduleSettings>("ScheduleSettings", Constants.MUTEX_DATA); if (e.NavigationMode == NavigationMode.New) { //달력 환경 설정 로딩 LoadConfigCalendar(); //라이브타일 로드 LoadLivetile(); //락스크린 리스트 로드 LoadLockscreenList(); //날씨 로드(비동기 처리로..) LoadLiveWeather(); //달력 로드 LoadCalendar(DateTime.Now); } else { if (PanoramaMainView != null && PanoramaMainView.SelectedItem != null) { string panoramaName = (PanoramaMainView.SelectedItem as PanoramaItem).Name; if (panoramaName == PILockscreen.Name) { //락스크린 리스트 로드 LoadLockscreenList(); } else if (panoramaName == PIWeather.Name) { //if (!PhoneApplicationService.Current.State.ContainsKey(Constants.WEATHER_MAIN_CITY)) //{ // PhoneApplicationService.Current.State[Constants.WEATHER_UNIT_TYPE] = true; //} //날씨 조회 지역을 찾아서 선택하고 들어온 경우는 날씨를 업데이트 해주고 락스크린을 갱신 if (PhoneApplicationService.Current.State.ContainsKey(Constants.WEATHER_MAIN_CITY)) { WeatherCity city = PhoneApplicationService.Current.State[Constants.WEATHER_MAIN_CITY] as WeatherCity; //위의 설정값은 RetriveWeather에서도 사용되며, 콜백 메소드에서 사용되므로 해당 콜백 메소드에서 지워야 함. RetrieveWeather(city); } } else if (panoramaName == PICalendar.Name) { //달력 환경 설정 로딩 LoadConfigCalendar(); //등록후 재검색.. LoadCalendar(CurrentCalendar); //락스크린 갱신되도록 설정 PhoneApplicationService.Current.State[Constants.LIVETILE_CALENDAR_BACKGROUND_COLOR] = true; } } } string lockscreenKey = "WallpaperSettings"; string piName = string.Empty; if (NavigationContext.QueryString.TryGetValue(lockscreenKey, out piName)) { //잠금화면 설정에서 진입했는가를 체크 piName = PILockscreen.Name; } else { //라이브 타일을 눌러서 진입했는가를 체크 NavigationContext.QueryString.TryGetValue("pi", out piName); NavigationContext.QueryString.Remove("pi"); } if (!string.IsNullOrEmpty(piName)) { //해당 메뉴로 이동 시킴 foreach (PanoramaItem pi in PanoramaMainView.Items) { if (pi.Name == piName) { PanoramaMainView.DefaultItem = pi; if (piName == PILivetile.Name) { ApplicationBar = IAppBarLivetile; ApplicationBar.IsVisible = true; } else if (piName == PILockscreen.Name) { ApplicationBar = IAppBarLockscreen; ApplicationBar.IsVisible = true; } else if (piName == PIWeather.Name) { ApplicationBar = iAppBarWeather; ApplicationBar.IsVisible = true; PhoneApplicationService.Current.State[Constants.WEATHER_UNIT_TYPE] = true; } else if (piName == PICalendar.Name) { ApplicationBar = IAppBarCalendar; ApplicationBar.IsVisible = true; } break; } } } bool isLoadedBatteryTile = false; bool isLoadedWeatherTile = false; bool isLoadedCalendarTile = false; if (ExistStatus(Constants.LIVETILE_RANDOM_BACKGROUND_COLOR)) { //라이브타일 전체 다시 로드 CreateCalendarLivetileImage(); CreateWeatherLivetileImage(); CreateBatteryLivetileImage(); //타일 로딩 여부 isLoadedCalendarTile = true; isLoadedBatteryTile = true; } else { if (ExistStatus(Constants.LIVETILE_CALENDAR_BACKGROUND_COLOR)) { //달력 라이브타일 다시 로드 CreateCalendarLivetileImage(); isLoadedCalendarTile = true; } if (ExistStatus(Constants.LIVETILE_WEATHER_BACKGROUND_COLOR)) { //날씨 라이브타일 다시 로드 CreateWeatherLivetileImage(); isLoadedWeatherTile = true; } if (ExistStatus(Constants.LIVETILE_BATTERY_BACKGROUND_COLOR)) { //배터리 라이브타일 다시 로드 CreateBatteryLivetileImage(); isLoadedBatteryTile = true; } } if (ExistStatus(Constants.LIVETILE_FONT_WEIGHT)) { if (!isLoadedWeatherTile) { //날씨 라이브타일 다시 로드 CreateWeatherLivetileImage(); } if (!isLoadedCalendarTile) { //달력 라이브타일 다시 로드 CreateCalendarLivetileImage(); } } if (ExistStatus(Constants.LIVETILE_WEATHER_FONT_SIZE) && !isLoadedWeatherTile) { //날씨 라이브타일 다시 로드 CreateWeatherLivetileImage(); } if (ExistStatus(Constants.LIVETILE_BATTERY_FULL_INDICATION) && !isLoadedBatteryTile) { //배터리 라이브타일 다시 로드 CreateBatteryLivetileImage(); } if (ExistStatus(Constants.WEATHER_UNIT_TYPE) || ExistStatus(Constants.WEATHER_ICON_TYPE)) { //날시 아이콘 다시 로딩 if (ExistStatus(Constants.WEATHER_ICON_TYPE)) { WeatherIconMap.Instance.Load((WeatherIconType)SettingHelper.Get(Constants.WEATHER_ICON_TYPE)); } //날씨 갱신 (무조건) RefreshLiveWeather(); } if (ExistStatus(Constants.CHAMELEON_USE_PROTECTIVE_COLOR)) { if (!(bool)SettingHelper.Get(Constants.CHAMELEON_USE_PROTECTIVE_COLOR)) { //바탕화면 색상 갱신 Color color = (SettingHelper.Get(Constants.CHAMELEON_SKIN_BACKGROUND_COLOR) as ColorItem).Color; ChangeBackgroundColor(color); SetAppbarColor(ApplicationBar, color); } } if (ExistStatus(Constants.CALENDAR_FIRST_DAY_OF_WEEK) || ExistStatus(Constants.CALENDAR_SHOW_APPOINTMENT)) { LoadConfigCalendar(); LoadCalendar(CurrentCalendar); //달력 타일 로드 if (!isLoadedCalendarTile) { CreateCalendarLivetileImage(); } } PhoneApplicationService.Current.State.Remove(Constants.CHANGED_SETTINGS); PhoneApplicationService.Current.State.Remove(Constants.CHAMELEON_USE_PROTECTIVE_COLOR); PhoneApplicationService.Current.State.Remove(Constants.LIVETILE_CALENDAR_BACKGROUND_COLOR); PhoneApplicationService.Current.State.Remove(Constants.LIVETILE_WEATHER_BACKGROUND_COLOR); PhoneApplicationService.Current.State.Remove(Constants.LIVETILE_BATTERY_BACKGROUND_COLOR); PhoneApplicationService.Current.State.Remove(Constants.LIVETILE_WEATHER_FONT_SIZE); PhoneApplicationService.Current.State.Remove(Constants.LIVETILE_BATTERY_FULL_INDICATION); PhoneApplicationService.Current.State.Remove(Constants.WEATHER_UNIT_TYPE); PhoneApplicationService.Current.State.Remove(Constants.WEATHER_ICON_TYPE); PhoneApplicationService.Current.State.Remove(Constants.CALENDAR_FIRST_DAY_OF_WEEK); PhoneApplicationService.Current.State.Remove(Constants.CALENDAR_SHOW_APPOINTMENT); }