예제 #1
0
        private async Task OnPressedCachedImage(CachedImage cachedImage)
        {
            if (cachedImage is null || !cachedImage.IsEnabled)
            {
                return;
            }

            cachedImage.Transformations.Clear();
            cachedImage.Transformations.Add(pressed);
            cachedImage.ReloadImage();

            await Task.Delay(250);

            ResetHeaderButtonColor(cachedImage);
        }
예제 #2
0
        /// <summary>
        /// Create Image Widget
        /// </summary>
        /// <returns>nothing</returns>
        public static void Image(Grid grid, int px, int py, int sx, int sy, string header, string straspect, JObject data)
        {
            Microsoft.AppCenter.Analytics.Analytics.TrackEvent("Create Image Widget");
            CrossLogger.Current.Debug("Image", "Creating Image Widget");


            try
            {
                Models.Image item = data.ToObject <Models.Image>();
                CrossLogger.Current.Debug("Image", "URL: " + item.Url);

                //Aspect ratio
                Aspect aspect = Aspect.AspectFit;
                switch (straspect.ToLower())
                {
                case "fill":
                    aspect = Aspect.Fill;
                    break;

                case "aspectfill":
                    aspect = Aspect.AspectFill;
                    break;

                case "aspectfit":
                    aspect = Aspect.AspectFit;
                    break;
                }

                var img = new CachedImage()
                {
                    DownsampleToViewSize = false,
                    CacheDuration        = TimeSpan.FromMilliseconds(1000),
                    Aspect              = aspect,
                    RetryCount          = 999,
                    RetryDelay          = 2000,
                    BitmapOptimizations = true,
                    Source              = item.Url
                };
                grid.Children.Add(img, px, px + sx, py, py + sy);

                Label l_header = new Label
                {
                    Text              = header,
                    FontSize          = 20,
                    TextColor         = App.Config.TextColor,
                    BackgroundColor   = Color.Transparent,
                    HorizontalOptions = LayoutOptions.Start,
                    VerticalOptions   = LayoutOptions.Start
                };
                grid.Children.Add(l_header, px, px + sx, py, py + sy);

                //Button must be last to be added to work
                ItemImageButton ImageButton = new ItemImageButton
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    BackgroundColor   = Color.Transparent,
                    Name = header,
                    URL  = item.Url,
                };
                grid.Children.Add(ImageButton, px, px + sx, py, py + sy);
                ImageButton.Clicked += OnImageButtonClicked;

                // Start the refresh time
                if (item.Refresh != string.Empty)
                {
                    int refresh = Convert.ToInt32(item.Refresh);
                    if (refresh > 0)
                    {
                        Device.StartTimer(TimeSpan.FromMilliseconds(refresh), () =>
                        {
                            Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Debug("Image", "Refresh Image: " + item.Url));
                            try
                            {
                                //If not clearing the cache, image does not refresh
                                ImageService.Instance.InvalidateCacheAsync(CacheType.All);
                                img.ReloadImage();
                            }
                            catch (Exception ex)
                            {
                                Device.BeginInvokeOnMainThread(() => CrossLogger.Current.Error("Image", "Failed to refresh Image: " + ex.ToString()));
                            }
                            return(true);
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                CrossLogger.Current.Error("Image", "Image crashed: " + ex.ToString());
                Error(grid, px, py, sx, sy, ex.ToString());
            }
        }
예제 #3
0
 private void ResetHeaderButtonColor(CachedImage cachedImage)
 {
     cachedImage?.Transformations.Clear();
     cachedImage?.Transformations.Add(idle);
     cachedImage?.ReloadImage();
 }
예제 #4
0
 private void ResetHeaderButtonColor(CachedImage cachedImage)
 {
     cachedImage?.Transformations.Clear();
     cachedImage?.Transformations.Add(cachedImage.IsEnabled ? idle : disabled);
     cachedImage?.ReloadImage();
 }