Skip to content

Commit a638773

Browse files
authored
[Xamarin.Android.Build.Task] Handle res-auto headerLayout (#3531)
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/969915 Certain android resource items can make use of the following namespace xmlns:app=""http://schemas.android.com/apk/res-auto"" this provides additional extension attributes which need to be fixed up. Some examples are `actionLayout`, `rectLayout` and `roundLayout`. The values for these attributes should be lowercased as they refer to a `@layout` item. It seems however that this list is always expanding. A new item `headerLayout` seems to have appeared. Rather than handcoding each of these items, the code here changes to check for `Layout` in the attrbiute and will then lowercase the value. This should protect us from future "additions", and help our customers since they won't have to work around casing problems for attributes we do not support.
1 parent 9ee2d2b commit a638773

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/AndroidResourceTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,37 @@ namespace Xamarin.Android.Build.Tests {
1313
[TestFixture]
1414
[Parallelizable (ParallelScope.Self)]
1515
public class AndroidResourceTests : BaseTest {
16+
[Test]
17+
public void HeaderLayout ()
18+
{
19+
var path = Path.Combine (Root, "temp", TestName);
20+
Directory.CreateDirectory (path);
21+
var layoutDir = Path.Combine (path, "res", "layout");
22+
var menuDir = Path.Combine (path, "res", "menu");
23+
Directory.CreateDirectory (layoutDir);
24+
Directory.CreateDirectory (menuDir);
25+
var main = Path.Combine (layoutDir, "main.xml");
26+
File.WriteAllText (main, @"<?xml version=""1.0"" encoding=""utf-8""?>
27+
<LinearLayout xmlns:android=""http://schemas.android.com/apk/res/android""
28+
xmlns:app=""http://schemas.android.com/apk/res-auto""
29+
android:orientation = ""horizontal""
30+
android:layout_width = ""match_parent""
31+
android:layout_height = ""match_parent""
32+
app:headerLayout=""@layout/headerLayout""
33+
>
34+
</LinearLayout>");
35+
36+
var headerLayout = Path.Combine (layoutDir, "headerlayout.xml");
37+
File.WriteAllText (headerLayout, @"<?xml version=""1.0"" encoding=""utf-8""?>
38+
<LinearLayout>
39+
</LinearLayout>
40+
");
41+
Monodroid.AndroidResource.UpdateXmlResource (Path.Combine (path, "res"), main, new Dictionary<string, string> (), null);
42+
var mainText = File.ReadAllText (main);
43+
Assert.True (mainText.Contains ("@layout/headerlayout"), "'@layout/headerLayout' was not converted to '@layout/headerlayout'");
44+
Directory.Delete (path, recursive: true);
45+
}
46+
1647
[Test]
1748
public void MenuActionLayout ()
1849
{

src/Xamarin.Android.Build.Tasks/Utilities/AndroidResource.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ private static bool TryFixResAuto (XAttribute attr, Dictionary<string, string> a
201201
{
202202
if (attr.Name.Namespace != res_auto)
203203
return false;
204-
switch (attr.Name.LocalName) {
205-
case "rectLayout":
206-
case "roundLayout":
207-
case "actionLayout":
204+
if (attr.Name.LocalName.EndsWith ("Layout", StringComparison.Ordinal)) {
208205
attr.Value = attr.Value.ToLowerInvariant ();
209206
return true;
210207
}

0 commit comments

Comments
 (0)