Skip to content

Commit

Permalink
Get better readouts
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaMorphic committed Dec 5, 2024
1 parent 6a71fa1 commit 5875aef
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/Android/Avalonia.Android/AvaloniaAccessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Avalonia.Android.Automation;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;
using Avalonia.Controls.Automation.Peers;
using Java.Lang;

namespace Avalonia.Android
Expand Down Expand Up @@ -90,15 +91,17 @@ private HashSet<INodeInfoProvider> GetOrCreateNodeInfoProvidersFromPeer(Automati
protected override int GetVirtualViewAt(float x, float y)
{
Point p = _view.TopLevelImpl.PointToClient(new PixelPoint((int)x, (int)y));
AutomationPeer? peer = _peers[0].GetProvider<IEmbeddedRootProvider>()?.GetPeerFromPoint(p);
IEmbeddedRootProvider? embeddedRootProvider = _peers[0].GetProvider<IEmbeddedRootProvider>();
AutomationPeer? peer = embeddedRootProvider?.GetPeerFromPoint(p);
if (peer is not null)
{
GetOrCreateNodeInfoProvidersFromPeer(peer, out int virtualViewId);
return virtualViewId;
return virtualViewId == 0 ? InvalidId : virtualViewId;
}
else
{
return InvalidId;
peer = embeddedRootProvider?.GetFocus();
return peer is null ? InvalidId : _peerIds[peer];
}
}

Expand All @@ -109,7 +112,8 @@ protected override void GetVisibleVirtualViews(IList<Integer>? virtualViewIds)
return;
}

foreach (AutomationPeer peer in _peers[0].GetAllDescendants().Where(x => x is not NoneAutomationPeer && !x.IsOffscreen()))
foreach (AutomationPeer peer in _peers[0].GetAllDescendants()
.Where(x => x is not NoneAutomationPeer && !x.IsOffscreen()))
{
GetOrCreateNodeInfoProvidersFromPeer(peer, out int virtualViewId);
virtualViewIds.Add(Integer.ValueOf(virtualViewId));
Expand All @@ -130,12 +134,6 @@ protected override void OnPopulateNodeForVirtualView(int virtualViewId, Accessib
return;
}

nodeInfo.Text = peer.GetName();
nodeInfo.ClassName = peer.GetClassName();
nodeInfo.Enabled = peer.IsEnabled();
nodeInfo.Focusable = peer.IsKeyboardFocusable();
nodeInfo.HintText = peer.GetHelpText();

nodeInfo.SetParent(_view, HostId);

AutomationPeer? labeledBy = peer.GetLabeledBy();
Expand All @@ -145,6 +143,12 @@ protected override void OnPopulateNodeForVirtualView(int virtualViewId, Accessib
nodeInfo.SetLabeledBy(_view.TopLevelImpl.View, labeledById);
}

nodeInfo.Text = peer.GetName() ?? labeledBy?.GetName();
nodeInfo.ClassName = peer.GetClassName();
nodeInfo.Enabled = peer.IsEnabled();
nodeInfo.Focusable = peer.IsControlElement();
nodeInfo.HintText = peer.GetHelpText();

Rect bounds = peer.GetBoundingRectangle();
PixelRect screenRect = new(
_view.TopLevelImpl.PointToScreen(bounds.TopLeft),
Expand Down

0 comments on commit 5875aef

Please sign in to comment.