From 63af84080454e7b108208b6e8e67bbf503e41209 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Fri, 24 Mar 2017 17:54:12 +0000 Subject: [PATCH] [Android] Still look for the normal drawable on resources (#839) * [Android] Still look for the normal drawable on resources * [Android]Fix code style --- .../Resources/drawable/synchronize.xml | 9 +++++ .../drawable/synchronize_disabled.xml | 5 +++ .../drawable/synchronize_enabled.png | Bin 0 -> 1558 bytes ...amarin.Forms.ControlGallery.Android.csproj | 9 +++++ .../Bugzilla53909.cs | 38 ++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + .../AppCompat/NavigationPageRenderer.cs | 4 +- Xamarin.Forms.Platform.Android/CellAdapter.cs | 6 +-- Xamarin.Forms.Platform.Android/Platform.cs | 7 ++-- 9 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize.xml create mode 100644 Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_disabled.xml create mode 100644 Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_enabled.png create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla53909.cs diff --git a/Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize.xml b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize.xml new file mode 100644 index 000000000..d5de57bdb --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_disabled.xml b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_disabled.xml new file mode 100644 index 000000000..866845bdd --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_disabled.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_enabled.png b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_enabled.png new file mode 100644 index 0000000000000000000000000000000000000000..339cab59e1e2a105cce727a66dd312caa747666f GIT binary patch literal 1558 zcmbVMeNfY87_V}t2zqYL+no-#5Cr^yCTUCBL<-j?t*xUB3R4`nxtOLULXs{Cw&2G+ zba>3cABs#pVN>Vr+)kWxL&53roO8;qDmTw5FgLp*%ovSEGsWp3-O4&seWNER-+ha+Ldr5jwiU>Ef>#buBBQZ*gyjt2 zmXoH+z(bj0vGlPDLE@ot4Ipbq_GuVIh zdk|nfW^hTG3wHSlrigWvi%ed5c0OHROk*A}GXqEu;)(%|ktra^mGBZCG=rmdab>TH zArKga$i-&x38?~C4nPPZ1Egu;R2oJR05xb41B@B46hH?fFoftJ*qDmIc$yK15n${A z6>p-)i@Qntm@nmI28(3bk3&!(5YPtnT0!(d2!>%0tb=sAR0WYLmGLqaOy#A7hy{|7 zXp!~HtiS`RMQXWFDw{!t>5~vRzsvR1FfWZIN=X?Mr2G(~g&~ep;~GUvvYYvr#xv1U zewm+v+>9iYinLM>Z$d;_$=&lEsX&Dd{)WgZMWISafiC43UUrgZP`S~1SPzbps3{F0 ztT3j7Q4@lg2*hB)bb1su8A-xOL~J}u7qOxi6J{e!R?LndHpFTnNehbFNIeOYcElFZ zb@Gx-@iY_h%PM{mtHG)x?S|*-;)KXhvLNOQLP?|pa*705kctF9K;)%q5x_;!EU!w` z0zHYBWJGo)rT_Pf-2i5J<=2s3+$A{sSnGu!Yh<=<|qtT2founl{c;%Zq^QJt@^va&lh~HJv z={X_J-?VP;zK5~k?rX2T5I-TldMjGEbfWumELs6xKj2_K2GNQSVvoj#f9r3)H28C< zYVc;1{sw=oYcNEZl6!V;U(i>}%*|LmET(J-j-OTK&A7TNaK5m&XV1jJ?8MyJtH#aB zZLcH`HV{`oT~K>+Po{0@A6q_Whm+dw4r%v3Xb8-YuJ8pr-+%b$+B=WBdx|%aOl~hU zGCbltUVILWzqzq~{iz+aWGjEMl1hjQ$8{E@OSjs{q~htPs%KvhUi8&Fw%fk!3fI@y zpIhl{zrC{ji_MOUZ~0!{*cHm_4bPjGAKw^0c`(tJ*xVS`)UiLKIrZ)uVKNH%7Vmew zb3d0II-dFF*&~V4+W~vlQ7Z25Wnk^XmLt*q?GSL7$&I_3WDk8rA1JAu?Mlwsf4V~# zSAC(SJ6D*sD9L$xMpI+|y))eQo)-G6ahSg5*yf+^9%K2=I_Hv**!{{&1KLUZdYaq$ zw(HS{#w9E}-1l9$^;++m#eD-!Deg0KKHRc(#@uhct6~>UUfhAkD z-Fs_W25&TFnQ9td9QrZp^#haK(~?z5ipy + + + + + + + + + diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla53909.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla53909.cs new file mode 100644 index 000000000..a02de5b39 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla53909.cs @@ -0,0 +1,38 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +// Apply the default category of "Issues" to all of the tests in this assembly +// We use this as a catch-all for tests which haven't been individually categorized +#if UITEST +[assembly: NUnit.Framework.Category("Issues")] +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 53909, "XML drawables cannot be used as ToolbarItem.Icon ", PlatformAffected.Default)] + public class Bugzilla53909 : TestContentPage // or TestMasterDetailPage, etc ... + { + protected override void Init() + { + + var tbi = new ToolbarItem(); + tbi.Icon = "synchronize.png"; + tbi.Order = ToolbarItemOrder.Primary; + tbi.Priority = 0; + + ToolbarItems.Add(tbi); + + // Initialize ui here instead of ctor + Content = new Label + { + Text = "We need to check the icon appears" + }; + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 6a621e4f2..bf393aec1 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -268,6 +268,7 @@ + diff --git a/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs index cc4742937..1b4afba2e 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs @@ -744,8 +744,8 @@ namespace Xamarin.Forms.Platform.Android.AppCompat FileImageSource icon = item.Icon; if (!string.IsNullOrEmpty(icon)) { - var iconBitmap = new BitmapDrawable(context.Resources, ResourceManager.GetBitmap(context.Resources, icon)); - if (iconBitmap != null && iconBitmap.Bitmap != null) + Drawable iconBitmap = context.Resources.GetDrawable(icon) ?? new BitmapDrawable(context.Resources, ResourceManager.GetBitmap(context.Resources, icon)); + if (iconBitmap != 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 dda0c7e10..187ac23cb 100644 --- a/Xamarin.Forms.Platform.Android/CellAdapter.cs +++ b/Xamarin.Forms.Platform.Android/CellAdapter.cs @@ -195,9 +195,9 @@ namespace Xamarin.Forms.Platform.Android 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)); + Drawable iconBitmap = _context.Resources.GetDrawable(action.Icon) ?? new BitmapDrawable(_context.Resources, ResourceManager.GetBitmap(_context.Resources, action.Icon)); + if (iconBitmap != null) + item.SetIcon(iconBitmap); } action.PropertyChanged += changed; diff --git a/Xamarin.Forms.Platform.Android/Platform.cs b/Xamarin.Forms.Platform.Android/Platform.cs index 0fc287c9c..c2bb007e0 100644 --- a/Xamarin.Forms.Platform.Android/Platform.cs +++ b/Xamarin.Forms.Platform.Android/Platform.cs @@ -359,10 +359,11 @@ namespace Xamarin.Forms.Platform.Android else { IMenuItem menuItem = menu.Add(item.Text); - if (!string.IsNullOrEmpty(item.Icon)) + var icon = item.Icon; + if (!string.IsNullOrEmpty(icon)) { - var iconBitmap = new BitmapDrawable(_context.Resources, ResourceManager.GetBitmap(_context.Resources, item.Icon)); - if (iconBitmap != null && iconBitmap.Bitmap != null) + Drawable iconBitmap = _context.Resources.GetDrawable(icon) ?? new BitmapDrawable(_context.Resources, ResourceManager.GetBitmap(_context.Resources, icon)); + if (iconBitmap != null) menuItem.SetIcon(iconBitmap); } menuItem.SetEnabled(controller.IsEnabled);