protected async override Task SetTargetAsync(SelfDisposingBitmapDrawable image, bool animated) { ThrowIfCancellationRequested(); var ffDrawable = image as FFBitmapDrawable; if (ffDrawable != null) { if (ffDrawable.IsAnimationRunning) { await Task.Delay(ffDrawable.FadeDuration + 25); } if (animated) { SelfDisposingBitmapDrawable placeholderDrawable = null; if (_loadingPlaceholderWeakReference != null && _loadingPlaceholderWeakReference.TryGetTarget(out placeholderDrawable) && placeholderDrawable != null) { int fadeDuration = Parameters.FadeAnimationDuration.HasValue ? Parameters.FadeAnimationDuration.Value : Configuration.FadeAnimationDuration; placeholderDrawable?.SetIsRetained(true); ffDrawable?.SetPlaceholder(placeholderDrawable, fadeDuration); placeholderDrawable?.SetIsRetained(false); } } } await MainThreadDispatcher.PostAsync(() => { ThrowIfCancellationRequested(); PlatformTarget.Set(this, image, animated); }).ConfigureAwait(false); }
protected async override Task SetTargetAsync(SelfDisposingBitmapDrawable image, bool animated) { if (Target == null) { return; } ThrowIfCancellationRequested(); var ffDrawable = image as FFBitmapDrawable; if (ffDrawable != null) { if (ffDrawable.IsAnimationRunning) { var mut = new FFBitmapDrawable(Context.Resources, ffDrawable.Bitmap, ffDrawable); ffDrawable = mut as FFBitmapDrawable; image = ffDrawable; // old hacky workaround //await Task.Delay(ffDrawable.FadeDuration + 50).ConfigureAwait(false); } if (animated) { SelfDisposingBitmapDrawable placeholderDrawable = null; PlaceholderWeakReference?.TryGetTarget(out placeholderDrawable); if (placeholderDrawable == null) { // Enable fade animation when no placeholder is set and the previous image is not null var imageView = PlatformTarget.Control as ImageViewAsync; placeholderDrawable = imageView?.Drawable as SelfDisposingBitmapDrawable; } if (placeholderDrawable.IsValidAndHasValidBitmap()) { int fadeDuration = Parameters.FadeAnimationDuration.HasValue ? Parameters.FadeAnimationDuration.Value : Configuration.FadeAnimationDuration; placeholderDrawable?.SetIsRetained(true); ffDrawable?.SetPlaceholder(placeholderDrawable, fadeDuration); placeholderDrawable?.SetIsRetained(false); } } else { ffDrawable?.SetPlaceholder(null, 0); } } await MainThreadDispatcher.PostAsync(() => { ThrowIfCancellationRequested(); PlatformTarget.Set(this, image, animated); }).ConfigureAwait(false); }
private void AddInBitmapOptions(BitmapFactory.Options options) { // inBitmap only works with mutable bitmaps so force the decoder to // return mutable bitmaps. options.InMutable = true; // Try and find a bitmap to use for inBitmap SelfDisposingBitmapDrawable bitmapDrawable = null; try { bitmapDrawable = ImageCache.Instance.GetBitmapDrawableFromReusableSet(options); var bitmap = bitmapDrawable == null ? null : bitmapDrawable.Bitmap; if (bitmap != null && bitmap.Handle != IntPtr.Zero && !bitmap.IsRecycled) { options.InBitmap = bitmapDrawable.Bitmap; } } finally { if (bitmapDrawable != null) { bitmapDrawable.SetIsRetained(false); } } }
protected async override Task SetTargetAsync(SelfDisposingBitmapDrawable image, bool animated) { ThrowIfCancellationRequested(); var ffDrawable = image as FFBitmapDrawable; if (ffDrawable != null) { if (ffDrawable.IsAnimationRunning) { var mut = new FFBitmapDrawable(Context.Resources, ffDrawable.Bitmap, ffDrawable); ffDrawable = mut as FFBitmapDrawable; image = ffDrawable; // old hacky workaround //await Task.Delay(ffDrawable.FadeDuration + 50).ConfigureAwait(false); } if (animated) { SelfDisposingBitmapDrawable placeholderDrawable = null; if (PlaceholderWeakReference != null && PlaceholderWeakReference.TryGetTarget(out placeholderDrawable) && placeholderDrawable != null) { int fadeDuration = Parameters.FadeAnimationDuration.HasValue ? Parameters.FadeAnimationDuration.Value : Configuration.FadeAnimationDuration; placeholderDrawable?.SetIsRetained(true); ffDrawable?.SetPlaceholder(placeholderDrawable, fadeDuration); placeholderDrawable?.SetIsRetained(false); } } else { ffDrawable?.SetPlaceholder(null, 0); } } await MainThreadDispatcher.PostAsync(() => { ThrowIfCancellationRequested(); PlatformTarget.Set(this, image, animated); }).ConfigureAwait(false); }
protected override void AfterLoading(SelfDisposingBitmapDrawable image, bool fromMemoryCache) { base.AfterLoading(image, fromMemoryCache); image?.SetIsRetained(false); }
protected override void BeforeLoading(SelfDisposingBitmapDrawable image, bool fromMemoryCache) { base.BeforeLoading(image, fromMemoryCache); image?.SetIsRetained(true); }
protected async override Task SetTargetAsync(SelfDisposingBitmapDrawable image, bool animated) { if (Target == null) { return; } ThrowIfCancellationRequested(); if (image is FFBitmapDrawable ffDrawable) { if (ffDrawable.IsAnimationRunning) { var mut = new FFBitmapDrawable(Context.Resources, ffDrawable.Bitmap, ffDrawable); ffDrawable = mut as FFBitmapDrawable; image = ffDrawable; // old hacky workaround //await Task.Delay(ffDrawable.FadeDuration + 50).ConfigureAwait(false); } if (animated) { SelfDisposingBitmapDrawable placeholderDrawable = null; PlaceholderWeakReference?.TryGetTarget(out placeholderDrawable); if (placeholderDrawable == null) { // Enable fade animation when no placeholder is set and the previous image is not null var imageView = PlatformTarget.Control as ImageViewAsync; placeholderDrawable = imageView?.Drawable as SelfDisposingBitmapDrawable; } var fadeDuration = Parameters.FadeAnimationDuration ?? Configuration.FadeAnimationDuration; if (placeholderDrawable.IsValidAndHasValidBitmap()) { placeholderDrawable?.SetIsRetained(true); ffDrawable?.SetPlaceholder(placeholderDrawable, fadeDuration); placeholderDrawable?.SetIsRetained(false); } else if (ffDrawable.IsValidAndHasValidBitmap()) { var width = ffDrawable.Bitmap.Width; var height = ffDrawable.Bitmap.Height; var bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); using (var canvas = new Canvas(bitmap)) using (var paint = new Paint() { Color = _placeholderHelperColor }) { canvas.DrawRect(0, 0, width, height, paint); } ffDrawable?.SetPlaceholder(new SelfDisposingBitmapDrawable(Context.Resources, bitmap), fadeDuration); } } else { ffDrawable?.SetPlaceholder(null, 0); } } await MainThreadDispatcher.PostAsync(() => { ThrowIfCancellationRequested(); PlatformTarget.Set(this, image, animated); }).ConfigureAwait(false); }