コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: MainPageCalendar.cs プロジェクト: yookjy/Chameleon
        public void LoadCalendar(DateTime dt)
        {
            //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            //watch.Start();
            //선택할 날짜
            DateTime selectDt = CurrentCalendar;

            if (CurrentCalendar.Year == 1)
            {
                selectDt = DateTime.Now;
            }

            //이전값 복원
            if (CalendarSelector.SelectedItem != null)
            {
                selectDt = (CalendarSelector.SelectedItem as Day).DateTime;
            }

            CurrentCalendar   = dt;
            PICalendar.Header = dt.ToString(DateTimeFormatInfo.CurrentInfo.YearMonthPattern.Replace("MMMM", "MMM"));

            int dim = DateTimeFormatInfo.CurrentInfo.Calendar.GetDaysInMonth(dt.Year, dt.Month);

            List <Day> dayList = VsCalendar.GetCalendarOfMonth(dt, new DateTime(), false, false);

            CalendarSelector.ItemsSource = dayList;

            if (IsShowAppointment)
            {
                Dictionary <string, object> state = new Dictionary <string, object>();
                state.Add("dayList", dayList);
                state.Add("selectDay", selectDt);

                appointments.SearchAsync(dayList[0].DateTime, dayList[dayList.Count - 1].DateTime, state);
            }

            //watch.Stop();
            //System.Diagnostics.Debug.WriteLine(watch.ElapsedMilliseconds);
        }
コード例 #3
0
        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());
                    }
                }
            });
        }
コード例 #4
0
ファイル: ScheduledAgent.cs プロジェクト: yookjy/Chameleon
        /// <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);
                    }
                });
            }
        }
コード例 #5
0
ファイル: MainPageLivetile.cs プロジェクト: yookjy/Chameleon
        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;
                }
            }
        }