private async void appBarIconBtnPreview_Click(object sender, EventArgs e) { await Task.Delay(10); ApplicationBar.IsVisible = false; LoadingProgressBar.Visibility = System.Windows.Visibility.Visible; LoadingText.Text = AppResources.MsgCreatingPreview; LockscreenData data = new LockscreenData(false) { BackgroundBitmap = GetCropImage(), DayList = VsCalendar.GetCalendarOfMonth(DateTime.Now, DateTime.Now, true, true), LiveWeather = SettingHelper.Get(Constants.WEATHER_LIVE_RESULT) as LiveWeather, Forecasts = SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT) as Forecasts }; if ((bool)SettingHelper.Get(Constants.CALENDAR_SHOW_APPOINTMENT)) { Appointments appointments = new Appointments(); appointments.SearchCompleted += (s, se) => { VsCalendar.MergeCalendar(data.DayList, se.Results); LockscreenHelper.RenderLayoutToBitmap(data); DisplayPreview(data.BackgroundBitmap); }; appointments.SearchAsync(data.DayList[7].DateTime, data.DayList[data.DayList.Count - 1].DateTime, null); } else { LockscreenHelper.RenderLayoutToBitmap(data); DisplayPreview(data.BackgroundBitmap); } }
void appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e) { Dictionary <string, object> state = e.State as Dictionary <string, object>; List <Day> dayList = state["dayList"] as List <Day>; DateTime selectDay = (DateTime)state["selectDay"]; //달력과 약속 데이터 합침 dayList = VsCalendar.MergeCalendar(dayList, e.Results); CalendarSelector.ItemsSource = dayList; //날짜 선택 IEnumerable <Day> days = from Day day in dayList where day.DateTime.ToLongDateString() == selectDay.ToLongDateString() select day; if (days.Any()) { //오늘 날짜를 디폴트 선택값으로 설정 CalendarSelector.SelectedItem = days.First(); //오늘 날짜에 약속이 있으면 약속을 표시 if (days.First().AppointmentList != null) { IOrderedEnumerable <Appointment> appointments = days.First().AppointmentList.OrderBy(x => x.StartTime); CalendarAppointmentSelector.ItemsSource = appointments.ToList(); CalendarAppointmentSelector.SelectedItem = days.First(); var item = appointments.Where(x => { if (x.StartTime.CompareTo(DateTime.Now) <= 1 && x.EndTime.CompareTo(DateTime.Now) >= 1) { return(true); } return(false); }); //현재 시간에 걸린 아이템으로 스크롤을 옮긴다. if (item.Any() && item.Count() > 2) { CalendarAppointmentSelector.ScrollTo(item.First()); } } } else { CalendarAppointmentSelector.ItemsSource = null; } }
private void DelegateUpdateProcess(ScheduledTask task, LiveData data, bool hasCalendar) { if (hasCalendar && (bool)SettingHelper.Get(Constants.CALENDAR_SHOW_APPOINTMENT)) { //일정이 몇개 있는지를 백타일에 표시 Appointments ap = new Appointments(); ap.SearchCompleted += (so, se) => { VsCalendar.MergeCalendar(data.DayList, se.Results); if (data is LockscreenData) { SetLockscreenImage(task, (LockscreenData)data); } else { SetLivetileImage(task, (LivetileData)data); } //완료됨을 OS에 알림 NotifyComplete(); }; ap.SearchAsync(data.DayList[7].DateTime, data.DayList[data.DayList.Count - 1].DateTime.AddDays(1), null); } else { //백타일에 일정 표시하지 않음 if (data is LockscreenData) { SetLockscreenImage(task, (LockscreenData)data); } else { SetLivetileImage(task, (LivetileData)data); } //완료됨을 OS에 알림 NotifyComplete(); } }
private async Task SelectLockscreen(PhonePicture picture) { await Task.Run(async() => { if (picture != null) { try { var isProvider = LockScreenManager.IsProvidedByCurrentApplication; var op = isProvider ? LockScreenRequestResult.Granted : LockScreenRequestResult.Denied; if (!isProvider) { // If you're not the provider, this call will prompt the user for permission. // Calling RequestAccessAsync from a background agent is not allowed. op = await LockScreenManager.RequestAccessAsync(); } if (op == LockScreenRequestResult.Granted) { Dispatcher.BeginInvoke(() => { //로딩 패널 띄움 ShowLoadingPanel(AppResources.MsgApplyingLockscreen); using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream sourceStream = isoStore.OpenFile(picture.Name, FileMode.Open, FileAccess.Read)) { WriteableBitmap wb = BitmapFactory.New(0, 0).FromStream(sourceStream); Size rSize = ResolutionHelper.CurrentResolution; MemoryStream ms = null; LockscreenData data = new LockscreenData(false) { DayList = VsCalendar.GetCalendarOfMonth(DateTime.Now, DateTime.Now, true, true), LiveWeather = SettingHelper.Get(Constants.WEATHER_LIVE_RESULT) as LiveWeather, Forecasts = SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT) as Forecasts, BackgroundBitmap = wb.Crop(new Rect((wb.PixelWidth - rSize.Width) / 2, (wb.PixelHeight - rSize.Height) / 2, rSize.Width, rSize.Height)) }; //편집이 필요한 이미지라면 스트림 생성 및 이미지 복사 if (picture.Warnning != null) { //메모리 스트림 생성 (close 처리는 SetLockscreen에서 한다.) ms = new MemoryStream(); //잘라내기가 된 이미지를 스트림에 저장 data.BackgroundBitmap.SaveJpeg(ms, data.BackgroundBitmap.PixelWidth, data.BackgroundBitmap.PixelHeight, 0, 100); } if ((bool)SettingHelper.Get(Constants.CALENDAR_SHOW_APPOINTMENT)) { Appointments appointments = new Appointments(); appointments.SearchCompleted += (s, se) => { VsCalendar.MergeCalendar(data.DayList, se.Results); LockscreenHelper.RenderLayoutToBitmap(data); SetLockscreen(picture, data.BackgroundBitmap, ms); }; appointments.SearchAsync(data.DayList[7].DateTime, data.DayList[data.DayList.Count - 1].DateTime, null); } else { LockscreenHelper.RenderLayoutToBitmap(data); SetLockscreen(picture, data.BackgroundBitmap, ms); } } } }); } } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } }); }
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; } } }