Esempio n. 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            wallpaperManager = WallpaperManager.GetInstance(Application.Context);

            configurationManager = new ConfigurationManager(PreferenceManager.GetDefaultSharedPreferences(Application.Context));

            // Create your application here
            SetContentView(Resource.Layout.BackgroundSettings);
            wallpaperPreview           = FindViewById <ImageView>(Resource.Id.wallpaperPreview);
            blur                       = FindViewById <SeekBar>(Resource.Id.blur);
            opacity                    = FindViewById <SeekBar>(Resource.Id.opacity);
            opacity.Max                = 255;
            blur.Max                   = 25;
            blur.StopTrackingTouch    += Blur_StopTrackingTouch;
            opacity.StopTrackingTouch += Opacity_StopTrackingTouch;
            if (Build.VERSION.SdkInt > BuildVersionCodes.LollipopMr1)
            {
                if (Application.Context.CheckSelfPermission("android.permission.READ_EXTERNAL_STORAGE") != Permission.Granted)
                {
                    RequestPermissions(new string[1] {
                        "android.permission.READ_EXTERNAL_STORAGE"
                    }, 1);
                }
                else
                {
                    LoadPreviousValues();
                }
            }
            else
            {
                LoadPreviousValues();
            }
        }
        private void SetWallpaperFromStream(Context context, Stream stream)
        {
            WallpaperManager wallpaperManager
                = WallpaperManager.GetInstance(context);

            wallpaperManager.SetStream(stream);
        }
Esempio n. 3
0
 public override void OnReceive(Context context, Intent intent)
 {
     Toast.MakeText(context, "Its time to download the data", ToastLength.Short).Show();
     try
     {
         ThreadPool.QueueUserWorkItem(async m =>
         {
             var httpClient = new HttpClient();
             var result     = await httpClient.GetStringAsync(urlplussecret);
             var post       = JsonConvert.DeserializeObject <ImageOfTheDay>(result);
             imageOfTheDay  = post;
             using (var dbhelper = new DBHelper())
             {
                 dbhelper.InsertIntoTableImageOfTheDay(imageOfTheDay);
                 if (post.Media_Type == "image")
                 {
                     WallpaperManager wallpaperManager = WallpaperManager.GetInstance(Application.Context);
                     wallpaperManager.SetBitmap(ImageComposer.RetrieveImagey(post.Hdurl));
                 }
             }
         });
     }
     catch
     {
         //Failed download
     }
 }
Esempio n. 4
0
        //sevice wallpapers
        public bool GetWallpaperBysystem(Bitmap cropped)
        {
            WallpaperManager wallpaperManager = WallpaperManager.GetInstance(Android.App.Application.Context);


            Android.Graphics.Bitmap CroppedBitmap = Android.Graphics.Bitmap.CreateScaledBitmap(cropped, wallpaperManager.DesiredMinimumWidth, wallpaperManager.DesiredMinimumWidth, true);


            if (Xamarin.Essentials.Preferences.Get("Screen", 1) == 1)
            {
                wallpaperManager.SetBitmap(cropped, null, true, WallpaperManagerFlags.System);
            }
            else if (Xamarin.Essentials.Preferences.Get("Screen", 1) == 2)
            {
                wallpaperManager.SetBitmap(cropped, null, true, WallpaperManagerFlags.Lock);
            }
            else if (Xamarin.Essentials.Preferences.Get("Screen", 1) == 3)
            {
                wallpaperManager.SetBitmap(cropped, null, true, WallpaperManagerFlags.Lock);
                wallpaperManager.SetBitmap(cropped, null, true, WallpaperManagerFlags.System);
            }



            return(true);
        }
Esempio n. 5
0
        private static WallpaperManager GetWallpaperManager()
        {
            if (ContextHelper.Current == null)
            {
                throw new InvalidOperationException("Operation called too early in application lifecycle.");
            }

            return(WallpaperManager.GetInstance(ContextHelper.Current));
        }
Esempio n. 6
0
        public void setWallpaper()
        {
            Bitmap bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.sample);

            WallpaperManager manager = WallpaperManager.GetInstance(ApplicationContext);

            manager.SetBitmap(bitmap);
            //or
            manager.SetBitmap(bitmap, null, true, WallpaperManagerFlags.Lock);
        }
        private void LoadWallpaper(ConfigurationManager configurationManager)
        {
            int savedblurlevel    = configurationManager.RetrieveAValue(ConfigurationParameters.BlurLevel, ConfigurationParameters.DefaultBlurLevel);
            int savedOpacitylevel = configurationManager.RetrieveAValue(ConfigurationParameters.OpacityLevel, ConfigurationParameters.DefaultOpacityLevel);

            switch (configurationManager.RetrieveAValue(ConfigurationParameters.ChangeWallpaper, "1"))
            {
            case "0":

                if (Checkers.ThisAppHasReadStoragePermission())
                {
                    WallpaperManager.GetInstance(Application.Context).ForgetLoadedWallpaper();
                    var wallpaper = WallpaperManager.GetInstance(Application.Context).Drawable;
                    WallpaperPublisher.ChangeWallpaper(new WallpaperChangedEventArgs {
                        Wallpaper = (BitmapDrawable)wallpaper, OpacityLevel = 0, BlurLevel = 0, WallpaperPoster = WallpaperPoster.Lockscreen
                    });
                }
                break;

            case "1":
                if (Checkers.ThisAppHasReadStoragePermission())
                {
                    WallpaperManager.GetInstance(Application.Context).ForgetLoadedWallpaper();
                    var wallpaper = WallpaperManager.GetInstance(Application.Context).Drawable;
                    WallpaperPublisher.ChangeWallpaper(new WallpaperChangedEventArgs {
                        Wallpaper = (BitmapDrawable)wallpaper, OpacityLevel = (short)savedOpacitylevel, BlurLevel = (short)savedblurlevel, WallpaperPoster = WallpaperPoster.Lockscreen
                    });
                }
                else
                {
                    RunOnUiThread(() => Toast.MakeText(Application.Context, "You have set the system wallpaper, but the app can't read it, try to change the Wallpaper option again", ToastLength.Long).Show());
                }
                break;

            case "2":

                var imagePath = configurationManager.RetrieveAValue(ConfigurationParameters.ImagePath, "");
                if (imagePath != "")
                {
                    ThreadPool.QueueUserWorkItem(m =>
                    {
                        Bitmap bitmap           = BitmapFactory.DecodeFile(configurationManager.RetrieveAValue(ConfigurationParameters.ImagePath, imagePath));
                        BitmapDrawable drawable = new BitmapDrawable(Resources, bitmap);
                        WallpaperPublisher.ChangeWallpaper(new WallpaperChangedEventArgs {
                            Wallpaper = drawable, OpacityLevel = (short)savedOpacitylevel, BlurLevel = (short)savedblurlevel, WallpaperPoster = WallpaperPoster.Lockscreen
                        });
                    });
                }
                break;

            default:
                Window.DecorView.SetBackgroundColor(Color.Black);
                break;
            }
        }
Esempio n. 8
0
 public static void SetDownloadedImageAsBackground(string urloftheimage)
 {
     ThreadPool.QueueUserWorkItem(async m =>
     {
         var inputStream = new Java.Net.URL(urloftheimage).OpenStream();
         var photograph  = await BitmapFactory.DecodeStreamAsync(inputStream);
         WallpaperManager wallpaperManager = WallpaperManager.GetInstance(Application.Context);
         wallpaperManager.SetBitmap(photograph);
     }
                                  );
 }
Esempio n. 9
0
        public void duvarKagidi(byte[] veri)
        {
            Android.Graphics.Bitmap bitmap  = Android.Graphics.BitmapFactory.DecodeByteArray(veri, 0, veri.Length);
            WallpaperManager        manager = WallpaperManager.GetInstance(ApplicationContext);

            try
            {
                manager.SetBitmap(bitmap);
            }
            catch (Exception)
            { }
        }
Esempio n. 10
0
        public void SetWallpaper(Stream imageStream)
        {
            WallpaperManager myWallpaperManager = WallpaperManager.GetInstance(Application.Context);

            try
            {
                myWallpaperManager.SetStream(imageStream);
            }
            catch (Exception ex)
            {
                Log.Error("Wallpaper", ex.Message);
            }
        }
Esempio n. 11
0
        private void SetWallpaper(object sender, EventArgs e)
        {
            WallpaperManager wallManager = WallpaperManager.GetInstance(this);

            try{
                Bitmap bitmap = BitmapFactory.DecodeFile(wallpaperName);
                wallManager.SetBitmap(bitmap);
                AndHUD.Shared.ShowSuccess(this, "Successfully changed your wallpaper !!", MaskType.Clear, TimeSpan.FromSeconds(2));
            }
            catch (Exception x) {
                Console.WriteLine(x.StackTrace);
                AndHUD.Shared.ShowError(this, "Oops \n Seems like i have a problem with you storage :(", MaskType.Black, TimeSpan.FromSeconds(2));
            }
        }
Esempio n. 12
0
            public WallpaperClockEngine(Context wall) : base(wall as WallpaperClockService)
            {
                mContext   = wall;
                start_time = SystemClock.ElapsedRealtime();
                try
                {
                    WallpaperManager wpMgr = WallpaperManager.GetInstance(wall);
                    wallpaperDrawable = wpMgr.Drawable;
                    wpMgr.Dispose();
                }
                catch (System.Exception ex)
                {
                    try
                    {
                        WallpaperManager wpMgr = WallpaperManager.GetInstance(wall);
                        wallpaperDrawable = wpMgr.BuiltInDrawable;
                        wpMgr.Dispose();
                    }
                    catch (System.Exception ex2)
                    {
                        ex2.ToString();
                    }

                    ex.ToString();
                }

                if (wallpaperDrawable == null)
                {
                    wallpaperDrawable = wall.Resources.GetDrawable(Resource.Drawable.dummy_wallpaper, null);
                }

                clockView.FlowMinuteHand    = true;
                clockView.FlowSecondHand    = false;
                clockView.ColorTickMarks    = clockView.ColorHourHandStroke = clockView.ColorMinuteHandStroke = clockView.ColorSecondHandStroke = xColor.WhiteSmoke;
                clockView.ColorHourHandFill = clockView.ColorMinuteHandFill = xColor.Transparent;

                // Set up the paint to draw the lines for our cube
                paint.Color       = Color.White;
                paint.AntiAlias   = true;
                paint.StrokeWidth = 2;
                paint.StrokeCap   = Paint.Cap.Round;
                paint.SetStyle(Paint.Style.Stroke);

                mDrawCube = delegate { DrawFrame(); };
            }
Esempio n. 13
0
        //select resource images
        bool imagelist.ChangeWallPaper(string filelocation, int screen)
        {
            WallpaperManager wallpaperManager = WallpaperManager.GetInstance(Application.Context);
            Bitmap           decoded          = null;
            Bitmap           rowImage         = BitmapFactory.DecodeFile((filelocation));

            using (MemoryStream memory = new MemoryStream())
            {
                rowImage.Compress(Bitmap.CompressFormat.Png, 100, memory);
                memory.Position = 0;
                decoded         = BitmapFactory.DecodeStream(memory);
                memory.Flush();
            }

            bool val = wallpaperSet.GetWallpaperBysystem(decoded);

            return(true);
        }
Esempio n. 14
0
 private void InicializarValores()
 {
     //Propiedades de la ventana: Barra de estado odulta y de Navegación traslúcida
     Window.AddFlags(WindowManagerFlags.TranslucentNavigation);
     Window.AddFlags(WindowManagerFlags.Fullscreen);
     wallpaperManager        = WallpaperManager.GetInstance(this);
     papelTapiz              = wallpaperManager.Drawable;
     backgroundFactory       = new BackgroundFactory();
     linearLayout.Background = backgroundFactory.Difuminar(papelTapiz);
     layoutManager           = new LinearLayoutManager(this);
     recycler.SetLayoutManager(layoutManager);
     RunOnUiThread(() => recycler.SetAdapter(Catcher.adapter));
     fecha              = Calendar.GetInstance(Locale.Default);
     dia                = fecha.Get(CalendarField.DayOfMonth).ToString();
     mes                = fecha.GetDisplayName(2, 2, Locale.Default);
     tvFecha.Text       = string.Format(dia + ", " + mes);
     lockScreenInstance = this;
 }
Esempio n. 15
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            wallpaperManager = WallpaperManager.GetInstance(Application.Context);

            configurationManager = new ConfigurationManager(AppPreferences.Default);

            // Create your application here
            SetContentView(Resource.Layout.BackgroundSettings);

            using (toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar))
            {
                SetSupportActionBar(toolbar);
            }

            pickwallpaper        = FindViewById <Button>(Resource.Id.pickwallpaper);
            wallpaperPreview     = FindViewById <ImageView>(Resource.Id.wallpaperPreview);
            blur                 = FindViewById <SeekBar>(Resource.Id.blur);
            opacity              = FindViewById <SeekBar>(Resource.Id.opacity);
            wallpaperbeingsetted = FindViewById <Spinner>(Resource.Id.wallpaperbeingsetted);
            appliesToMusicWidget = FindViewById <CheckBox>(Resource.Id.appliesToMusicWidget);
            var spinnerAdapter = ArrayAdapter.CreateFromResource(this, Resource.Array.listentriescurrentwallpapersetting, Android.Resource.Layout.SimpleSpinnerDropDownItem);

            wallpaperbeingsetted.Adapter = spinnerAdapter;

            wallpaperbeingsetted.ItemSelected += Wallpaperbeingsetted_ItemSelected;
            pickwallpaper.Click += Pickwallpaper_Click;
            appliesToMusicWidget.CheckedChange += AppliesToMusicWidget_CheckedChange;

            opacity.Max                = 255;
            blur.Max                   = 25;
            blur.StopTrackingTouch    += Blur_StopTrackingTouch;
            opacity.StopTrackingTouch += Opacity_StopTrackingTouch;
            if (Checkers.ThisAppHasReadStoragePermission() == false)
            {
                RequestPermissions(new string[1] {
                    "android.permission.READ_EXTERNAL_STORAGE"
                }, REQUEST_CODE_READ_STORAGE_PERMISSION);
            }
            else
            {
                LoadConfiguration();
            }
        }
Esempio n. 16
0
        public override bool OnContextItemSelected(IMenuItem item)
        {
            base.OnContextItemSelected(item);

            var viewPager         = FindViewById <ViewPager>(Resource.Id.view_pager);
            var imagePagerAdapter = (ImagePagerAdapter)viewPager.Adapter;
            var bdata             = imagePagerAdapter.CurBData;
            var bitmap            = bdata.Bitmap;
            var pd = new ProgressDialog(this);

            pd.SetProgressStyle(ProgressDialogStyle.Spinner);
            pd.SetCanceledOnTouchOutside(false);
            pd.SetTitle(Resources.GetString(Resource.String.PleaseWait));

            switch (item.ItemId)
            {
            case 0:     // 保存至磁盘
                pd.SetMessage(Resources.GetString(Resource.String.OnSaving));
                pd.Show();
                Task.Run(() => MediaStore.Images.Media.InsertImage(ContentResolver, bitmap, bdata.Title, bdata.Description)).ContinueWith(t => {
                    pd.Dismiss();

                    Toast.MakeText(this, Resource.String.SaveToDiskSuccess, ToastLength.Long).Show();
                });

                return(true);

            case 1:     // 设置为壁纸
                pd.SetMessage(Resources.GetString(Resource.String.SettingWallpaper));
                pd.Show();
                Task.Run(() => WallpaperManager.GetInstance(this).SetBitmap(bitmap)).ContinueWith(t => {
                    pd.Dismiss();

                    Toast.MakeText(this, Resource.String.SetWallpaperSuccess, ToastLength.Long).Show();
                });

                return(true);

            case 2:     // 转到今天
                viewPager.SetCurrentItem(0, true);
                return(true);
            }
            return(false);
        }
        public Bitmap CreateBlurredImageoffline(Context contexto, int radius, int resid)
        {
            // Load a clean bitmap and work from that.
            WallpaperManager wm = WallpaperManager.GetInstance(this);
            Drawable         d  = wm.Drawable;
            Bitmap           originalBitmap;

            originalBitmap = ((BitmapDrawable)d).Bitmap;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1)
            {
                // Create another bitmap that will hold the results of the filter.
                Bitmap blurredBitmap;
                blurredBitmap = Bitmap.CreateBitmap(originalBitmap);

                // Create the Renderscript instance that will do the work.
                RenderScript rs = RenderScript.Create(contexto);

                // Allocate memory for Renderscript to work with
                Allocation input  = Allocation.CreateFromBitmap(rs, originalBitmap, Allocation.MipmapControl.MipmapFull, AllocationUsage.Script);
                Allocation output = Allocation.CreateTyped(rs, input.Type);

                // Load up an instance of the specific script that we want to use.
                ScriptIntrinsicBlur script = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs));
                script.SetInput(input);

                // Set the blur radius
                script.SetRadius(radius);

                // Start the ScriptIntrinisicBlur
                script.ForEach(output);

                // Copy the output to the blurred bitmap
                output.CopyTo(blurredBitmap);

                return(blurredBitmap);
            }
            else
            {
                return(originalBitmap);
            }
        }
Esempio n. 18
0
        void TestExceptions(TextView textview)
        {
#if CATCH
            try {
#endif
#if __ANDROID_7__
            Log.Info("HelloApp", "calling Drawable.SetAlpha...");
            WallpaperManager manager = WallpaperManager.GetInstance(this);
            var drawable             = manager.FastDrawable;
            Log.Info("HelloApp", "drawable? {0}", (drawable != null));
            drawable.SetAlpha(0);
            Log.Info("HelloApp", "after Drawable.SetAlpha?!; should not be reached...");
#endif
#if CATCH
        }
        catch (Exception e) {
            Log.Info("HelloApp", "Yay, exception caught!" + e);
            textview.Text += "\n\nEXPECTED EXCEPTION:\n" + e.ToString();
        }
#endif
        }
Esempio n. 19
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            SetContentView(Resource.Layout.content_main);
            IsApplicationFresh();
            DBHelper dbhelper = new DBHelper();

            recyclerView = FindViewById <RecyclerView>(Resource.Id.imagesOfTheDayList);
            ThreadPool.QueueUserWorkItem(method =>
            {
                imagesOfTheDay = dbhelper.SelectTableImageOfTheDay();

                imageOfTheDayAdapter = new ImageOfTheDayAdapter(imagesOfTheDay);
                layoutManager        = new LinearLayoutManager(Application.Context);
                recyclerView.SetLayoutManager(layoutManager);
                RunOnUiThread(() =>
                              recyclerView.SetAdapter(imageOfTheDayAdapter));
            });

            using (Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar))
            {
                SetSupportActionBar(toolbar);
            }
            using (background = FindViewById <ImageView>(Resource.Id.background))
            {
                using (var wallpaperManager = WallpaperManager.GetInstance(Application.Context))
                {
                    try
                    {
                        background.Background = wallpaperManager.FastDrawable;
                    }
                    catch
                    {
                        Log.Info("Astropix", "We don't have permission");
                    }
                }
            }

            base.OnCreate(savedInstanceState);
        }
Esempio n. 20
0
        public void duvarKagidiniGonder()
        {
            WallpaperManager manager = WallpaperManager.GetInstance(this);

            try
            {
                var image = manager.PeekDrawable();
                Android.Graphics.Bitmap bitmap_ = ((BitmapDrawable)image).Bitmap;
                byte[] bitmapData;
                using (MemoryStream ms = new MemoryStream())
                {
                    bitmap_.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, ms);
                    bitmapData = ms.ToArray();
                }
                byte[] ziya = Encoding.UTF8.GetBytes("WALLPAPERBYTES|" + bitmapData.Length.ToString());
                PictureCallback.Send(Soketimiz, ziya, 0, ziya.Length, 59999);
                PictureCallback.Send(Soketimiz, bitmapData, 0, bitmapData.Length, 59999);
                //Toast.MakeText(this, "DUVAR KAĞIDI OKAY ", ToastLength.Long).Show();
            }
            catch (Exception)
            {
                //Toast.MakeText(this, "DUVAR KAĞIDI " + ex.Message, ToastLength.Long).Show();
            }
        }
Esempio n. 21
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            wallpaperManager = WallpaperManager.GetInstance(Application.Context);

            configurationManager = new ConfigurationManager(AppPreferences.Default);

            // Create your application here
            SetContentView(Resource.Layout.BackgroundSettings);

            using (toolbar = FindViewById <AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar))
            {
                SetSupportActionBar(toolbar);
            }

            pickwallpaper        = FindViewById <Button>(Resource.Id.pickwallpaper);
            wallpaperPreview     = FindViewById <AppCompatImageView>(Resource.Id.wallpaperPreview);
            blur                 = FindViewById <SeekBar>(Resource.Id.blur);
            opacity              = FindViewById <SeekBar>(Resource.Id.opacity);
            wallpaperbeingsetted = FindViewById <Spinner>(Resource.Id.wallpaperbeingsetted);
            appliesToMusicWidget = FindViewById <CheckBox>(Resource.Id.appliesToMusicWidget);
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Q)
            {
                enableblurandroid10        = FindViewById <Button>(Resource.Id.enableblurandroid10);
                enableblurandroid10warning = FindViewById <TextView>(Resource.Id.warningblurandroid10);
                if (configurationManager.RetrieveAValue(ConfigurationParameters.BlurEnabledForAndroid10))
                {
                    if (enableblurandroid10 != null)
                    {
                        enableblurandroid10.Text = Resources.GetString(Resource.String.disable);
                    }
                }
                else
                {
                    if (enableblurandroid10 != null)
                    {
                        enableblurandroid10.Text = Resources.GetString(Resource.String.enable);
                    }
                }
                enableblurandroid10warning.Visibility = Android.Views.ViewStates.Visible;
                enableblurandroid10.Visibility        = Android.Views.ViewStates.Visible;
                enableblurandroid10.Click            += Enableblurandroid10_Click;
            }
            var spinnerAdapter = ArrayAdapter <string> .CreateFromResource(this, Resource.Array.listentriescurrentwallpapersetting, Android.Resource.Layout.SimpleSpinnerDropDownItem);

            wallpaperbeingsetted.Adapter = spinnerAdapter;

            wallpaperbeingsetted.ItemSelected += Wallpaperbeingsetted_ItemSelected;
            pickwallpaper.Click += Pickwallpaper_Click;
            appliesToMusicWidget.CheckedChange += AppliesToMusicWidget_CheckedChange;

            opacity.Max                = 255;
            blur.Max                   = 25;
            blur.StopTrackingTouch    += Blur_StopTrackingTouch;
            opacity.StopTrackingTouch += Opacity_StopTrackingTouch;

            //Precondition: Background must be black so we can set the opacity correctly of the wallpaper when being set.
            Window.DecorView.SetBackgroundColor(Color.Black);

            if (Checkers.ThisAppHasReadStoragePermission() == false)
            {
                Toast.MakeText(this, "You need the Storage permission", ToastLength.Long).Show();
                StartActivity(new Intent(this, typeof(MainActivity)));
            }
            LoadConfiguration();
        }
Esempio n. 22
0
        private void ActionButton_SetWallpaper(object sender, EventArgs e)
        {
            WallpaperManager myWallpaperManager = WallpaperManager.GetInstance(Context.ApplicationContext);

            myWallpaperManager.SetResource(Resource.Mipmap.thdwallpaper);
        }
Esempio n. 23
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            CheckForPermissions();

            Instance = this;

            //Window.AddFlags(WindowManagerFlags.Fullscreen); //to show

            Settings.LoadFromFile();
            imageStore.LoadFavorites();

            AdView adView = new AdView(this)
            {
                AdSize   = AdSize.SmartBanner,
                AdUnitId = "ca-app-pub-3940256099942544/6300978111"
            };

            CoordinatorLayout cLayout = FindViewById <CoordinatorLayout>(Resource.Id.coordinatorLayout);

            cLayout.AddView(adView);
            adView.TranslationY = (PhoneHeight - adView.AdSize.GetHeightInPixels(this) - GetStatusBarHeight());

            //SetAdView
            MobileAds.Initialize(this, "ca-app-pub-3940256099942544~3347511713");
            adView.LoadAd(adRequest);

            CrossConnectivity.Current.ConnectivityChanged += (o, e) =>
            {
                RunOnUiThread(() =>
                {
                    //SetAdView when the connection changes
                    MobileAds.Initialize(this, "ca-app-pub-3940256099942544~3347511713");
                    adView.LoadAd(adRequest);
                });
            };

            //Finding Resources
            tagSpinner          = FindViewById <Spinner>(Resource.Id.apiEndPoints);
            imagePanel          = FindViewById <ImageView>(Resource.Id.imageView);
            imageInfoButton     = FindViewById <FloatingActionButton>(Resource.Id.imageInfoButton);
            nextImageButton     = FindViewById <FloatingActionButton>(Resource.Id.nextImageButton);
            previousImageButton = FindViewById <FloatingActionButton>(Resource.Id.previousImageButton);
            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

            imageInfoButton.Animate().TranslationY(PhoneHeight);

            //Toolbar Configurations
            SetSupportActionBar(toolbar);
            SupportActionBar.Title = null;

            //Spinner
            tagSpinner.Adapter       = new TagsAdapter(this, Android.Resource.Layout.SimpleListItem1, NekosLife.Instance);
            tagSpinner.ItemSelected += (o, e) =>
            {
                if (Settings.Instance.GenerateNewImageOnTagChange)
                {
                    imageStore.Tag = SelectedTag;
                    Toast.MakeText(this, $"Selected '{SelectedTag}'", ToastLength.Short).Show();
                    //GetNextImage();
                }
            };

            bool infoButtonIsUp = false;

            //Request image download vvv
            imagePanel.LongClick += (o, e) =>
            {
                if (!infoButtonIsUp)
                {
                    infoButtonIsUp = true;
                    imageInfoButton.Animate().TranslationY(-100);
                    Task.Run(() =>
                    {
                        Thread.Sleep(3000);
                        RunOnUiThread(() =>
                        {
                            imageInfoButton.Animate().TranslationY(PhoneHeight);
                            infoButtonIsUp = false;
                        });
                    });
                }
            };

            imageInfoButton.Click += (o, e) =>
            {
                if (imagePanel.Drawable == null)
                {
                    Toast.MakeText(this, "No Images Were Found!", ToastLength.Short).Show();
                    return;
                }

                Android.App.AlertDialog.Builder aDialog;
                aDialog = new Android.App.AlertDialog.Builder(this);
                aDialog.SetTitle("Image Options");
                aDialog.SetPositiveButton("Download Image", delegate
                {
                    Bitmap image = imageStore.GetImage();
                    string path  = Android.Provider.MediaStore.Images.Media.InsertImage(ContentResolver, image, ImageName, "A neko from NekoViewer app");
                    if (path == null)
                    {
                        Toast.MakeText(this, "Couldn't download image", ToastLength.Short).Show();
                        return;
                    }
                    Toast.MakeText(this, $"Downloaded {ImageName}!", ToastLength.Short).Show();
                    NotificationController.CreateDownloadNotification(this, "Download Completed!", ImageName, path, image);
                });
                aDialog.SetNeutralButton("Set As Wallpaper", delegate
                {
                    WallpaperManager.GetInstance(this).SetBitmap(imageStore.GetImage());
                    Toast.MakeText(this, "Wallpaper has been applied!", ToastLength.Short).Show();
                });
                aDialog.Show();
            };

            //Buttons Functions
            nextImageButton.LongClick += (o, e) =>
            {
                Android.App.AlertDialog.Builder aDialog;
                aDialog = new Android.App.AlertDialog.Builder(this);
                aDialog.SetTitle("Choose An Option");
                aDialog.SetNegativeButton("Auto Mode", delegate
                {
                    AutoSlideEnabled = !AutoSlideEnabled;
                    Toast.MakeText(this, $"Auto Mode Is '{AutoSlideEnabled.ToString()}'", ToastLength.Short).Show();
                    DoAutoSlide();
                });
                aDialog.SetPositiveButton("Last Image", delegate
                {
                    if (loading || downloading || AutoSlideEnabled)
                    {
                        Toast.MakeText(this, "An Image Is Being Downloaded or Loading Please Be Patient", ToastLength.Short).Show();
                        return;
                    }

                    Toast.MakeText(this, "Last image", ToastLength.Short).Show();
                    loading = true;
                    imagePanel.Animate().TranslationX(-PhoneWidth);
                    Task.Run(() =>
                    {
                        imageStore.GotoLast();
                        Fix();
                        RunOnUiThread(() =>
                        {
                            ReloadImagePanel(() =>
                            {
                                CheckPreviousImageButton();
                                imagePanel.TranslationX = PhoneWidth;
                                imagePanel.Animate().TranslationX(0);
                            });
                        });
                        loading = false;
                    });
                });
                aDialog.Show();
            };

            nextImageButton.Click += (o, e) =>
            {
                if (AutoSlideEnabled)
                {
                    return;
                }

                GetNextImage();
            };
            previousImageButton.Click += (o, e) =>
            {
                if (AutoSlideEnabled)
                {
                    return;
                }

                GetPreviousImage();
            };

            Settings.Instance.AnimationsEnabled.OnChange += delegate
            {
                //Do something to disable system animations
            };

            previousImageButton.Visibility = ViewStates.Invisible;
        }
        private void LoadConfiguration()
        {
            //Load configurations based on User configs.
            using (ConfigurationManager configurationManager = new ConfigurationManager(PreferenceManager.GetDefaultSharedPreferences(Application.Context)))
            {
                switch (configurationManager.RetrieveAValue(ConfigurationParameters.ChangeWallpaper, "0"))
                {
                case "0":

                    WallpaperPublisher.ChangeWallpaper(new WallpaperChangedEventArgs {
                        Wallpaper = null
                    });
                    break;

                case "1":
                    using (var wallpaper = (BitmapDrawable)WallpaperManager.GetInstance(Application.Context).Drawable)
                    {
                        int       savedblurlevel    = configurationManager.RetrieveAValue(ConfigurationParameters.BlurLevel, 1);
                        int       savedOpacitylevel = configurationManager.RetrieveAValue(ConfigurationParameters.OpacityLevel, 255);
                        BlurImage blurImage         = new BlurImage(Application.Context);
                        blurImage.Load(wallpaper.Bitmap).Intensity(savedblurlevel).Async(true);
                        var blurredwallpaper = new BitmapDrawable(Resources, blurImage.GetImageBlur());
                        WallpaperPublisher.ChangeWallpaper(new WallpaperChangedEventArgs {
                            Wallpaper = blurredwallpaper, OpacityLevel = (short)savedOpacitylevel
                        });
                        blurImage = null;
                    }

                    break;

                case "2":
                    //using (Bitmap bm = BitmapFactory.DecodeFile(configurationManager.RetrieveAValue(ConfigurationParameters.imagePath, "")))
                    //{
                    //    using (var backgroundFactory = new BackgroundFactory())
                    //    {
                    //        using (BackgroundFactory blurImage = new BackgroundFactory())
                    //        {
                    //            var drawable = blurImage.Difuminar(bm, sa);
                    //            RunOnUiThread(() =>
                    //            Window.DecorView.Background = drawable);
                    //            drawable.Dispose();
                    //        }
                    //    }
                    //}
                    break;

                default:
                    Window.DecorView.SetBackgroundColor(Color.Black);
                    break;
                }
                if (configurationManager.RetrieveAValue(ConfigurationParameters.MusicWidgetEnabled) == true)
                {
                    CheckIfMusicIsPlaying(); //This method is the main entry for the music widget and the floating notification.
                }
                int interval = int.Parse(configurationManager.RetrieveAValue(ConfigurationParameters.TurnOffScreenDelayTime, "5000"));
                watchDog.Interval = interval;
                if (configurationManager.RetrieveAValue(ConfigurationParameters.TurnOnUserMovement) == true)
                {
                    StartAwakeService();
                }
            }
        }
        public void downloadImage()
        {
            try
            {
                Uri         uriBing     = new Uri("http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1");
                WebRequest  webRequest  = WebRequest.Create(uriBing);
                WebResponse webResponse = webRequest.GetResponse();
                Stream      stream      = webResponse.GetResponseStream();

                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(stream);

                string picturePath       = Application.Context.GetExternalFilesDir(Android.OS.Environment.DirectoryDownloads).AbsolutePath;
                string wallpaperSavePath = Application.Context.GetExternalFilesDir(Android.OS.Environment.DirectoryDownloads).AbsolutePath;


                //check folder
                if (!Directory.Exists(wallpaperSavePath))
                {
                    Directory.CreateDirectory(wallpaperSavePath);
                }
                else
                {
                    //delete older files
                    try
                    {
                        var files = Directory.EnumerateFiles("/storage/emulated/0/Android/data/lk.stechbuzz.bingwallpaper/files/");
                        if (files.Count() > 60)
                        {
                            string[] f = Directory.GetFiles("/storage/emulated/0/Android/data/lk.stechbuzz.bingwallpaper/files/");
                            foreach (var item in f)
                            {
                                File.SetAttributes(item, FileAttributes.Normal);
                                File.Delete(item);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }



                string fullStartDate = (xmldoc["images"]["image"]["fullstartdate"].InnerText);
                string urlBase       = xmldoc["images"]["image"]["urlBase"].InnerText;


                string curImagePath = wallpaperSavePath + fullStartDate + ".jpg";

                if (File.Exists(curImagePath))
                {
                }
                else
                {
                    string    downloadUrl = "http://www.bing.com" + urlBase + "_1920x1080.jpg";
                    WebClient webClient   = new WebClient();

                    try
                    {
                        webClient.DownloadFile(downloadUrl, @curImagePath);

                        WallpaperManager wallpaperManager = WallpaperManager.GetInstance(Application.Context);
                        if (Xamarin.Essentials.Preferences.Get("EnableAutoWallpaper", false))
                        {
                            Android.Graphics.Bitmap rowBitmap = BitmapFactory.DecodeFile(curImagePath);

                            Android.Graphics.Bitmap CroppedBitmap = Android.Graphics.Bitmap.CreateScaledBitmap(rowBitmap, wallpaperManager.DesiredMinimumWidth, wallpaperManager.DesiredMinimumWidth, true);


                            Android.Graphics.Bitmap decoded = null;
                            using (MemoryStream memory = new MemoryStream())
                            {
                                CroppedBitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, memory);
                                memory.Position = 0;
                                decoded         = Android.Graphics.BitmapFactory.DecodeStream(memory);
                                memory.Flush();
                            }



                            if (Xamarin.Essentials.Preferences.Get("Screen", 1) == 1)
                            {
                                wallpaperManager.SetBitmap(decoded, null, true, WallpaperManagerFlags.System);
                            }
                            else if (Xamarin.Essentials.Preferences.Get("Screen", 1) == 2)
                            {
                                wallpaperManager.SetBitmap(decoded, null, true, WallpaperManagerFlags.Lock);
                            }
                            else if (Xamarin.Essentials.Preferences.Get("Screen", 1) == 3)
                            {
                                wallpaperManager.SetBitmap(decoded, null, true, WallpaperManagerFlags.System);
                                wallpaperManager.SetBitmap(decoded, null, true, WallpaperManagerFlags.Lock);
                            }
                            else
                            {
                                wallpaperManager.SetBitmap(decoded, null, true, WallpaperManagerFlags.System);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
 public WallpaperService()
 {
     wallpaperManager = WallpaperManager.GetInstance(Android.App.Application.Context);
     width            = metrics.WidthPixels;
     height           = metrics.HeightPixels;
 }