diff options
author | Rui Marinho <me@ruimarinho.net> | 2017-04-06 14:19:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-06 14:19:52 +0100 |
commit | 425fafb05723a299a5eaa0f6d801f87bdf7141fa (patch) | |
tree | a9e38aa0a0252e6a6d2da6990303d82f2163a5a9 /Xamarin.Forms.Platform.Android/Extensions | |
parent | 829a4bda76166ddffce5a0e84538183b9527a1bd (diff) | |
download | xamarin-forms-425fafb05723a299a5eaa0f6d801f87bdf7141fa.tar.gz xamarin-forms-425fafb05723a299a5eaa0f6d801f87bdf7141fa.tar.bz2 xamarin-forms-425fafb05723a299a5eaa0f6d801f87bdf7141fa.zip |
Android fastrenderers (#845)
* Obsolete IVisualElementRenderer.ViewGroup in favor of .View
* Fix NRE
* Changing TContainer in PlatformEffect to View
* Fix "View" type
* new VisualElementRenderer
* First attempt at a fast(er) button renderer
* Fast Label Renderer
* Let's try that again. Behold: Label Fast Renderer
* Move FrameRenderer into Fast Renderers
* Fix Disposable on VisualElementRenderer
* Simplify touch and click handlers
* Drop empty if clause
* [Android] Add initial Image fast renderer
* Split accessibility out to a separate helper class; fix tapgesture bug with label
* [Android] Small fixes to VisualElementRenderer
* Move accessiblity stuff to a separate class (which needs a good name)
* Prevent query from looking to parent for fast renderers
* [Android] ImageRenderer refactoring
* Fix elevation/z-index bugs with Button (e.g., 40173)
* Move SetLabeledBy to Accessibilitizer
* Un-break automation IDs for Labels
* Move gesture handling to its own class
* Split gesture and effect management into separate classes
* Remove unneeded packager from LabelRenderer
* LabelRenderer inherits from FormsTextView
* Batch updates to View
* Fix isOnParentRenderer check for non-Android platforms
* [Controls] Update Xamarin.Forms.ControlGallery.iOS.csproj
* [Android,IOS] Small fixes to rebase and use of Internals
* [Android] Ignroe warning for now
* Fast renderers now passing InputTransparent and IsEnabled tests
* Fast and legacy renderers now pass the Enabled and InputTransparent tests
* Change PlatformEffect back, default container to null
* Fix mangled using directives
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Extensions')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Extensions/ImageViewExtensions.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Extensions/ImageViewExtensions.cs b/Xamarin.Forms.Platform.Android/Extensions/ImageViewExtensions.cs new file mode 100644 index 00000000..f60acb7e --- /dev/null +++ b/Xamarin.Forms.Platform.Android/Extensions/ImageViewExtensions.cs @@ -0,0 +1,61 @@ +using System; +using System.Threading.Tasks; +using Android.Graphics; +using Java.IO; +using AImageView = Android.Widget.ImageView; + +namespace Xamarin.Forms.Platform.Android +{ + internal static class ImageViewExtensions + { + public static async void UpdateBitmap(this AImageView imageView, Image newImage, Image previousImage = null) + { + if (Device.IsInvokeRequired) + throw new InvalidOperationException("Image Bitmap must not be updated from background thread"); + + if (previousImage != null && Equals(previousImage.Source, newImage.Source)) + return; + + ((IImageController)newImage).SetIsLoading(true); + + (imageView as IImageRendererController).SkipInvalidate(); + + imageView.SetImageResource(global::Android.Resource.Color.Transparent); + + ImageSource source = newImage.Source; + Bitmap bitmap = null; + IImageSourceHandler handler; + + if (source != null && (handler = Internals.Registrar.Registered.GetHandler<IImageSourceHandler>(source.GetType())) != null) + { + try + { + bitmap = await handler.LoadImageAsync(source, imageView.Context); + } + catch (TaskCanceledException) + { + } + catch (IOException ex) + { + Internals.Log.Warning("Xamarin.Forms.Platform.Android.ImageRenderer", "Error updating bitmap: {0}", ex); + } + } + + if (newImage == null || !Equals(newImage.Source, source)) + { + bitmap?.Dispose(); + return; + } + + if (bitmap == null && source is FileImageSource) + imageView.SetImageResource(ResourceManager.GetDrawableByName(((FileImageSource)source).File)); + else + imageView.SetImageBitmap(bitmap); + + bitmap?.Dispose(); + + ((IImageController)newImage).SetIsLoading(false); + ((IVisualElementController)newImage).NativeSizeChanged(); + } + } +} |