[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>
<Reference Include="Mono.Android" />
<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.Core" />
<Reference Include="System.Xml.Linq" />

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

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<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.Design" 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)Bugzilla42519.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43516.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43569.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44166.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44461.cs" />

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

@ -304,6 +304,14 @@
</EmbeddedResource>
</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">
<HintPath>..\packages\Xamarin.Insights.1.12.3\lib\portable-win+net45+wp80+windows8+wpa+MonoAndroid10+MonoTouch10\Xamarin.Insights.dll</HintPath>
</Reference>

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

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
</packages>

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

@ -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);

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

@ -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)
{
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;

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

@ -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;

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

@ -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));