[Android] Still look for the normal drawable on resources (#839)
authorRui Marinho <me@ruimarinho.net>
Fri, 24 Mar 2017 17:54:12 +0000 (17:54 +0000)
committerGitHub <noreply@github.com>
Fri, 24 Mar 2017 17:54:12 +0000 (17:54 +0000)
* [Android] Still look for the normal drawable on resources

* [Android]Fix code style

Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize.xml [new file with mode: 0644]
Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_disabled.xml [new file with mode: 0644]
Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_enabled.png [new file with mode: 0644]
Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla53909.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs
Xamarin.Forms.Platform.Android/CellAdapter.cs
Xamarin.Forms.Platform.Android/Platform.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 (file)
index 0000000..d5de57b
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+  <item
+      android:state_enabled="false"
+      android:drawable="@drawable/synchronize_disabled" />
+  <item
+      android:state_enabled="true"
+      android:drawable="@drawable/synchronize_enabled" />
+</selector>
\ 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 (file)
index 0000000..866845b
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+    android:src="@drawable/synchronize_enabled"
+    android:alpha="178">
+</bitmap>
\ 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 (file)
index 0000000..339cab5
Binary files /dev/null and b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/synchronize_enabled.png differ
index c8b9f6e..75a5a7b 100644 (file)
   <ItemGroup>
     <BundleResource Include="Resources\drawable\caret_r.png" />
   </ItemGroup>
+  <ItemGroup>
+    <AndroidResource Include="Resources\drawable\synchronize.xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <AndroidResource Include="Resources\drawable\synchronize_disabled.xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <AndroidResource Include="Resources\drawable\synchronize_enabled.png" />
+  </ItemGroup>
   <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
   <Import Project="..\packages\Xamarin.Insights.1.11.4\build\MonoAndroid10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.11.4\build\MonoAndroid10\Xamarin.Insights.targets')" />
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 (file)
index 0000000..a02de5b
--- /dev/null
@@ -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
index 6a621e4..bf393ae 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla52533.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla53362.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla45874.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Bugzilla53909.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue1075.cs" />
index cc47429..1b4afba 100644 (file)
@@ -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);
index dda0c7e..187ac23 100644 (file)
@@ -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;
index 0fc287c..c2bb007 100644 (file)
@@ -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);