Skip to content

Commit

Permalink
ImageSource and ImageSourceServices (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow authored Apr 29, 2021
1 parent cacabd6 commit 4340ccf
Show file tree
Hide file tree
Showing 242 changed files with 5,883 additions and 1,087 deletions.
20 changes: 10 additions & 10 deletions .nuspec/Microsoft.Maui.Controls.MultiTargeting.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS')) != true AND $(TargetFramework.StartsWith('net6.0-ios')) != true AND $(TargetFramework.StartsWith('net6.0-maccatalyst')) != true ">
<Compile Remove="**\*.iOS.cs" />
<None Include="**\*.iOS.cs" />
<Compile Remove="**\iOS\*.cs" />
<None Include="**\iOS\*.cs" />
<Compile Remove="**\iOS\**\*.cs" />
<None Include="**\iOS\**\*.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac')) != true ">
<Compile Remove="**\*.Mac.cs" />
<None Include="**\*.Mac.cs" />
<Compile Remove="**\Mac\*.cs" />
<None Include="**\Mac\*.cs" />
<Compile Remove="**\Mac\**\*.cs" />
<None Include="**\Mac\**\*.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac')) != true AND $(TargetFramework.StartsWith('Xamarin.iOS')) != true AND $(TargetFramework.StartsWith('net6.0-ios')) != true AND $(TargetFramework.StartsWith('net6.0-maccatalyst')) != true">
<Compile Remove="**\*.MaciOS.cs" />
<None Include="**\*.MaciOS.cs" />
<Compile Remove="**\MaciOS\*.cs" />
<None Include="**\MaciOS\*.cs" />
<Compile Remove="**\MaciOS\**\*.cs" />
<None Include="**\MaciOS\**\*.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('MonoAndroid')) != true AND $(TargetFramework.StartsWith('net6.0-android')) != true ">
<Compile Remove="**\*.Android.cs" />
<None Include="**\*.Android.cs" />
<Compile Remove="**\Android\*.cs" />
<None Include="**\Android\*.cs" />
<Compile Remove="**\Android\**\*.cs" />
<None Include="**\Android\**\*.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard')) != true ">
<Compile Remove="**\*.Standard.cs" />
<None Include="**\*.Standard.cs" />
<Compile Remove="**\Standard\*.cs" />
<None Include="**\Standard\*.cs" />
<Compile Remove="**\Standard\**\*.cs" />
<None Include="**\Standard\**\*.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.Contains('-windows')) != true ">
<Compile Remove="**\*.Windows.cs" />
Expand Down
4 changes: 2 additions & 2 deletions .nuspec/Microsoft.Maui.Resizetizer.targets
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
_CleanResizetizer;
</CleanDependsOn>

<_ResizetizerInputsFile>$(IntermediateOutputPath)resizetizer.inputs</_ResizetizerInputsFile>
<_ResizetizerStampFile>$(IntermediateOutputPath)resizetizer.stamp</_ResizetizerStampFile>
<_ResizetizerInputsFile>$(IntermediateOutputPath)mauiimage.inputs</_ResizetizerInputsFile>
<_ResizetizerStampFile>$(IntermediateOutputPath)mauiimage.stamp</_ResizetizerStampFile>
<_MauiFontInputsFile>$(IntermediateOutputPath)mauifont.inputs</_MauiFontInputsFile>
<_MauiFontStampFile>$(IntermediateOutputPath)mauifont.stamp</_MauiFontStampFile>
<_MauiSplashInputsFile>$(IntermediateOutputPath)mauisplash.inputs</_MauiSplashInputsFile>
Expand Down
13 changes: 13 additions & 0 deletions eng/Microsoft.Extensions.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<_MicrosoftProjectReunionVersion>0.5.0</_MicrosoftProjectReunionVersion>
<_MicrosoftGraphicsWin2DVersion>0.5.0.13</_MicrosoftGraphicsWin2DVersion>
<_MicrosoftMauiGraphics>6.0.100-preview.3.61</_MicrosoftMauiGraphics>
<_XamarinAndroidGlideVersion>4.11.0.1</_XamarinAndroidGlideVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0-ios' Or '$(TargetFramework)' == 'net6.0-maccatalyst'">
<!-- Debugger workaround -->
Expand Down Expand Up @@ -40,6 +41,14 @@
Update="Microsoft.Extensions.Logging"
Version="$(_MicrosoftHostingVersion)"
/>
<PackageReference
Update="Microsoft.Extensions.Logging.Console"
Version="$(_MicrosoftHostingVersion)"
/>
<PackageReference
Update="Microsoft.Extensions.Logging.Debug"
Version="$(_MicrosoftHostingVersion)"
/>
<PackageReference
Update="Microsoft.ProjectReunion"
Version="$(_MicrosoftProjectReunionVersion)"
Expand All @@ -56,5 +65,9 @@
Update="Microsoft.Graphics.Win2D"
Version="$(_MicrosoftGraphicsWin2DVersion)"
/>
<PackageReference
Update="Xamarin.Android.Glide"
Version="$(_XamarinAndroidGlideVersion)"
/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using Microsoft.Maui.Controls.Compatibility.Platform.UWP;
using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI;
using Microsoft.Maui.Controls.Platform;

[assembly: ExportRenderer(typeof(_51173Image), typeof(_51173CustomImageRenderer))]
namespace Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Maui.Controls.Compatibility.Platform.UWP;
using Microsoft.Maui.Controls.Compatibility.ControlGallery.Issues;
using Microsoft.Maui.Controls.Compatibility.ControlGallery.WinUI;
using Microsoft.Maui.Controls.Platform;
using Bitmap = Microsoft.UI.Xaml.Media.ImageSource;

[assembly: Dependency(typeof(_13109IssueHelper))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
<AndroidResource Include="Resources\layout\toolbar.axml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\..\Controls\src\Core\Crc64.cs" Link="Crc64.cs" />
<Compile Include="..\..\..\..\Controls\src\Core\StreamWrapper.cs" Link="StreamWrapper.cs" />
<Compile Include="..\AppHostBuilderExtensions.cs" Link="AppHostBuilderExtensions.cs" />
<Compile Include="..\MauiHandlersCollectionExtensions.cs" Link="MauiHandlersCollectionExtensions.cs" />
</ItemGroup>
Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions src/Compatibility/Core/src/Android/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static class Forms
static bool? s_isNougatOrNewer;
static bool? s_isOreoOrNewer;
static bool? s_isPieOrNewer;
static FontManager s_fontManager;

// One per process; does not change, suitable for loading resources (e.g., ResourceProvider)
internal static Context ApplicationContext { get; private set; } = global::Android.App.Application.Context;
Expand Down Expand Up @@ -155,9 +154,6 @@ internal static bool IsPieOrNewer
}
}

internal static IFontManager FontManager =>
s_fontManager ??= new FontManager(Registrar.FontRegistrar);

public static float GetFontSizeNormal(Context context)
{
float size = 50;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,18 @@ public override bool SelectDrawable(int index)

public static async Task<IFormsAnimationDrawable> LoadImageAnimationAsync(UriImageSource imagesource, Context context, CancellationToken cancelationToken = default(CancellationToken))
{
Uri uri = imagesource?.Uri;
FormsAnimationDrawable animation = null;

if (uri != null)
if (imagesource is IStreamImageSource streamImageSource)
{
var options = new BitmapFactory.Options
using var stream = await streamImageSource.GetStreamAsync(cancelationToken).ConfigureAwait(false);
if (stream != null)
{
InJustDecodeBounds = true
};
var options = new BitmapFactory.Options
{
InJustDecodeBounds = true
};

using (Stream stream = await imagesource.GetStreamAsync(cancelationToken).ConfigureAwait(false))
{
using (var decoder = new AndroidGIFImageParser(context, options.InDensity, options.InTargetDensity))
{
try
Expand All @@ -247,11 +247,11 @@ public override bool SelectDrawable(int index)
animation = null;
}
}
}

if (animation == null)
{
Log.Warning(nameof(FileImageSourceHandler), "Could not retrieve image or image data was invalid: {0}", imagesource);
if (animation == null)
{
Log.Warning(nameof(FileImageSourceHandler), "Could not retrieve image or image data was invalid: {0}", imagesource);
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/Compatibility/Core/src/Android/Renderers/FontExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
public static class FontExtensions
{
public static float ToScaledPixel(this Font self)
=> Forms.FontManager.GetScaledPixel(self);
=> CompatServiceProvider.FontManager.GetScaledPixel(self);

public static Typeface ToTypeface(this Font self)
=> Forms.FontManager.GetTypeface(self);
=> CompatServiceProvider.FontManager.GetTypeface(self);

internal static Typeface ToTypeface(this string fontfamily, FontAttributes attr = FontAttributes.None)
=> Forms.FontManager.GetTypeface(Font.OfSize(fontfamily, 0.0).WithAttributes(attr));
=> CompatServiceProvider.FontManager.GetTypeface(Font.OfSize(fontfamily, 0.0).WithAttributes(attr));

internal static bool IsDefault(this IFontElement self)
=> self.FontFamily == null && self.FontSize == Device.GetNamedSize(NamedSize.Default, typeof(Label), true) && self.FontAttributes == FontAttributes.None;

internal static Typeface ToTypeface(this IFontElement self)
{
if (self.IsDefault())
return Forms.FontManager.DefaultTypeface;
return CompatServiceProvider.FontManager.DefaultTypeface;

var font = Font.OfSize(self.FontFamily, self.FontSize).WithAttributes(self.FontAttributes);

return Forms.FontManager.GetTypeface(font);
return CompatServiceProvider.FontManager.GetTypeface(font);
}
}
}
25 changes: 0 additions & 25 deletions src/Compatibility/Core/src/Android/Renderers/ImageExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ public sealed class ImageLoaderSourceHandler : IAnimationSourceHandler, IImageSo
{
public async Task<Bitmap> LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken = default(CancellationToken))
{
var imageLoader = imagesource as UriImageSource;
Bitmap bitmap = null;
if (imageLoader?.Uri != null)

if (imagesource is IStreamImageSource imageLoader)
{
using (Stream imageStream = await imageLoader.GetStreamAsync(cancelationToken).ConfigureAwait(false))
using var imageStream = await imageLoader.GetStreamAsync(cancelationToken).ConfigureAwait(false);
if (imageStream != null)
{
bitmap = await BitmapFactory.DecodeStreamAsync(imageStream).ConfigureAwait(false);
}

if (bitmap == null)
{
Log.Warning(nameof(ImageLoaderSourceHandler), "Could not retrieve image or image data was invalid: {0}", imageLoader);
if (bitmap == null)
{
Log.Warning(nameof(ImageLoaderSourceHandler), "Could not retrieve image or image data was invalid: {0}", imagesource);
}
}
}

return bitmap;
Expand Down
Loading

0 comments on commit 4340ccf

Please sign in to comment.