summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.ControlGallery.Android
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-04-25 12:16:25 -0600
committerRui Marinho <me@ruimarinho.net>2017-04-25 19:16:25 +0100
commitcdc405512844671bc3b2c8bd28f583036e5530a2 (patch)
tree881d68b4a26eecbbc77e76b86b3f322cd41b3e3d /Xamarin.Forms.ControlGallery.Android
parent9631ec2d8bbac8b837955af238f322c1023af097 (diff)
downloadxamarin-forms-cdc405512844671bc3b2c8bd28f583036e5530a2.tar.gz
xamarin-forms-cdc405512844671bc3b2c8bd28f583036e5530a2.tar.bz2
xamarin-forms-cdc405512844671bc3b2c8bd28f583036e5530a2.zip
Better error handling for image loading errors on iOS/Android (#849)
* First run at removing async void image update methods Consistent error logging and IsLoading on Android,iOS,UWP Move error logging into image handlers for better messages Add demo of custom ImageRenderer error handling Update docs Make the test smaller so the results don't get pushed offscreen Fix namespace error * Update error handling for fast image renderer * Update 37625 test to use image we control * Add java disposed check to avoid ObjectDisposedException in async operations * Add disposed checks to legacy renderer; null check element before SetIsLoading * Check disposed on GetDesiredSize for fast renderer Use local disposed member where possible for disposed check * Check for disposal after async handlers in iOS * Add disposal checks after async methods in Windows * Reset linker settings on project; reduce redundant casts in ImageViewExtensions
Diffstat (limited to 'Xamarin.Forms.ControlGallery.Android')
-rw-r--r--Xamarin.Forms.ControlGallery.Android/BrokenImageSourceHandler.cs38
-rw-r--r--Xamarin.Forms.ControlGallery.Android/Properties/AssemblyInfo.cs7
-rw-r--r--Xamarin.Forms.ControlGallery.Android/Resources/drawable/invalidimage.jpg1
-rw-r--r--Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj27
-rw-r--r--Xamarin.Forms.ControlGallery.Android/_38989CustomRenderer.cs2
5 files changed, 62 insertions, 13 deletions
diff --git a/Xamarin.Forms.ControlGallery.Android/BrokenImageSourceHandler.cs b/Xamarin.Forms.ControlGallery.Android/BrokenImageSourceHandler.cs
new file mode 100644
index 00000000..390d77c9
--- /dev/null
+++ b/Xamarin.Forms.ControlGallery.Android/BrokenImageSourceHandler.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Android.Content;
+using Android.Graphics;
+using Xamarin.Forms;
+using Xamarin.Forms.ControlGallery.Android;
+using Xamarin.Forms.Controls.Issues;
+using Xamarin.Forms.Platform.Android;
+
+[assembly: ExportRenderer(typeof(_51173Image), typeof(_51173CustomImageRenderer))]
+namespace Xamarin.Forms.ControlGallery.Android
+{
+ public sealed class BrokenImageSourceHandler : IImageSourceHandler
+ {
+ public Task<Bitmap> LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken = default(CancellationToken))
+ {
+ throw new Exception("Fail");
+ }
+ }
+
+ public class _51173CustomImageRenderer : ImageRenderer
+ {
+ protected override async Task TryUpdateBitmap(Image previous = null)
+ {
+ try
+ {
+ await UpdateBitmap(previous).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ await Application.Current.MainPage.DisplayAlert("Image Error 51173", $"The image failed to load, here's why: {ex.Message}", "OK");
+ }
+ }
+ }
+}
+
+
diff --git a/Xamarin.Forms.ControlGallery.Android/Properties/AssemblyInfo.cs b/Xamarin.Forms.ControlGallery.Android/Properties/AssemblyInfo.cs
index dc197baf..82e72528 100644
--- a/Xamarin.Forms.ControlGallery.Android/Properties/AssemblyInfo.cs
+++ b/Xamarin.Forms.ControlGallery.Android/Properties/AssemblyInfo.cs
@@ -2,8 +2,11 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
+using Xamarin.Forms.Controls;
+using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
-
+using Xamarin.Forms.ControlGallery.Android;
+
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
@@ -37,6 +40,8 @@ using Xamarin.Forms;
[assembly: Android.App.MetaData("com.google.android.maps.v2.API_KEY", Value = "AIzaSyAdstcJQswxEjzX5YjLaMcu2aRVEBJw39Y")]
[assembly: Xamarin.Forms.ResolutionGroupName ("XamControl")]
+// Deliberately broken image source and handler so we can test handling of image loading errors
+[assembly: ExportImageSourceHandler(typeof(FailImageSource), typeof(BrokenImageSourceHandler))]
#if TEST_LEGACY_RENDERERS
[assembly: ExportRenderer(typeof(Button), typeof(Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer))]
[assembly: ExportRenderer(typeof(Image), typeof(Xamarin.Forms.Platform.Android.ImageRenderer))]
diff --git a/Xamarin.Forms.ControlGallery.Android/Resources/drawable/invalidimage.jpg b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/invalidimage.jpg
new file mode 100644
index 00000000..6c7ebbb3
--- /dev/null
+++ b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/invalidimage.jpg
@@ -0,0 +1 @@
+This is certainly not a real JPEG. \ No newline at end of file
diff --git a/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj b/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj
index b606e109..e8011acb 100644
--- a/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj
+++ b/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj
@@ -26,6 +26,9 @@
<RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
+ <AndroidTlsProvider>
+ </AndroidTlsProvider>
+ <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<AndroidKeyStore>True</AndroidKeyStore>
@@ -46,20 +49,27 @@
<AndroidLinkMode>Full</AndroidLinkMode>
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
- <BundleAssemblies>False</BundleAssemblies>
<CustomCommands>
<CustomCommands>
- <Command type="AfterBuild" command="xbuild /t:SignAndroidPackage Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj" workingdir="${SolutionDir}" />
+ <Command>
+ <type>AfterBuild</type>
+ <command>xbuild /t:SignAndroidPackage Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj</command>
+ <workingdir>${SolutionDir}</workingdir>
+ </Command>
</CustomCommands>
</CustomCommands>
- <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidSupportedAbis>armeabi;armeabi-v7a;x86</AndroidSupportedAbis>
- <Debugger>Xamarin</Debugger>
- <AndroidEnableMultiDex>False</AndroidEnableMultiDex>
+ <Debugger>.Net (Xamarin)</Debugger>
<DevInstrumentationEnabled>True</DevInstrumentationEnabled>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>
</NoWarn>
+ <BundleAssemblies>False</BundleAssemblies>
+ <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
+ <AotAssemblies>False</AotAssemblies>
+ <EnableLLVM>False</EnableLLVM>
+ <AndroidEnableMultiDex>False</AndroidEnableMultiDex>
+ <EnableProguard>False</EnableProguard>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -73,8 +83,6 @@
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
<AndroidLinkSkip />
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
- <BundleAssemblies>False</BundleAssemblies>
- <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidSupportedAbis>armeabi-v7a,x86</AndroidSupportedAbis>
<AndroidStoreUncompressedFileExtensions />
<MandroidI18n />
@@ -97,14 +105,11 @@
<AndroidLinkSkip />
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
- <BundleAssemblies>False</BundleAssemblies>
- <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
<AndroidStoreUncompressedFileExtensions />
<MandroidI18n />
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
<Debugger>Xamarin</Debugger>
- <AndroidEnableMultiDex>False</AndroidEnableMultiDex>
<DevInstrumentationEnabled>True</DevInstrumentationEnabled>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>
@@ -176,6 +181,7 @@
<Compile Include="CustomRenderers.cs" />
<Compile Include="ColorPicker.cs" />
<Compile Include="_38989CustomRenderer.cs" />
+ <Compile Include="BrokenImageSourceHandler.cs" />
</ItemGroup>
<ItemGroup>
<AndroidAsset Include="Assets\default.css" />
@@ -204,6 +210,7 @@
<AndroidResource Include="Resources\drawable\coffee.png" />
<AndroidResource Include="Resources\drawable\toolbar_close.png" />
<AndroidResource Include="Resources\drawable\test.jpg" />
+ <AndroidResource Include="Resources\drawable\invalidimage.jpg" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\Icon.png" />
diff --git a/Xamarin.Forms.ControlGallery.Android/_38989CustomRenderer.cs b/Xamarin.Forms.ControlGallery.Android/_38989CustomRenderer.cs
index 1cde98a8..ef4aad71 100644
--- a/Xamarin.Forms.ControlGallery.Android/_38989CustomRenderer.cs
+++ b/Xamarin.Forms.ControlGallery.Android/_38989CustomRenderer.cs
@@ -30,6 +30,4 @@ namespace Xamarin.Forms.ControlGallery.Android
return nativeView;
}
}
-
-
} \ No newline at end of file