private async void UpdateLockScreenImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var isProvider = LockScreenManager.IsProvidedByCurrentApplication;
                if (!isProvider)
                {
                    var op = await LockScreenManager.RequestAccessAsync();

                    isProvider = op == LockScreenRequestResult.Granted;
                }

                if (isProvider)
                {
                    var uri = new Uri("ms-appx:///Assets/Lock/kramer.jpg", UriKind.Absolute);
                    LockScreen.SetImageUri(uri);
                }
                else
                {
                    MessageBox.Show("You said no, so I can't update your background.");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
예제 #2
0
        private async static Task SetLockScreen(string fileName)
        {
            bool hasAccessForLockScreen = LockScreenManager.IsProvidedByCurrentApplication;

            if (!hasAccessForLockScreen)
            {
                var accessRequested = await LockScreenManager.RequestAccessAsync();

                hasAccessForLockScreen = (accessRequested == LockScreenRequestResult.Granted);
            }

            if (hasAccessForLockScreen)
            {
                Uri imgUri = new Uri("ms-appdata:///Local/" + BackgroundRoot + fileName, UriKind.Absolute);
                LockScreen.SetImageUri(imgUri);
            }

            var mainTile = ShellTile.ActiveTiles.FirstOrDefault();

            if (null != mainTile)
            {
                Uri iconUri = new Uri("isostore:///" + IconRoot + fileName, UriKind.Absolute);
                var images  = new List <Uri>();
                images.Add(iconUri);

                CycleTileData tileData = new CycleTileData();
                tileData.CycleImages = images;

                mainTile.Update(tileData);
            }
        }
예제 #3
0
        private async void ButtonSetImage_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var isProvider = LockScreenManager.IsProvidedByCurrentApplication;
                if (!isProvider)
                {
                    LockScreenRequestResult op = await LockScreenManager.RequestAccessAsync();

                    isProvider = op == LockScreenRequestResult.Granted;
                }
                if (isProvider)
                {
                    if (App.MainViewModel.ImageUri == App.MainViewModel.DefaultImageUri)
                    {
                        LockScreen.SetImageUri(new Uri("ms-appx://" + App.MainViewModel.DefaultImageUriSystem.OriginalString));
                    }
                    else
                    {
                        LockScreen.SetImageUri(new Uri("ms-appdata:///local/" + imageFileNameSystem));
                    }
                    App.MainViewModel.RaisePropertyChanged("IsLockscreen");
                    MessageBox.Show(AppResources.SettingBackgroundSuccess);
                }
                else
                {
                    MessageBox.Show(AppResources.SettingBackgroundError);
                }
            }
            catch { MessageBox.Show(AppResources.SettingBackgroundError); }
        }
예제 #4
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                var result = await LockScreenManager.RequestAccessAsync();

                if (result == LockScreenRequestResult.Granted)
                {
                    var photolen = IsolatedStorageSettings.ApplicationSettings["navchk"] as string;
                    if (photolen == "0")
                    {
                        MessageBox.Show("Please choose some images");
                    }
                    else
                    {
                        StartLockScreenImageChange();
                    }
                }
            }
            else
            {
                var photolen = IsolatedStorageSettings.ApplicationSettings["navchk"] as string;
                if (photolen == "0")
                {
                    MessageBox.Show("Please choose some images");
                }
                else
                {
                    StartLockScreenImageChange();
                }
            }
        }
예제 #5
0
        async void btnPinToStart_Click(object sender, EventArgs e)
        {
            var uri = NavigationService.Source.ToString();

            if (Features.Tile.TileExists(uri))
            {
                Features.Tile.DeleteTile(uri);
            }
            else
            {
                //Setup lockscreen background once setting the recipe as favorite
                if (!LockScreenManager.IsProvidedByCurrentApplication)
                {
                    await LockScreenManager.RequestAccessAsync();
                }

                if (LockScreenManager.IsProvidedByCurrentApplication)
                {
                    Uri imageUri = new Uri("ms-appx:///" + item.ImagePath.LocalPath, UriKind.RelativeOrAbsolute);
                    System.Diagnostics.Debug.WriteLine(imageUri.OriginalString);

                    LockScreen.SetImageUri(imageUri);
                }

                Features.Tile.SetTile(item, uri);
            }

            SetPinBar();
        }
예제 #6
0
        public async void SetLockScreen(string bloodType)
        {
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                await LockScreenManager.RequestAccessAsync();
            }

            if (LockScreenManager.IsProvidedByCurrentApplication)
            {
                LockScreenChange(bloodType, true);
            }
        }
예제 #7
0
파일: Program.cs 프로젝트: geandev/ardulock
 private static void LockScreen()
 {
     if (!PositionsIsFull())
     {
         return;
     }
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine("Locked");
     Console.ResetColor();
     LockScreenManager.Use(new WindowsUser32LockStationStrategy(), m => m.LockNow());
     LastPositions.Clear();
 }
예제 #8
0
        public async void GetLockScreenPermission()
        {
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                var result = await LockScreenManager.RequestAccessAsync();

                if (result == LockScreenRequestResult.Granted)
                {
                    MessageBox.Show("Now You Can Change Your LockScreen for every 20 minutes.");
                    MessageBox.Show("Choose the photos from your library by clicking Add Photos button");
                    MessageBox.Show("Click the Change Lockscreen button to change it for every 20 minutes");
                }
            }
        }
예제 #9
0
        public async static void SetBackgroundImage(Uri imageUri)
        {
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                var permission = await LockScreenManager.RequestAccessAsync();

                if (permission == LockScreenRequestResult.Denied)
                {
                    return;
                }
            }

            LockScreen.SetImageUri(imageUri);
        }
예제 #10
0
        public static async void SetLockscreen(string filePathOfTheImage, bool isAppResource, AsyncCallback asyncCallback)
        {
            AsyncLockScreenResult result = null;

            try
            {
                var isProvider = LockScreenManager.IsProvidedByCurrentApplication;
                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.
                    var op = await LockScreenManager.RequestAccessAsync();

                    // Only do further work if the access was granted.
                    isProvider = (op == LockScreenRequestResult.Granted);
                }

                if (isProvider)
                {
                    // At this stage, the app is the active lock screen background provider.

                    // The following code example shows the new URI schema.
                    // ms-appdata points to the root of the local app data folder.
                    // ms-appx points to the Local app install folder, to reference resources bundled in the XAP package.
                    var schema = isAppResource ? Constants.PREFIX_APP_RESOURCE_FOLDER : Constants.PREFIX_APP_DATA_FOLDER;
                    var uri    = new Uri(schema + filePathOfTheImage, UriKind.Absolute);

                    // Set the lock screen background image.
                    LockScreen.SetImageUri(uri);

                    // Get the URI of the lock screen background image.
                    var currentImage = LockScreen.GetImageUri();
                    System.Diagnostics.Debug.WriteLine("The new lock screen background image is set to {0}", currentImage.ToString());
                    result = new AsyncLockScreenResult(true, null, true, true);
                }
                else
                {
                    //"You said no, so I can't update your background."
                    System.Diagnostics.Debug.WriteLine("아니오가 선택되어 잠금화면으로 설정할 수 없음."); //"You said no, so I can't update your background."
                    result = new AsyncLockScreenResult(false, null, true, true);
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                result = new AsyncLockScreenResult(ex.Message, null, true, true);
            }

            asyncCallback.Invoke(result);
        }
예제 #11
0
        public static async Task <bool> EnsureOrRequestLockScreenAccess()
        {
            if (LockScreenManager.IsProvidedByCurrentApplication)
            {
                return(true);
            }
            else
            {
                // If you're not the provider, this call will prompt the user for permission.
                // Calling RequestAccessAsync from a background agent is not allowed.
                var result = await LockScreenManager.RequestAccessAsync();

                return(result == LockScreenRequestResult.Granted);
            }
        }
예제 #12
0
        /// <summary>
        /// Sets the current app as the lock screen background provider.
        /// </summary>
        /// <returns>The <see cref="Task"/> object representing the asynchronous operation.</returns>
        public async Task <LockScreenServiceRequestResult> RequestAccessAsync()
        {
            var result = await LockScreenManager.RequestAccessAsync();

            switch (result)
            {
            case LockScreenRequestResult.Denied:
                return(LockScreenServiceRequestResult.Denied);

            case LockScreenRequestResult.Granted:
                return(LockScreenServiceRequestResult.Granted);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #13
0
        private async void LockScreenChange(string bloodtype, bool isAppResource)
        {
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                await LockScreenManager.RequestAccessAsync();
            }

            if (LockScreenManager.IsProvidedByCurrentApplication)
            {
                BeginSaveJpeg(bloodtype);
            }
            else
            {
                MessageBox.Show("Background cant be updated as you clicked no!!");
            }
        }
예제 #14
0
        private async void LockscreenProvider_Toggle_Checked(object sender, RoutedEventArgs e)
        {
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                var result = await LockScreenManager.RequestAccessAsync();
            }

            if (LockScreenManager.IsProvidedByCurrentApplication)
            {
                IsolatedStorageSettings.ApplicationSettings["shouldChange"] = true;
                StartAgent();
            }
            else
            {
                LockscreenProvider_Toggle.IsChecked = false;
            }
        }
예제 #15
0
        /// <summary>
        /// Handle the lockscreen button is clicked.
        /// </summary>
        async void lockscreenButton_Click(object sender, EventArgs args)
        {
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                await LockScreenManager.RequestAccessAsync();
            }

            if (LockScreenManager.IsProvidedByCurrentApplication)
            {
                // retrieve the filename
                var fileName = string.Format("lockscreen-{0}.jpg", DateTime.Now.Ticks);

                // start to download the picture and save it
                var webClient = new WebClient();
                webClient.OpenReadCompleted += (s, e) =>
                {
                    SystemTray.ProgressIndicator.IsVisible = false;

                    BitmapImage bitmap = new BitmapImage();
                    bitmap.SetSource(e.Result);

                    using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (file.FileExists(fileName))
                        {
                            file.DeleteFile(fileName);
                        }

                        IsolatedStorageFileStream fileStream = file.CreateFile(fileName);
                        WriteableBitmap           wb         = new WriteableBitmap(bitmap);
                        System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
                        fileStream.Close();
                    }

                    LockScreen.SetImageUri(new Uri("ms-appdata:///Local/" + fileName, UriKind.Absolute));
                    MessageBox.Show(AppResources.SetLockScreenDoneText);
                };
                webClient.OpenReadAsync(new Uri(imageUrl, UriKind.Absolute));
                SystemTray.ProgressIndicator.IsVisible = true;
            }
        }
예제 #16
0
        private async void ApplicationBarIconButton_Click_Wallpaper(object sender, EventArgs e)
        {
            var    viewModel = (PatternDetailViewModel)ViewModel;
            string title     = viewModel.Title;
            string uriString = viewModel.ImageUrl;
            string fileName  = StripInvalidChars(title) + ".jpeg";

            var size         = ResolutionHelper.DisplayResolution;
            int targetWidth  = (int)size.Width;
            int targetHeight = (int)size.Height;

            lock (locker)
            {
                WriteableBitmap writeableBitmap = GetBitmap(uriString, targetWidth, targetHeight);
                SaveImageToIsolatedStorage(writeableBitmap, targetWidth, targetHeight, fileName);
            }

            using (var section = await critSection.EnterAsync())
            {
                if (!LockScreenManager.IsProvidedByCurrentApplication)
                {
                    LockScreenRequestResult result = await LockScreenManager.RequestAccessAsync();

                    if (result == LockScreenRequestResult.Granted)
                    {
                        lock (locker)
                        {
                            SetAsWallpaper(fileName);
                        }
                    }
                }
                else
                {
                    lock (locker)
                    {
                        SetAsWallpaper(fileName);
                    }
                }
            }
        }
예제 #17
0
        private async void SetLockScreen()
        {
            //Check to see if the app is currently the lock screen provider
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                //Request to be lock screen provider
                await LockScreenManager.RequestAccessAsync();
            }

            //Check to see if the app is currently the lock screen provider
            if (LockScreenManager.IsProvidedByCurrentApplication)
            {
                //Set the image to the lock screen image
                //Uri imageUri = new Uri("ms-appx:///Images/lockscreen.png", UriKind.RelativeOrAbsolute);

                // this works : string.Concat(RootFolder, Images[i], Extension)


                Uri imageUri = GetAsUri(9);
                LockScreen.SetImageUri(imageUri);
            }
        }
        async void miLockscreen_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;

            if (mi != null)
            {
                ContextMenu cm = mi.Parent as ContextMenu;

                FilmInfo fi = (FilmInfo)cm.Tag;

                if (Config.AnimateLockscreen && !LockScreenManager.IsProvidedByCurrentApplication)
                {
                    // If you're not the provider, this call will prompt the user for permission.
                    // Calling RequestAccessAsync from a background agent is not allowed.
                    await LockScreenManager.RequestAccessAsync();
                }

                Config.AnimateLockscreen = LockScreenManager.IsProvidedByCurrentApplication;

                await ScheduledAgent.SetPoster(fi.MediumPosterUrl);
            }
        }
예제 #19
0
        private async void btnLockscreen_Click(object sender, RoutedEventArgs e)
        {
            Config.AnimateLockscreen = this.btnLockscreen.IsChecked == true;

            if (Config.AnimateLockscreen)
            {
                if (!LockScreenManager.IsProvidedByCurrentApplication)
                {
                    // If you're not the provider, this call will prompt the user for permission.
                    // Calling RequestAccessAsync from a background agent is not allowed.
                    await LockScreenManager.RequestAccessAsync();
                }
            }
            else
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-lock:"));
            }

            Config.AnimateLockscreen = LockScreenManager.IsProvidedByCurrentApplication;

            this.btnLockscreen.IsChecked = LockScreenManager.IsProvidedByCurrentApplication;
        }
예제 #20
0
 public static async Task <LockScreenRequestResult> SetLockscreenProvider()
 {
     return(await Task.Run <LockScreenRequestResult>(async() =>
     {
         LockScreenRequestResult result = LockScreenRequestResult.Denied;
         try
         {
             var isProvider = LockScreenManager.IsProvidedByCurrentApplication;
             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.
                 result = await LockScreenManager.RequestAccessAsync();
             }
         }
         catch (System.Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.ToString());
         }
         return result;
     }));
 }
예제 #21
0
        async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!LockScreenManager.IsProvidedByCurrentApplication)
            {
                await LockScreenManager.RequestAccessAsync();
            }

            new UpdateBackgroundAgent().StartPeriodicAgent();

            DailyQuoteLogic.Settings.AccentColor = ((SolidColorBrush)App.Current.Resources["PhoneAccentBrush"]).Color;

            try
            {
                await ShowQuote();
            }
            catch (Exception)
            {
                MessageBox.Show("Could not download quote. Pin to start and wait for quotes.");
            }
            finally
            {
                loadingProgressBar.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
예제 #22
0
 public void Should_throw_Exception()
 {
     Assert.ThrowsException <NullReferenceException>(() => LockScreenManager.Use(null, m => m.LockNow()));
     _lockWorkStationStrategy.Verify(x => x.Lock(), Times.Never());
 }
예제 #23
0
        private static async Task SetLockScreen(string fileName)
        {
            // This article describes how to programmatically
            // take control of the lockscreen background:
            // http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206968(v=vs.105).aspx

            // Right-click WMAppManifest.xml, select Open With ...
            // Choose 'XML (Text) Editor with Encoding'
            // Choose AutoDetect when asked about which Encoding

            // IMPORTANT: Add this under </Tokens> section:
            //

            /*
             *  <Extensions>
             *          <Extension ExtensionName="LockScreen_Background"
             *       ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}"
             *       TaskID="_default" />
             *  </Extensions>
             */
            // That will make our app a Lock Screen Background "provider".

            // Lockscreen Design Guidelines
            // http://msdn.microsoft.com/en-us/library/windowsphone/design/jj662927(v=vs.105).aspx

            bool hasAccessForLockScreen
                = LockScreenManager.IsProvidedByCurrentApplication;

            if (!hasAccessForLockScreen)
            {
                // If you're not the provider, this call will prompt the user for permission.
                // Calling RequestAccessAsync from a background agent is not allowed.
                var accessRequested = await LockScreenManager.RequestAccessAsync();

                // Only do further work if the access was granted.
                hasAccessForLockScreen = (accessRequested == LockScreenRequestResult.Granted);
            }

            if (hasAccessForLockScreen)
            {
                Uri imgUri = new Uri(
                    "ms-appdata:///local/" + BackgroundRoot + fileName,
                    UriKind.Absolute);
                LockScreen.SetImageUri(imgUri);
            }

            var mainTile = ShellTile.ActiveTiles.FirstOrDefault();

            if (null != mainTile)
            {
                Uri iconUri = new Uri("isostore:///" + IconRoot + fileName, UriKind.Absolute);
                var imgs    = new List <Uri>();
                imgs.Add(iconUri);

                CycleTileData tileData = new CycleTileData();
                tileData.CycleImages = imgs;
                //tileData.IconImage = imgUri;

                mainTile.Update(tileData);
            }
        }
예제 #24
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());
                    }
                }
            });
        }
예제 #25
0
 public void Should_Call_LockNow()
 {
     LockScreenManager.Use(_lockWorkStationStrategy.Object, m => m.LockNow());
     _lockWorkStationStrategy.Verify(x => x.Lock(), Times.Once());
 }