[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
This commit is contained in:
adrianknight89 2016-11-03 13:38:38 -05:00 коммит произвёл Samantha Houts
Родитель a2fae62d83
Коммит 84995a9212
10 изменённых файлов: 133 добавлений и 6 удалений

Просмотреть файл

@ -115,6 +115,14 @@
<ItemGroup> <ItemGroup>
<Reference Include="Mono.Android" /> <Reference Include="Mono.Android" />
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="PCLStorage, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\PCLStorage.1.0.2\lib\monoandroid\PCLStorage.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PCLStorage.Abstractions, Version=1.0.2.0, Culture=neutral, PublicKeyToken=286fe515a2c35b64, processorArchitecture=MSIL">
<HintPath>..\packages\PCLStorage.1.0.2\lib\monoandroid\PCLStorage.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="PCLStorage" version="1.0.2" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" /> <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" /> <package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" /> <package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -127,6 +127,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42364.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla42364.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42519.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla42519.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43516.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43516.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43569.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44166.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44166.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44461.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44461.cs" />

Просмотреть файл

@ -304,6 +304,14 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="PCLStorage, Version=1.0.2.0, Culture=neutral, PublicKeyToken=286fe515a2c35b64, processorArchitecture=MSIL">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-net45+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac\PCLStorage.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PCLStorage.Abstractions, Version=1.0.2.0, Culture=neutral, PublicKeyToken=286fe515a2c35b64, processorArchitecture=MSIL">
<HintPath>..\packages\PCLStorage.1.0.2\lib\portable-net45+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac\PCLStorage.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xamarin.Insights"> <Reference Include="Xamarin.Insights">
<HintPath>..\packages\Xamarin.Insights.1.12.3\lib\portable-win+net45+wp80+windows8+wpa+MonoAndroid10+MonoTouch10\Xamarin.Insights.dll</HintPath> <HintPath>..\packages\Xamarin.Insights.1.12.3\lib\portable-win+net45+wp80+windows8+wpa+MonoAndroid10+MonoTouch10\Xamarin.Insights.dll</HintPath>
</Reference> </Reference>

Просмотреть файл

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="PCLStorage" version="1.0.2" targetFramework="portable45-net45+win8+wp8+wpa81" />
<package id="Xamarin.Insights" version="1.12.3" targetFramework="portable45-net45+win8+wp8+wpa81" /> <package id="Xamarin.Insights" version="1.12.3" targetFramework="portable45-net45+win8+wp8+wpa81" />
</packages> </packages>

Просмотреть файл

@ -709,8 +709,8 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
FileImageSource icon = item.Icon; FileImageSource icon = item.Icon;
if (!string.IsNullOrEmpty(icon)) if (!string.IsNullOrEmpty(icon))
{ {
Drawable iconBitmap = context.Resources.GetDrawable(icon); var iconBitmap = new BitmapDrawable(context.Resources, ResourceManager.GetBitmap(context.Resources, icon));
if (iconBitmap != null) if (iconBitmap != null && iconBitmap.Bitmap != null)
menuItem.SetIcon(iconBitmap); menuItem.SetIcon(iconBitmap);
} }
menuItem.SetEnabled(controller.IsEnabled); menuItem.SetEnabled(controller.IsEnabled);

Просмотреть файл

@ -8,6 +8,7 @@ using Android.Views;
using Android.Widget; using Android.Widget;
using AView = Android.Views.View; using AView = Android.Views.View;
using AListView = Android.Widget.ListView; using AListView = Android.Widget.ListView;
using Android.Graphics.Drawables;
namespace Xamarin.Forms.Platform.Android 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); IMenuItem item = menu.Add(Menu.None, i, Menu.None, action.Text);
if (action.Icon != null) 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.PropertyChanged += changed;
action.PropertyChanging += changing; action.PropertyChanging += changing;

Просмотреть файл

@ -361,8 +361,8 @@ namespace Xamarin.Forms.Platform.Android
IMenuItem menuItem = menu.Add(item.Text); IMenuItem menuItem = menu.Add(item.Text);
if (!string.IsNullOrEmpty(item.Icon)) if (!string.IsNullOrEmpty(item.Icon))
{ {
Drawable iconBitmap = _context.Resources.GetDrawable(item.Icon); var iconBitmap = new BitmapDrawable(_context.Resources, ResourceManager.GetBitmap(_context.Resources, item.Icon));
if (iconBitmap != null) if (iconBitmap != null && iconBitmap.Bitmap != null)
menuItem.SetIcon(iconBitmap); menuItem.SetIcon(iconBitmap);
} }
menuItem.SetEnabled(controller.IsEnabled); menuItem.SetEnabled(controller.IsEnabled);
@ -948,7 +948,10 @@ namespace Xamarin.Forms.Platform.Android
FileImageSource titleIcon = NavigationPage.GetTitleIcon(view); FileImageSource titleIcon = NavigationPage.GetTitleIcon(view);
if (!string.IsNullOrWhiteSpace(titleIcon)) 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; useLogo = true;
showHome = true; showHome = true;
showTitle = true; showTitle = true;

Просмотреть файл

@ -16,6 +16,17 @@ namespace Xamarin.Forms.Platform.Android
public static Type ResourceClass { get; set; } 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) public static Bitmap GetBitmap(this Resources resource, string name)
{ {
return BitmapFactory.DecodeResource(resource, IdFromTitle(name, DrawableClass)); return BitmapFactory.DecodeResource(resource, IdFromTitle(name, DrawableClass));