From 3e2e2b4056652165edb69ad988f800afaf80bfc6 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 31 Jul 2018 14:29:28 +0100 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Add 'transition' and 'array' support (#2014) * [Xamarin.Android.Build.Tasks] Add 'transition' support The ManagedResourceParser did not support `transition` resource types. This commit adds support for that missing type. * Added missing Array parsing for R.txt too * Added Unit Test --- .../Expected/GenerateDesignerFileExpected.cs | 80 +++++++++++++------ .../ManagedResourceParserTests.cs | 16 ++++ .../Utilities/ManagedResourceParser.cs | 15 +++- 3 files changed, 86 insertions(+), 25 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Expected/GenerateDesignerFileExpected.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Expected/GenerateDesignerFileExpected.cs index 6564a091752..4820919b1a9 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Expected/GenerateDesignerFileExpected.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Expected/GenerateDesignerFileExpected.cs @@ -27,8 +27,8 @@ static Resource() public partial class Animator { - // aapt resource value: 0x7F030002 - public const int slide_in_bottom = 2130903042; + // aapt resource value: 0x7F040002 + public const int slide_in_bottom = 2130968578; static Animator() { @@ -40,11 +40,27 @@ private Animator() } } + public partial class Array + { + + // aapt resource value: 0x7F110002 + public const int widths_array = 2131820546; + + static Array() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Array() + { + } + } + public partial class Dimension { - // aapt resource value: 0x7F090002 - public const int main_text_item_size = 2131296258; + // aapt resource value: 0x7F100002 + public const int main_text_item_size = 2131755010; static Dimension() { @@ -59,8 +75,8 @@ private Dimension() public partial class Drawable { - // aapt resource value: 0x7F040002 - public const int ic_menu_preferences = 2130968578; + // aapt resource value: 0x7F050002 + public const int ic_menu_preferences = 2131034114; static Drawable() { @@ -75,8 +91,8 @@ private Drawable() public partial class Font { - // aapt resource value: 0x7F050002 - public const int arial = 2131034114; + // aapt resource value: 0x7F060002 + public const int arial = 2131099650; static Font() { @@ -91,8 +107,8 @@ private Font() public partial class Id { - // aapt resource value: 0x7F060002 - public const int menu_settings = 2131099650; + // aapt resource value: 0x7F070002 + public const int menu_settings = 2131165186; static Id() { @@ -107,8 +123,8 @@ private Id() public partial class Menu { - // aapt resource value: 0x7F070002 - public const int Options = 2131165186; + // aapt resource value: 0x7F080002 + public const int Options = 2131230722; static Menu() { @@ -123,8 +139,8 @@ private Menu() public partial class Mipmap { - // aapt resource value: 0x7F080002 - public const int icon = 2131230722; + // aapt resource value: 0x7F090002 + public const int icon = 2131296258; static Mipmap() { @@ -139,8 +155,8 @@ private Mipmap() public partial class Plurals { - // aapt resource value: 0x7F020002 - public const int num_locations_reported = 2130837506; + // aapt resource value: 0x7F030002 + public const int num_locations_reported = 2130903042; static Plurals() { @@ -155,17 +171,17 @@ private Plurals() public partial class String { - // aapt resource value: 0x7F010003 - public const int app_name = 2130771971; + // aapt resource value: 0x7F020003 + public const int app_name = 2130837507; - // aapt resource value: 0x7F010005 - public const int foo = 2130771973; + // aapt resource value: 0x7F020005 + public const int foo = 2130837509; - // aapt resource value: 0x7F010002 - public const int hello = 2130771970; + // aapt resource value: 0x7F020002 + public const int hello = 2130837506; - // aapt resource value: 0x7F010004 - public const int menu_settings = 2130771972; + // aapt resource value: 0x7F020004 + public const int menu_settings = 2130837508; static String() { @@ -176,6 +192,22 @@ private String() { } } + + public partial class Transition + { + + // aapt resource value: 0x7F010002 + public const int transition = 2130771970; + + static Transition() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + + private Transition() + { + } + } } } #pragma warning restore 1591 diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManagedResourceParserTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManagedResourceParserTests.cs index c7b4a640c6d..2b5f262fc21 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManagedResourceParserTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManagedResourceParserTests.cs @@ -31,6 +31,13 @@ public class ManagedResourceParserTests : BaseTest { const string StringsXml2 = @" Hello World, Click Me! + + Thin + Thinish + Medium + Thickish + Thick + "; const string Menu = @" @@ -54,13 +61,22 @@ public class ManagedResourceParserTests : BaseTest { 17dp "; + const string Transition = @" + +"; + [Test] public void GenerateDesignerFile () { var path = Path.Combine ("temp", TestName); Directory.CreateDirectory (Path.Combine (Root, path, "res", "values")); + Directory.CreateDirectory (Path.Combine (Root, path, "res", "transition")); File.WriteAllText (Path.Combine (Root, path, "res", "values", "strings.xml"), StringsXml); + File.WriteAllText (Path.Combine (Root, path, "res", "transition", "transition.xml"), Transition); Directory.CreateDirectory (Path.Combine (Root, path, "lp", "res", "animator")); Directory.CreateDirectory (Path.Combine (Root, path, "lp", "res", "font")); diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs index 38f33eeb9c8..eee4967b3fc 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ManagedResourceParser.cs @@ -12,7 +12,7 @@ namespace Xamarin.Android.Tasks class ManagedResourceParser : ResourceParser { CodeTypeDeclaration resources; - CodeTypeDeclaration layout, ids, drawable, strings, colors, dimension, raw, animator, animation, attrib, boolean, font, ints, interpolators, menu, mipmaps, plurals, styleable, style, arrays, xml; + CodeTypeDeclaration layout, ids, drawable, strings, colors, dimension, raw, animator, animation, attrib, boolean, font, ints, interpolators, menu, mipmaps, plurals, styleable, style, arrays, xml, transition; Dictionary map; bool app; List declarationIds = new List (); @@ -56,6 +56,7 @@ public CodeTypeDeclaration Parse (string resourceDirectory, IEnumerable plurals = CreateClass ("Plurals"); styleable = CreateClass ("Styleable"); style = CreateClass ("Style"); + transition = CreateClass ("Transition"); xml = CreateClass ("Xml"); // This top most R.txt will contain EVERYTHING we need. including library resources since it represents @@ -103,6 +104,7 @@ public CodeTypeDeclaration Parse (string resourceDirectory, IEnumerable SortMembers (strings); SortMembers (style); SortMembers (styleable); + SortMembers (transition); SortMembers (xml); @@ -146,6 +148,8 @@ public CodeTypeDeclaration Parse (string resourceDirectory, IEnumerable resources.Members.Add (style); if (styleable.Members.Count > 1) resources.Members.Add (styleable); + if (transition.Members.Count > 1) + resources.Members.Add (transition); if (xml.Members.Count > 1) resources.Members.Add (xml); @@ -169,6 +173,9 @@ void ProcessRtxtFile (string file) case "attr": CreateIntField (attrib, itemName, value); break; + case "array": + CreateIntField (arrays, itemName, value); + break; case "bool": CreateIntField (boolean, itemName, value); break; @@ -225,6 +232,9 @@ void ProcessRtxtFile (string file) break; } break; + case "transition": + CreateIntField (transition, itemName, value); + break; case "xml": CreateIntField (xml, itemName, value); break; @@ -429,6 +439,9 @@ void CreateResourceField (string root, string fieldName, XmlReader element = nul case "style": CreateIntField (style, fieldName.Replace (".", "_")); break; + case "transition": + CreateIntField (transition, fieldName); + break; case "xml": CreateIntField (xml, fieldName); break;