diff --git a/src/Android/Avalonia.Android/Automation/AutomationPeerExtensions.cs b/src/Android/Avalonia.Android/Automation/AutomationPeerExtensions.cs deleted file mode 100644 index 3e1a4693ebf..00000000000 --- a/src/Android/Avalonia.Android/Automation/AutomationPeerExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Avalonia.Automation.Peers; - -namespace Avalonia.Android.Automation -{ - public static class AutomationPeerExtensions - { - public static IEnumerable GetAllDescendants(this AutomationPeer thisPeer) - { - yield return thisPeer; - - foreach (AutomationPeer otherPeer in thisPeer.GetChildren().SelectMany(GetAllDescendants)) - { - yield return otherPeer; - } - } - } -} diff --git a/src/Android/Avalonia.Android/Automation/AutomationPeerState.cs b/src/Android/Avalonia.Android/Automation/AutomationPeerState.cs deleted file mode 100644 index fa08ceb433a..00000000000 --- a/src/Android/Avalonia.Android/Automation/AutomationPeerState.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Avalonia.Automation.Peers; - -namespace Avalonia.Android.Automation -{ - internal class AutomationPeerState - { - public AutomationPeer Instance { get; } - - public bool IsOffscreenCached { get; set; } - - public AutomationPeerState(AutomationPeer instance) - { - Instance = instance; - IsOffscreenCached = instance.IsOffscreen(); - } - } -} diff --git a/src/Android/Avalonia.Android/Automation/ExpandCollapseNodeInfoProvider.cs b/src/Android/Avalonia.Android/Automation/ExpandCollapseNodeInfoProvider.cs index d8fc5e0eb60..971575a13f4 100644 --- a/src/Android/Avalonia.Android/Automation/ExpandCollapseNodeInfoProvider.cs +++ b/src/Android/Avalonia.Android/Automation/ExpandCollapseNodeInfoProvider.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Android.OS; +using Android.OS; using AndroidX.Core.View.Accessibility; using Avalonia.Automation.Peers; using Avalonia.Automation.Provider; diff --git a/src/Android/Avalonia.Android/Automation/RangeValueNodeInfoProvider.cs b/src/Android/Avalonia.Android/Automation/RangeValueNodeInfoProvider.cs index f855bb9a87e..451849c196e 100644 --- a/src/Android/Avalonia.Android/Automation/RangeValueNodeInfoProvider.cs +++ b/src/Android/Avalonia.Android/Automation/RangeValueNodeInfoProvider.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Android.OS; +using Android.OS; using AndroidX.Core.View.Accessibility; using Avalonia.Automation.Peers; using Avalonia.Automation.Provider; diff --git a/src/Android/Avalonia.Android/Automation/ScrollNodeInfoProvider.cs b/src/Android/Avalonia.Android/Automation/ScrollNodeInfoProvider.cs index 6193fd3a825..b13e793c6c3 100644 --- a/src/Android/Avalonia.Android/Automation/ScrollNodeInfoProvider.cs +++ b/src/Android/Avalonia.Android/Automation/ScrollNodeInfoProvider.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Android.OS; +using Android.OS; using AndroidX.Core.View.Accessibility; using Avalonia.Automation.Peers; using Avalonia.Automation.Provider; diff --git a/src/Android/Avalonia.Android/Automation/ToggleNodeInfoProvider.cs b/src/Android/Avalonia.Android/Automation/ToggleNodeInfoProvider.cs index 07d26bb64ec..584941bbeb9 100644 --- a/src/Android/Avalonia.Android/Automation/ToggleNodeInfoProvider.cs +++ b/src/Android/Avalonia.Android/Automation/ToggleNodeInfoProvider.cs @@ -1,5 +1,4 @@ -using System; -using Android.OS; +using Android.OS; using AndroidX.Core.View.Accessibility; using Avalonia.Automation.Peers; using Avalonia.Automation.Provider; diff --git a/src/Android/Avalonia.Android/Automation/ValueNodeInfoProvider.cs b/src/Android/Avalonia.Android/Automation/ValueNodeInfoProvider.cs index f2248c65636..aa5a2b4058f 100644 --- a/src/Android/Avalonia.Android/Automation/ValueNodeInfoProvider.cs +++ b/src/Android/Avalonia.Android/Automation/ValueNodeInfoProvider.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Android.OS; +using Android.OS; using AndroidX.Core.View.Accessibility; using Avalonia.Automation.Peers; using Avalonia.Automation.Provider; diff --git a/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs b/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs index a4f81afa83d..3ec51aca493 100644 --- a/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs +++ b/src/Android/Avalonia.Android/AvaloniaAccessHelper.cs @@ -1,17 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; using Android.OS; -using Android.Runtime; using AndroidX.Core.View.Accessibility; using AndroidX.CustomView.Widget; using Avalonia.Android.Automation; using Avalonia.Automation.Peers; using Avalonia.Automation.Provider; -using Avalonia.Threading; using Java.Lang; -using Java.Nio.Channels; namespace Avalonia.Android { @@ -30,8 +26,8 @@ private static readonly IReadOnlyDictionary }; private readonly Dictionary _peers; - private readonly Dictionary _peerStates; private readonly Dictionary _peerIds; + private readonly Dictionary> _peerNodeInfoProviders; private readonly AvaloniaView _view; @@ -39,8 +35,6 @@ private static readonly IReadOnlyDictionary public AvaloniaAccessHelper(AvaloniaView view) : base(view) { _peers = []; - _peerStates = []; - _peerIds = []; _peerNodeInfoProviders = []; @@ -78,10 +72,9 @@ private HashSet GetOrCreateNodeInfoProvidersFromPeer(Automati { peerViewId = _peerNodeInfoProviders.Count; _peers.Add(peerViewId, peer); - _peerStates.Add(peerViewId, new(peer)); + _peerIds.Add(peer, peerViewId); nodeInfoProviders = new(); - _peerIds.Add(peer, peerViewId); _peerNodeInfoProviders.Add(peer, nodeInfoProviders); peer.PropertyChanged += (s, ev) => InvalidateVirtualView(peerViewId, @@ -148,15 +141,17 @@ protected override void OnPopulateNodeForVirtualView(int virtualViewId, Accessib { if (!_peers.TryGetValue(virtualViewId, out AutomationPeer? peer)) { - return; + return; // BAIL!! No work to be done } + // UI logical structure foreach (AutomationPeer child in peer.GetChildren()) { GetOrCreateNodeInfoProvidersFromPeer(child, out int childId); nodeInfo.AddChild(_view, childId); } + // UI labeling AutomationPeer? labeledBy = peer.GetLabeledBy(); if (labeledBy is not null) { @@ -164,12 +159,16 @@ protected override void OnPopulateNodeForVirtualView(int virtualViewId, Accessib nodeInfo.SetLabeledBy(_view.TopLevelImpl.View, labeledById); } + // UI text contents nodeInfo.Text = peer.GetName(); + nodeInfo.ContentDescription = peer.GetHelpText(); + + // UI metadata nodeInfo.ClassName = peer.GetClassName(); nodeInfo.Enabled = peer.IsEnabled(); - nodeInfo.Focusable = !peer.IsOffscreen() && peer.IsContentElement(); - nodeInfo.HintText = peer.GetHelpText(); + nodeInfo.Focusable = peer.IsContentElement() && !peer.IsOffscreen(); + // On-screen bounds Rect bounds = peer.GetBoundingRectangle(); PixelRect screenRect = new PixelRect( _view.TopLevelImpl.PointToScreen(bounds.TopLeft), @@ -180,6 +179,7 @@ protected override void OnPopulateNodeForVirtualView(int virtualViewId, Accessib screenRect.Right, screenRect.Bottom )); + // UI provider specifics foreach (INodeInfoProvider nodeInfoProvider in _peerNodeInfoProviders[peer]) { nodeInfoProvider.PopulateNodeInfo(nodeInfo); diff --git a/src/Android/Avalonia.Android/ISSUE.txt b/src/Android/Avalonia.Android/ISSUE.txt deleted file mode 100644 index 6ca2ea6d272..00000000000 --- a/src/Android/Avalonia.Android/ISSUE.txt +++ /dev/null @@ -1,10 +0,0 @@ -## Android Accessibility Features Aren't Implemented - -Hello Avalonia team! I'm opening this issue to discuss the possiblity of using the -Android ExploreByTouchHelper class in conjunction with the AutomationPeer API in Avalonia in -order to add support for Android UI automation and accessiblity features. - -Thoughts? - -Thanks, -Isabelle Santin