Skip to content

Commit

Permalink
Merge pull request #21 from paulcbetts/fix-android-resource-lookup
Browse files Browse the repository at this point in the history
Try the passed in string without an extension on Android for resource loading
  • Loading branch information
Paul Betts committed Oct 7, 2013
2 parents dae033d + b3ae8bf commit c57020d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Splat/Android/Bitmaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Collections.Generic;
using System.Linq;

using Path = System.IO.Path;

namespace Splat
{
public class PlatformBitmapLoader : IBitmapLoader
Expand Down Expand Up @@ -55,6 +57,13 @@ public Task<IBitmap> LoadFromResource(string source, float? desiredWidth, float?
return Task.Run(() => (IBitmap)new DrawableBitmap(res.GetDrawable(drawableList[source])));
}

// NB: On iOS, you have to pass the extension, but on Android it's
// stripped - try stripping the extension to see if there's a Drawable.
var key = Path.GetFileNameWithoutExtension(source);
if (drawableList.ContainsKey(key)) {
return Task.Run(() => (IBitmap)new DrawableBitmap(res.GetDrawable(drawableList[key])));
}

throw new ArgumentException("Either pass in an integer ID cast to a string, or the name of a drawable resource");
}

Expand Down

0 comments on commit c57020d

Please sign in to comment.