Skip to content

Commit bbcc3ba

Browse files
[android] fix Android namespace conflicts
Context: dotnet/android#9973 We introduced a new `internal` type in `Mono.Android.dll`: namespace Microsoft.Android.Runtime; class ManagedValueManager : JniRuntime.JniValueManager Causes various C# compiler errors in dotnet/maui: D:\src\maui\src\Essentials\src\AppActions\AppActions.shared.cs(62,28): error CS0234: The type or namespace name 'Content' does not exist in the namespace 'Microsoft.Android' (are you missing an assembly reference?) At some point in .NET 10 (or future), we will likely introduce a *public* type in `Microsoft.Android` namespace. This means MAUI's codebase will need to be fixed in a .NET 10 timeframe, so instead of: Android.Content.Context content; This works: using Android.Content; //... Context content; Because the `using Android.Content;` directive is scoped *outside* of a `Microsoft.*` namespace. We don't anticipate this to be a problem with customers, because they aren't writing code in `Microsoft.*` namespaces. I generally took the approach: * Use `using Android.Content;` if possible. * Use `global::` if that caused other conflicts. * Use `using AView = Android.Views.View;` in Microsoft.Maui.Controls or other places this is commonly used. * Update `#if __ANDROID__` to `#if ANDROID` in a few places.
1 parent ce8ab8f commit bbcc3ba

File tree

53 files changed

+249
-151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+249
-151
lines changed

src/BlazorWebView/src/Maui/Android/BlazorWebChromeClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Components.WebView.Maui
1414
{
1515
class BlazorWebChromeClient : WebChromeClient
1616
{
17-
public override bool OnCreateWindow(Android.Webkit.WebView? view, bool isDialog, bool isUserGesture, Message? resultMsg)
17+
public override bool OnCreateWindow(global::Android.Webkit.WebView? view, bool isDialog, bool isUserGesture, Message? resultMsg)
1818
{
1919
if (view?.Context is not null)
2020
{
@@ -29,7 +29,7 @@ public override bool OnCreateWindow(Android.Webkit.WebView? view, bool isDialog,
2929
return false;
3030
}
3131

32-
public override bool OnShowFileChooser(Android.Webkit.WebView? view, IValueCallback? filePathCallback, FileChooserParams? fileChooserParams)
32+
public override bool OnShowFileChooser(global::Android.Webkit.WebView? view, IValueCallback? filePathCallback, FileChooserParams? fileChooserParams)
3333
{
3434
if (filePathCallback is null)
3535
{

src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Threading.Tasks;
33
using Android.Webkit;
4+
using Android.Widget;
45
using Microsoft.Extensions.DependencyInjection;
56
using Microsoft.Extensions.FileProviders;
67
using Microsoft.Extensions.Logging;
@@ -32,7 +33,7 @@ protected override AWebView CreatePlatformView()
3233
var blazorAndroidWebView = new BlazorAndroidWebView(Context!)
3334
{
3435
#pragma warning disable 618 // This can probably be replaced with LinearLayout(LayoutParams.MatchParent, LayoutParams.MatchParent); just need to test that theory
35-
LayoutParameters = new Android.Widget.AbsoluteLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent, 0, 0)
36+
LayoutParameters = new AbsoluteLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent, 0, 0)
3637
#pragma warning restore 618
3738
};
3839
#pragma warning restore CA1416, CA1412, CA1422 // Validate platform compatibility

src/Controls/src/Core/Cells/Cell.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void OnParentPropertyChanging(object sender, PropertyChangingEventArgs e)
312312
// This is used by ListView to pass data to the GetCell call
313313
// Ideally we can pass these as arguments to ToHandler
314314
// But we'll do that in a different smaller more targeted PR
315-
internal Android.Views.View ConvertView { get; set; }
315+
internal global::Android.Views.View ConvertView { get; set; }
316316
#elif IOS
317317
internal UIKit.UITableViewCell ReusableCell { get; set; }
318318

src/Controls/src/Core/Compatibility/Handlers/VisualElementRenderer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#if WINDOWS
1010
using PlatformView = Microsoft.UI.Xaml.FrameworkElement;
1111
#elif ANDROID
12+
using Android.Content;
1213
using PlatformView = Android.Views.View;
1314
#elif IOS
1415
using PlatformView = UIKit.UIView;
@@ -64,7 +65,7 @@ public abstract partial class VisualElementRenderer<TElement> : IPlatformViewHan
6465
protected bool AutoPackage { get; set; } = true;
6566

6667
#if ANDROID
67-
public VisualElementRenderer(Android.Content.Context context) : this(context, VisualElementRendererMapper, VisualElementRendererCommandMapper)
68+
public VisualElementRenderer(Context context) : this(context, VisualElementRendererMapper, VisualElementRendererCommandMapper)
6869
{
6970
}
7071
#else
@@ -75,7 +76,7 @@ public VisualElementRenderer() : this(VisualElementRendererMapper, VisualElement
7576

7677

7778
#if ANDROID
78-
protected VisualElementRenderer(Android.Content.Context context, IPropertyMapper mapper, CommandMapper? commandMapper = null)
79+
protected VisualElementRenderer(Context context, IPropertyMapper mapper, CommandMapper? commandMapper = null)
7980
#else
8081
protected VisualElementRenderer(IPropertyMapper mapper, CommandMapper? commandMapper = null)
8182
#endif

src/Controls/src/Core/DragAndDrop/PlatformDragEventArgs.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
using System;
2+
#if ANDROID
3+
using Android.Views;
4+
using AView = Android.Views.View;
5+
#endif
6+
27
namespace Microsoft.Maui.Controls;
38

49
/// <summary>
@@ -49,14 +54,14 @@ public void SetDropProposal(UIKit.UIDropProposal dropProposal)
4954
/// <summary>
5055
/// Gets the native view attached to the event.
5156
/// </summary>
52-
public Android.Views.View Sender { get; }
57+
public AView Sender { get; }
5358

5459
/// <summary>
5560
/// Gets the event containing information for drag and drop status.
5661
/// </summary>
57-
public Android.Views.DragEvent DragEvent { get; }
62+
public DragEvent DragEvent { get; }
5863

59-
internal PlatformDragEventArgs(Android.Views.View sender, Android.Views.DragEvent dragEvent)
64+
internal PlatformDragEventArgs(AView sender, DragEvent dragEvent)
6065
{
6166
Sender = sender;
6267
DragEvent = dragEvent;

src/Controls/src/Core/DragAndDrop/PlatformDragStartingEventArgs.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
using System;
22

3+
#if ANDROID
4+
using Android.Content;
5+
using Android.Views;
6+
using DragShadowBuilder = Android.Views.View.DragShadowBuilder;
7+
using AView = Android.Views.View;
8+
#endif
9+
310
namespace Microsoft.Maui.Controls;
411

512
/// <summary>
@@ -91,19 +98,19 @@ public void SetPrefersFullSizePreviews(Func<UIKit.UIDragInteraction, UIKit.IUIDr
9198
/// <summary>
9299
/// Gets the native view attached to the event.
93100
/// </summary>
94-
public Android.Views.View Sender { get; }
101+
public AView Sender { get; }
95102

96103
/// <summary>
97104
/// Gets the event containing information for drag and drop status.
98105
/// </summary>
99-
public Android.Views.MotionEvent MotionEvent { get; }
106+
public MotionEvent MotionEvent { get; }
100107

101-
internal Android.Views.View.DragShadowBuilder? DragShadowBuilder { get; private set; }
102-
internal Android.Content.ClipData? ClipData { get; private set; }
108+
internal DragShadowBuilder? DragShadowBuilder { get; private set; }
109+
internal ClipData? ClipData { get; private set; }
103110
internal Java.Lang.Object? LocalData { get; private set; }
104-
internal Android.Views.DragFlags? DragFlags { get; private set; }
111+
internal DragFlags? DragFlags { get; private set; }
105112

106-
internal PlatformDragStartingEventArgs(Android.Views.View sender, Android.Views.MotionEvent motionEvent)
113+
internal PlatformDragStartingEventArgs(AView sender, MotionEvent motionEvent)
107114
{
108115
Sender = sender;
109116
MotionEvent = motionEvent;
@@ -113,7 +120,7 @@ internal PlatformDragStartingEventArgs(Android.Views.View sender, Android.Views.
113120
/// Sets the drag shadow when dragging begins.
114121
/// </summary>
115122
/// <param name="dragShadowBuilder">The custom drag shadow builder to use.</param>
116-
public void SetDragShadowBuilder(Android.Views.View.DragShadowBuilder dragShadowBuilder)
123+
public void SetDragShadowBuilder(DragShadowBuilder dragShadowBuilder)
117124
{
118125
DragShadowBuilder = dragShadowBuilder;
119126
}
@@ -122,7 +129,7 @@ public void SetDragShadowBuilder(Android.Views.View.DragShadowBuilder dragShadow
122129
/// Sets the clip data when dragging begins.
123130
/// </summary>
124131
/// <param name="clipData">The custom clip data to use.</param>
125-
public void SetClipData(Android.Content.ClipData clipData)
132+
public void SetClipData(ClipData clipData)
126133
{
127134
ClipData = clipData;
128135
}
@@ -140,7 +147,7 @@ public void SetLocalData(Java.Lang.Object localData)
140147
/// Sets the drag flags when dragging begins.
141148
/// </summary>
142149
/// <param name="dragFlags">The custom drag flags to use.</param>
143-
public void SetDragFlags(Android.Views.DragFlags dragFlags)
150+
public void SetDragFlags(DragFlags dragFlags)
144151
{
145152
DragFlags = dragFlags;
146153
}

src/Controls/src/Core/DragAndDrop/PlatformDropCompletedEventArgs.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
using System;
2+
3+
#if ANDROID
4+
using Android.Views;
5+
using AView = Android.Views.View;
6+
#endif
7+
28
namespace Microsoft.Maui.Controls;
39

410
/// <summary>
@@ -73,14 +79,14 @@ internal PlatformDropCompletedEventArgs(UIKit.UIView? sender, UIKit.UIDropIntera
7379
/// <summary>
7480
/// Gets the native view attached to the event.
7581
/// </summary>
76-
public Android.Views.View Sender { get; }
82+
public AView Sender { get; }
7783

7884
/// <summary>
7985
/// Gets the event containing information for drag and drop status.
8086
/// </summary>
81-
public Android.Views.DragEvent DragEvent { get; }
87+
public DragEvent DragEvent { get; }
8288

83-
internal PlatformDropCompletedEventArgs(Android.Views.View sender, Android.Views.DragEvent dragEvent)
89+
internal PlatformDropCompletedEventArgs(AView sender, DragEvent dragEvent)
8490
{
8591
Sender = sender;
8692
DragEvent = dragEvent;

src/Controls/src/Core/DragAndDrop/PlatformDropEventArgs.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
using System;
22

3+
#if ANDROID
4+
using Android.Views;
5+
using AView = Android.Views.View;
6+
#endif
7+
38
namespace Microsoft.Maui.Controls;
49

510
/// <summary>
@@ -35,14 +40,14 @@ internal PlatformDropEventArgs(UIKit.UIView? sender, UIKit.UIDropInteraction dro
3540
/// <summary>
3641
/// Gets the native view attached to the event.
3742
/// </summary>
38-
public Android.Views.View Sender { get; }
43+
public AView Sender { get; }
3944

4045
/// <summary>
4146
/// Gets the event containing information for drag and drop status.
4247
/// </summary>
43-
public Android.Views.DragEvent DragEvent { get; }
48+
public DragEvent DragEvent { get; }
4449

45-
internal PlatformDropEventArgs(Android.Views.View sender, Android.Views.DragEvent dragEvent)
50+
internal PlatformDropEventArgs(AView sender, DragEvent dragEvent)
4651
{
4752
Sender = sender;
4853
DragEvent = dragEvent;

src/Controls/src/Core/Element/Element.Android.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Maui.Controls.Platform;
2+
using AView = Android.Views.View;
23

34
namespace Microsoft.Maui.Controls
45
{
@@ -7,13 +8,13 @@ public partial class Element
78
public static void MapAutomationPropertiesIsInAccessibleTree(IElementHandler handler, Element element)
89
{
910
Platform.AutomationPropertiesProvider.SetImportantForAccessibility(
10-
handler.PlatformView as Android.Views.View, element);
11+
handler.PlatformView as AView, element);
1112
}
1213

1314
public static void MapAutomationPropertiesExcludedWithChildren(IElementHandler handler, Element element)
1415
{
1516
Platform.AutomationPropertiesProvider.SetImportantForAccessibility(
16-
handler.PlatformView as Android.Views.View, element);
17+
handler.PlatformView as AView, element);
1718
}
1819

1920
static void MapAutomationPropertiesIsInAccessibleTree(IElementHandler handler, IElement element)

src/Controls/src/Core/Embedding/EmbeddingExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static class EmbeddingExtensions
3737
internal static MauiAppBuilder UseMauiEmbedding(this MauiAppBuilder builder)
3838
{
3939
#if ANDROID
40-
var platformApplication = (Android.App.Application)Android.App.Application.Context;
40+
var platformApplication = (global::Android.App.Application)global::Android.App.Application.Context;
4141
#elif IOS || MACCATALYST
4242
var platformApplication = UIKit.UIApplication.SharedApplication.Delegate;
4343
#elif WINDOWS

0 commit comments

Comments
 (0)