Skip to content

Commit

Permalink
glidex -> Xamarin.Android.Glide (#35)
Browse files Browse the repository at this point in the history
Context: #28

For a fuller binding for Glide, we can use the Xamarin.Android.Glide
NuGet that is now provided by Xamarin.

This should allow us to expose more advanced features of Glide to
glidex.forms users.

I also don't want to maintain my own binding, when a better (official)
one exists.

I also bumped the NuGet version number to 2.0.0-pre1.
  • Loading branch information
jonathanpeppers committed May 7, 2019
1 parent dd976a2 commit 627934b
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 416 deletions.
63 changes: 32 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,52 @@
# glidex and glidex.forms
glidex is a minimalist Xamarin.Android binding of [Glide](https://github.com/bumptech/glide). Google recommends Glide for simplifying the complexity of managing `Android.Graphics.Bitmap` within your apps ([docs here](https://developer.android.com/topic/performance/graphics/manage-memory.html)).
# glidex.forms (or just glidex)

glidex.forms is a prototype of what we can do to improve Xamarin.Forms image performance on Android by taking a dependency on Glide. See my post on the topic [here](http://jonathanpeppers.com/Blog/xamarin-forms-performance-on-android).
Google recommends [Glide][glide] for simplifying the complexity of
managing `Android.Graphics.Bitmap` within your apps ([docs
here][glide_docs]).

Download from NuGet (use the Prerelease checkbox):
glidex.forms is small library we can use to improve Xamarin.Forms
image performance on Android by taking a dependency on Glide. See my
post on the topic [here][blog].

| glidex | glidex.forms |
|---|---|
| [![NuGet](https://img.shields.io/nuget/dt/glidex.svg)](https://www.nuget.org/packages/glidex) | [![NuGet](https://img.shields.io/nuget/dt/glidex.forms.svg)](https://www.nuget.org/packages/glidex.forms) |
[glide]: https://github.com/bumptech/glide
[glide_docs]: https://developer.android.com/topic/performance/graphics/manage-memory.html
[blog]: http://jonathanpeppers.com/Blog/xamarin-forms-performance-on-android

Learn more on [this episode of the Xamarin Show](https://youtu.be/IYF2ChHTTWc):

[![Super Fast Image Loading for Android Apps with GlideX | The Xamarin Show](https://img.youtube.com/vi/IYF2ChHTTWc/maxresdefault.jpg)](https://youtu.be/IYF2ChHTTWc)

We don't want or care to bind the entirety of Glide's public API surface. Our goal here is to just bind the "useful" APIs for Glide.
Download from NuGet:

For example take the following C#:
```csharp
var image = FindViewById<ImageView> (Resource.Id.testImage);
Glide.With (this)
.Load ("https://botlist.co/system/BotList/Bot/logos/000/002/271/medium/chuck_norris.jpg")
.Apply (RequestOptions.CircleCropTransform ().Placeholder (Android.Resource.Drawable.IcMenuCamera))
.Into (image);
```
| glidex.forms |
|---|
| [![NuGet](https://img.shields.io/nuget/dt/glidex.forms.svg)](https://www.nuget.org/packages/glidex.forms) |

This code loads an image from a URL dynamically, taking care of all of Glide's cool caching functionality. These are the only APIs we need to make the library useful.
Learn more on [this episode of the Xamarin Show](https://youtu.be/IYF2ChHTTWc):

If you have a "classic" Xamarin.Android app that is not Xamarin.Forms, it could be useful to use the `glidex` NuGet package directly.
[![Super Fast Image Loading for Android Apps with GlideX | The Xamarin Show](https://img.youtube.com/vi/IYF2ChHTTWc/maxresdefault.jpg)](https://youtu.be/IYF2ChHTTWc)

_glidex is currently using the 4.7.0 release of Glide from Github_
If you have a "classic" Xamarin.Android app that is not Xamarin.Forms, it could be useful to use the [Xamarin.Android.Glide][xa_glide] NuGet package. If you want to improve the Xamarin binding for Glide, contribute to it on [Github][xa_glide_github]!

# glidex.forms for Xamarin.Forms on Android
[xa_glide]: https://www.nuget.org/packages/Xamarin.Android.Glide/
[xa_glide_github]: https://github.com/xamarin/XamarinComponents/tree/master/Android/Glide

My goal with this repo is to get fast Images for Xamarin.Forms on Android by using Glide.
_glidex.forms is currently using the 4.9.0 release of Xamarin.Android.Glide_

The new `IImageViewHandler` API in Xamarin.Forms 3.3.x, allows glidex.forms to operate without using *any* custom renderers!
# How do I use glidex.forms?

But to set this library up in your existing project, merely:
To set this library up in your existing project, merely:
- Add the `glidex.forms` NuGet package
- Add this one liner after your app's `Forms.Init` call:

```csharp
Xamarin.Forms.Forms.Init (this, bundle);
//This forces the custom renderers to be used
Android.Glide.Forms.Init ();
Android.Glide.Forms.Init (this);
LoadApplication (new App ());
```

## How do I know my app is using Glide?

On first use, you may want to enable debug logging:
```csharp
Android.Glide.Forms.Init (debug: true);
Android.Glide.Forms.Init (this, debug: true);
```
glidex.forms will print out log messages in your device log as to what is happening under the hood.

Expand Down Expand Up @@ -80,9 +75,15 @@ _NOTE: this was a past comparison with Xamarin.Forms 2.5.x_

_NOTE: I believe these numbers are in bytes. I restarted the app (release mode) before recording the numbers for each page. Pages with ListViews I scrolled up and down a few times._

Stock XF performance of images is poor due to the amount of `Android.Graphics.Bitmap` instances created on each page. Disabling the Glide library in the sample app causes "out of memory" errors to happen as images load. You will see empty white squares where this occurs and get console output.
Stock XF performance of images is poor due to the amount of
`Android.Graphics.Bitmap` instances created on each page. Disabling
the Glide library in the sample app causes "out of memory" errors to
happen as images load. You will see empty white squares where this
occurs and get console output.

To try stock Xamarin.Forms behavior yourself, you can remove the references to `glidex` and `glidex.forms` in the `glide.forms.sample` project and comment out the `Android.Glide.Forms.Init()` line.
To try stock Xamarin.Forms behavior yourself, you can remove the
references to `glidex` and `glidex.forms` in the `glide.forms.sample`
project and comment out the `Android.Glide.Forms.Init()` line.

# Features

Expand Down
33 changes: 4 additions & 29 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ string configuration = Argument("configuration", "Release");
var dirs = new[]
{
Directory("./build"),
Directory("./glidex/bin") + Directory(configuration),
Directory("./glidex/obj") + Directory(configuration),
Directory("./glidex.forms/bin") + Directory(configuration),
Directory("./glidex.forms/obj") + Directory(configuration),
Directory("./glidex.sample/bin") + Directory(configuration),
Directory("./glidex.sample/obj") + Directory(configuration),
Directory("./glidex.forms.sample/bin") + Directory(configuration),
Directory("./glidex.forms.sample/obj") + Directory(configuration),
};
string output = dirs[0];
string sln = "./glidex.sln";
string version = "1.0.4";
string suffix = "";
string version = "2.0.0";
string suffix = "-pre1";

Task("Clean")
.Does(() =>
Expand Down Expand Up @@ -50,40 +46,19 @@ Task("Install")
MSBuild("./glidex.forms.sample/glidex.forms.sample.csproj", settings => settings.SetConfiguration(configuration).WithTarget("Install").WithTarget("_Run"));
});

Task("NuGet-Package-GlideX")
.IsDependentOn("Build")
.Does(() =>
{
package(version + suffix, "./glidex/glidex.nuspec", "glidex.dll", output);
});

Task("NuGet-Push-GlideX")
.Does(() =>
{
push("./build/glidex." + version + suffix + ".nupkg");
});

Task("NuGet-Package-GlideX-Forms")
Task("NuGet-Package")
.IsDependentOn("Build")
.Does(() =>
{
package(version + suffix, "./glidex.forms/glidex.forms.nuspec", "glidex.forms.dll", output);
});

Task("NuGet-Push-GlideX-Forms")
Task("NuGet-Push")
.Does(() =>
{
push("./build/glidex.forms." + version + suffix + ".nupkg");
});

Task("NuGet-Package")
.IsDependentOn("NuGet-Package-GlideX")
.IsDependentOn("NuGet-Package-GlideX-Forms");

Task("NuGet-Push")
.IsDependentOn("NuGet-Push-GlideX")
.IsDependentOn("NuGet-Push-GlideX-Forms");

Task("Default")
.IsDependentOn("NuGet-Package");

Expand Down
4 changes: 0 additions & 4 deletions glidex.forms.sample/glidex.forms.sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@
<Project>{dfb39f19-eec3-4ecb-888d-d84c3b4a9113}</Project>
<Name>glidex.forms</Name>
</ProjectReference>
<ProjectReference Include="..\glidex\glidex.csproj">
<Project>{d8d4d6c6-b845-4114-ade0-ea3777c5e452}</Project>
<Name>glidex</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
4 changes: 3 additions & 1 deletion glidex.forms/GlideExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
using Android.App;
using Android.Views;
using Android.Widget;
using Bumptech.Glide;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using static Bumptech.Glide.Glide;

namespace Android.Glide
{
Expand All @@ -18,7 +20,7 @@ public static async Task LoadViaGlide (this ImageView imageView, ImageSource sou
if (!IsActivityAlive (imageView, source))
return;

RequestManager request = Glide.With (imageView.Context);
RequestManager request = With (imageView.Context);
RequestBuilder builder = null;

if (source is null) {
Expand Down
7 changes: 1 addition & 6 deletions glidex.forms/glidex.forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="3.4.0.1029999" ExcludeAssets="build" />
<PackageReference Include="Xamarin.Android.Glide" Version="4.9.0" />
<PackageReference Include="Xamarin.Android.Support.Design" Version="27.0.2" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2" />
<PackageReference Include="Xamarin.Android.Support.v4" Version="27.0.2" />
Expand All @@ -56,11 +57,5 @@
<Compile Include="ImageViewHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\glidex\glidex.csproj">
<Project>{d8d4d6c6-b845-4114-ade0-ea3777c5e452}</Project>
<Name>glidex</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
2 changes: 1 addition & 1 deletion glidex.forms/glidex.forms.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<releaseNotes></releaseNotes>
<tags>Xamarin, Xamarin.Forms, Android, Glide, Bitmap, Images</tags>
<dependencies>
<dependency id="glidex" version="$version$" />
<dependency id="Xamarin.Android.Glide" version="4.9.0" />
<dependency id="Xamarin.Forms" version="3.4.0.1029999" />
</dependencies>
</metadata>
Expand Down
26 changes: 0 additions & 26 deletions glidex.sample/MainActivity.cs

This file was deleted.

6 changes: 0 additions & 6 deletions glidex.sample/Properties/AndroidManifest.xml

This file was deleted.

16 changes: 0 additions & 16 deletions glidex.sample/Properties/AssemblyInfo.cs

This file was deleted.

13 changes: 0 additions & 13 deletions glidex.sample/Resources/layout/Main.axml

This file was deleted.

4 changes: 0 additions & 4 deletions glidex.sample/Resources/values/Strings.xml

This file was deleted.

83 changes: 0 additions & 83 deletions glidex.sample/glidex.sample.csproj

This file was deleted.

7 changes: 0 additions & 7 deletions glidex.sample/proguard.cfg

This file was deleted.

Loading

0 comments on commit 627934b

Please sign in to comment.