public static async Task LoadUrl(this UIImageView imageView, string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return;
            }
            var progress = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge)
            {
                Center = new PointF(imageView.Bounds.GetMidX(), imageView.Bounds.GetMidY()),
            };

            imageView.AddSubview(progress);


            var t = FileCache.Download(url);

            if (t.IsCompleted)
            {
                imageView.Image = UIImage.FromFile(t.Result);
                progress.RemoveFromSuperview();
                return;
            }
            progress.StartAnimating();
            var image = UIImage.FromFile(await t);

            UIView.Animate(.3,
                           () => imageView.Image = image,
                           () => {
                progress.StopAnimating();
                progress.RemoveFromSuperview();
            });
        }
Beispiel #2
0
 public async Task PreloadImages(float imageWidth)
 {
     if (hasPreloadedImages)
     {
         return;
     }
     hasPreloadedImages = true;
     //Lets precach the countries too
                 #pragma warning disable 4014
     GetCountries();
                 #pragma warning restore 4014
     await Task.Factory.StartNew(() => {
         var imagUrls = products.SelectMany(x => x.ImageUrls.Select(y => Product.ImageForSize(y, imageWidth))).ToList();
         imagUrls.ForEach(async(x) => await FileCache.Download(x));
     });
 }
Beispiel #3
0
                public async Task Update(Product product)
                {
                    NameLabel.Text  = product.Name;
                    SizeLabel.Text  = product.Size.Description;
                    ColorLabel.Text = product.Color.Name;
                    PriceLabel.Text = product.PriceDescription;
                    var imageTask = FileCache.Download(product.ImageForSize(320));

                    if (!imageTask.IsCompleted)
                    {
                        //Put default before doing the web request;
                        ImageView.Image = Image.Value;
                    }
                    var image = await imageTask;

                    ImageView.Image = UIImage.FromFile(image);
                }
        void PrecacheNextImage()
        {
            if (currentIndex + 1 >= images.Length)
            {
                cached = true;
            }
            if (cached)
            {
                return;
            }
            var next  = currentIndex + 1;
            var image = images [next];

            //No need to await the precache to finish
                        #pragma warning disable 4014
            FileCache.Download(Product.ImageForSize(image, Images.ScreenWidth));
                        #pragma warning restore 4014
        }
Beispiel #5
0
        public static async Task <Bitmap> FromUrl(string url)
        {
            Bitmap bmp;

            if (bmpCache.TryGetValue(url, out bmp))
            {
                return(bmp);
            }
            var path = await FileCache.Download(url);

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }
            bmp = await BitmapFactory.DecodeFileAsync(path);

            bmpCache [url] = bmp;
            return(bmp);
        }
Beispiel #6
0
        public async void LoadUrl(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return;
            }
            var t = FileCache.Download(url);

            if (t.IsCompleted)
            {
                Image = UIImage.FromFile(t.Result);
                return;
            }
            progress.StartAnimating();
            var image = UIImage.FromFile(await t);

            UIView.Animate(.3,
                           () => Image = image,
                           () => progress.StopAnimating());
        }