summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2016-11-03 13:38:38 -0500
committerSamantha Houts <samantha@teamredwall.com>2016-11-03 11:38:38 -0700
commit84995a921221811d2e7047d54dcefde0c8063397 (patch)
tree5868bf9bd5ffd6dd2fb0c8d8b22fd8728b9c4764 /Xamarin.Forms.Platform.Android
parenta2fae62d8384f78c1b5f0ba3dc088000946479bc (diff)
downloadxamarin-forms-84995a921221811d2e7047d54dcefde0c8063397.tar.gz
xamarin-forms-84995a921221811d2e7047d54dcefde0c8063397.tar.bz2
xamarin-forms-84995a921221811d2e7047d54dcefde0c8063397.zip
[Android] Allow path-based icons to be loaded as toolbar icons (#437)
* Created a bitmap method to check for resource as well as path * Update platform and navigationrenderer to get images from two locations * CellAdapter could use path-based icon finding * sample app to test toolbaritem icons
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs4
-rw-r--r--Xamarin.Forms.Platform.Android/CellAdapter.cs7
-rw-r--r--Xamarin.Forms.Platform.Android/Platform.cs9
-rw-r--r--Xamarin.Forms.Platform.Android/ResourceManager.cs11
4 files changed, 25 insertions, 6 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs
index b77063ee..dc3c5666 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs
@@ -709,8 +709,8 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
FileImageSource icon = item.Icon;
if (!string.IsNullOrEmpty(icon))
{
- Drawable iconBitmap = context.Resources.GetDrawable(icon);
- if (iconBitmap != null)
+ var iconBitmap = new BitmapDrawable(context.Resources, ResourceManager.GetBitmap(context.Resources, icon));
+ if (iconBitmap != null && iconBitmap.Bitmap != null)
menuItem.SetIcon(iconBitmap);
}
menuItem.SetEnabled(controller.IsEnabled);
diff --git a/Xamarin.Forms.Platform.Android/CellAdapter.cs b/Xamarin.Forms.Platform.Android/CellAdapter.cs
index 44bcb3d9..02bf7a38 100644
--- a/Xamarin.Forms.Platform.Android/CellAdapter.cs
+++ b/Xamarin.Forms.Platform.Android/CellAdapter.cs
@@ -8,6 +8,7 @@ using Android.Views;
using Android.Widget;
using AView = Android.Views.View;
using AListView = Android.Widget.ListView;
+using Android.Graphics.Drawables;
namespace Xamarin.Forms.Platform.Android
{
@@ -194,7 +195,11 @@ namespace Xamarin.Forms.Platform.Android
IMenuItem item = menu.Add(Menu.None, i, Menu.None, action.Text);
if (action.Icon != null)
- item.SetIcon(_context.Resources.GetDrawable(action.Icon));
+ {
+ var iconBitmap = new BitmapDrawable(_context.Resources, ResourceManager.GetBitmap(_context.Resources, action.Icon));
+ if (iconBitmap != null && iconBitmap.Bitmap != null)
+ item.SetIcon(_context.Resources.GetDrawable(action.Icon));
+ }
action.PropertyChanged += changed;
action.PropertyChanging += changing;
diff --git a/Xamarin.Forms.Platform.Android/Platform.cs b/Xamarin.Forms.Platform.Android/Platform.cs
index 3334ba6e..29af59f7 100644
--- a/Xamarin.Forms.Platform.Android/Platform.cs
+++ b/Xamarin.Forms.Platform.Android/Platform.cs
@@ -361,8 +361,8 @@ namespace Xamarin.Forms.Platform.Android
IMenuItem menuItem = menu.Add(item.Text);
if (!string.IsNullOrEmpty(item.Icon))
{
- Drawable iconBitmap = _context.Resources.GetDrawable(item.Icon);
- if (iconBitmap != null)
+ var iconBitmap = new BitmapDrawable(_context.Resources, ResourceManager.GetBitmap(_context.Resources, item.Icon));
+ if (iconBitmap != null && iconBitmap.Bitmap != null)
menuItem.SetIcon(iconBitmap);
}
menuItem.SetEnabled(controller.IsEnabled);
@@ -948,7 +948,10 @@ namespace Xamarin.Forms.Platform.Android
FileImageSource titleIcon = NavigationPage.GetTitleIcon(view);
if (!string.IsNullOrWhiteSpace(titleIcon))
{
- actionBar.SetLogo(_context.Resources.GetDrawable(titleIcon));
+ var iconBitmap = new BitmapDrawable(_context.Resources, ResourceManager.GetBitmap(_context.Resources, titleIcon));
+ if (iconBitmap != null && iconBitmap.Bitmap != null)
+ actionBar.SetLogo(iconBitmap);
+
useLogo = true;
showHome = true;
showTitle = true;
diff --git a/Xamarin.Forms.Platform.Android/ResourceManager.cs b/Xamarin.Forms.Platform.Android/ResourceManager.cs
index b8629026..397b3c27 100644
--- a/Xamarin.Forms.Platform.Android/ResourceManager.cs
+++ b/Xamarin.Forms.Platform.Android/ResourceManager.cs
@@ -16,6 +16,17 @@ namespace Xamarin.Forms.Platform.Android
public static Type ResourceClass { get; set; }
+ public static Bitmap GetBitmap(this Resources resource, FileImageSource fileImageSource)
+ {
+ var file = fileImageSource.File;
+
+ var bitmap = GetBitmap(resource, file);
+ if (bitmap != null)
+ return bitmap;
+
+ return BitmapFactory.DecodeFile(file);
+ }
+
public static Bitmap GetBitmap(this Resources resource, string name)
{
return BitmapFactory.DecodeResource(resource, IdFromTitle(name, DrawableClass));