private void Blur_StopTrackingTouch(object sender, SeekBar.StopTrackingTouchEventArgs e) { Drawable drawable = null; wallpaperManager.ForgetLoadedWallpaper(); ThreadPool.QueueUserWorkItem(m => { using (var backgroundcopy = (BitmapDrawable)wallpaperManager.Drawable) { BlurImage blurImage = new BlurImage(Application.Context); blurImage.Load(backgroundcopy.Bitmap).Intensity(e.SeekBar.Progress).Async(true); drawable = new BitmapDrawable(Resources, blurImage.GetImageBlur()); RunOnUiThread(() => { var previousAlpha = wallpaperPreview.Background.Alpha; wallpaperPreview.Background = drawable; wallpaperPreview.Background.Alpha = previousAlpha; }); } }); configurationManager.SaveAValue(ConfigurationParameters.BlurLevel, e.SeekBar.Progress); GC.Collect(0); }
private void Wallpaperbeingsetted_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e) { //This call is necessary because when this event handler is attached, for some reason is being called //Like if the user had clicked a item. why? idk. //if this method is called before the user has the ReadStorage permission the app will crash. //in that case simply do nothing. if (Checkers.ThisAppHasReadStoragePermission()) { currentSpinnerOptionSelected = (int)e.Id; switch (currentSpinnerOptionSelected) { case WallpaperConfig: if (pickwallpaper.Enabled == false) { pickwallpaper.Enabled = true; } switch (configurationManager.RetrieveAValue(ConfigurationParameters.ChangeWallpaper, "0")) { case "0": wallpaperPreview.SetBackgroundColor(Color.Black); blur.Enabled = false; opacity.Enabled = false; appliesToMusicWidget.Enabled = false; break; case "1": ThreadPool.QueueUserWorkItem(m => { wallpaperManager.ForgetLoadedWallpaper(); Bitmap bitmap = ((BitmapDrawable)wallpaperManager.Drawable).Bitmap; BlurImage blurImage = new BlurImage(Application.Context); blurImage.Load(bitmap).Intensity(defaultBlurLevel); Drawable drawable = new BitmapDrawable(Resources, blurImage.GetImageBlur()); RunOnUiThread(() => { wallpaperPreview.Background = drawable; wallpaperPreview.Background.Alpha = defaultOpacityLevel; } ); }); blur.Enabled = true; blur.SetProgress(defaultBlurLevel, true); opacity.Enabled = true; opacity.SetProgress(defaultOpacityLevel, true); appliesToMusicWidget.Enabled = true; //If the user tries to set the album artwork opacity and blur break; case "2": ThreadPool.QueueUserWorkItem(m => { var imagePath = configurationManager.RetrieveAValue(ConfigurationParameters.ImagePath, ""); using (var backgroundcopy = BitmapFactory.DecodeFile(configurationManager.RetrieveAValue(ConfigurationParameters.ImagePath, imagePath))) { BlurImage blurImage = new BlurImage(Application.Context); blurImage.Load(backgroundcopy).Intensity(defaultBlurLevel); var drawable = new BitmapDrawable(Resources, blurImage.GetImageBlur()); RunOnUiThread(() => { wallpaperPreview.Background = drawable; wallpaperPreview.Background.Alpha = defaultOpacityLevel; }); } }); blur.Enabled = true; blur.SetProgress(defaultBlurLevel, true); opacity.Enabled = true; opacity.SetProgress(defaultOpacityLevel, true); appliesToMusicWidget.Enabled = true; //If the user tries to set the album artwork opacity and blur break; } blur.Progress = defaultBlurLevel; opacity.Progress = defaultOpacityLevel; break; case AlbumArtConfig: pickwallpaper.Enabled = false; appliesToMusicWidget.Enabled = false; blur.Enabled = true; opacity.Enabled = true; if (appliesToMusicWidget.Checked == true) { //If the user tries to set the album artwork opacity and blur //then this checkbox is not anymore valid. blur.Enabled = false; //As well as the Seekbars for blur and opacity, because opacity.Enabled = false; //the Default wallpaper config. also applies to the AlbumArt config. //So the user can't slide the seekbars. } currentSpinnerOptionSelected = (int)e.Id; if (appliesToMusicWidget.Checked == true) { albumArtBlurLevel = defaultBlurLevel; albumArtOpacityLevel = defaultOpacityLevel; } ThreadPool.QueueUserWorkItem(m => { Bitmap bitmap = null; if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { bitmap = ((BitmapDrawable)Application.Context.GetDrawable(Resource.Drawable.album_artwork)).Bitmap; } else { bitmap = ((BitmapDrawable)Application.Context.Resources.GetDrawable(Resource.Drawable.album_artwork)).Bitmap; } BlurImage blurImage = new BlurImage(Application.Context); blurImage.Load(bitmap).Intensity(albumArtBlurLevel); Drawable drawable = new BitmapDrawable(Resources, blurImage.GetImageBlur()); RunOnUiThread(() => { wallpaperPreview.Background = drawable; wallpaperPreview.Background.Alpha = albumArtOpacityLevel; } ); } ); blur.Progress = albumArtBlurLevel; opacity.Progress = albumArtOpacityLevel; break; } } }