Skip to content

Commit

Permalink
Implement rest of providers and improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaMorphic committed Dec 5, 2024
1 parent 5875aef commit 2d772a3
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 38 deletions.
17 changes: 17 additions & 0 deletions src/Android/Avalonia.Android/Automation/AutomationPeerState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.OS;
using AndroidX.Core.View.Accessibility;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;

namespace Avalonia.Android.Automation
{
internal class ExpandCollapseNodeInfoProvider : NodeInfoProvider<IExpandCollapseProvider>
{
public ExpandCollapseNodeInfoProvider(AutomationPeer peer, int virtualViewId) : base(peer, virtualViewId)
{
}

public override bool PerformNodeAction(int action, Bundle? arguments)
{
switch (action)
{
case AccessibilityNodeInfoCompat.ActionExpand:
GetProvider().Expand();
return true;
case AccessibilityNodeInfoCompat.ActionCollapse:
GetProvider().Collapse();
return true;
default:
return false;
}
}

public override void PopulateNodeInfo(AccessibilityNodeInfoCompat nodeInfo)
{
nodeInfo.AddAction(AccessibilityNodeInfoCompat.ActionExpand);
nodeInfo.AddAction(AccessibilityNodeInfoCompat.ActionCollapse);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ public InvokeNodeInfoProvider(AutomationPeer peer, int virtualViewId) : base(pee

public override bool PerformNodeAction(int action, Bundle? arguments)
{
if (action == AccessibilityNodeInfoCompat.ActionClick)
switch (action)
{
GetProvider().Invoke();
return true;
}
else
{
return false;
case AccessibilityNodeInfoCompat.ActionClick:
GetProvider().Invoke();
return true;
default:
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.OS;
using AndroidX.Core.View.Accessibility;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;

namespace Avalonia.Android.Automation
{
internal class RangeValueNodeInfoProvider : NodeInfoProvider<IRangeValueProvider>
{
public RangeValueNodeInfoProvider(AutomationPeer peer, int virtualViewId) : base(peer, virtualViewId)
{
}

public override bool PerformNodeAction(int action, Bundle? arguments)
{
return false;
}

public override void PopulateNodeInfo(AccessibilityNodeInfoCompat nodeInfo)
{
IRangeValueProvider rangeValueProvider = GetProvider();
nodeInfo.RangeInfo = new AccessibilityNodeInfoCompat.RangeInfoCompat(
AccessibilityNodeInfoCompat.RangeInfoCompat.RangeTypeFloat,
(float)rangeValueProvider.Minimum, (float)rangeValueProvider.Maximum,
(float)rangeValueProvider.Value
);
}
}
}
56 changes: 56 additions & 0 deletions src/Android/Avalonia.Android/Automation/ScrollNodeInfoProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.OS;
using AndroidX.Core.View.Accessibility;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;

namespace Avalonia.Android.Automation
{
internal class ScrollNodeInfoProvider : NodeInfoProvider<IScrollProvider>
{
public ScrollNodeInfoProvider(AutomationPeer peer, int virtualViewId) : base(peer, virtualViewId)
{
}

public override bool PerformNodeAction(int action, Bundle? arguments)
{
IScrollProvider scrollProvider = GetProvider();
switch (action)
{
case AccessibilityNodeInfoCompat.ActionScrollForward:
if (scrollProvider.VerticallyScrollable)
{
scrollProvider.Scroll(ScrollAmount.NoAmount, ScrollAmount.SmallIncrement);
}
else if(scrollProvider.HorizontallyScrollable)
{
scrollProvider.Scroll(ScrollAmount.SmallIncrement, ScrollAmount.NoAmount);
}
return true;
case AccessibilityNodeInfoCompat.ActionScrollBackward:
if (scrollProvider.VerticallyScrollable)
{
scrollProvider.Scroll(ScrollAmount.NoAmount, ScrollAmount.SmallDecrement);
}
else if (scrollProvider.HorizontallyScrollable)
{
scrollProvider.Scroll(ScrollAmount.SmallDecrement, ScrollAmount.NoAmount);
}
return true;
default:
return false;
}
}

public override void PopulateNodeInfo(AccessibilityNodeInfoCompat nodeInfo)
{
nodeInfo.AddAction(AccessibilityNodeInfoCompat.ActionScrollForward);
nodeInfo.AddAction(AccessibilityNodeInfoCompat.ActionScrollBackward);
nodeInfo.Scrollable = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Android.OS;
using AndroidX.Core.View.Accessibility;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;

namespace Avalonia.Android.Automation
{
internal class SelectionItemNodeInfoProvider : NodeInfoProvider<ISelectionItemProvider>
{
public SelectionItemNodeInfoProvider(AutomationPeer peer, int virtualViewId) : base(peer, virtualViewId)
{
}

public override bool PerformNodeAction(int action, Bundle? arguments)
{
switch (action)
{
case AccessibilityNodeInfoCompat.ActionSelect:
GetProvider().Select();
return true;
default:
return false;
}
}

public override void PopulateNodeInfo(AccessibilityNodeInfoCompat nodeInfo)
{
nodeInfo.AddAction(AccessibilityNodeInfoCompat.ActionSelect);
nodeInfo.Selected = GetProvider().IsSelected;
}
}
}
36 changes: 36 additions & 0 deletions src/Android/Avalonia.Android/Automation/ToggleNodeInfoProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Android.OS;
using AndroidX.Core.View.Accessibility;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;

namespace Avalonia.Android.Automation
{
internal class ToggleNodeInfoProvider : NodeInfoProvider<IToggleProvider>
{
public ToggleNodeInfoProvider(AutomationPeer peer, int virtualViewId) : base(peer, virtualViewId)
{
}

public override bool PerformNodeAction(int action, Bundle? arguments)
{
switch (action)
{
case AccessibilityNodeInfoCompat.ActionClick:
GetProvider().Toggle();
return true;
default:
return false;
}
}

public override void PopulateNodeInfo(AccessibilityNodeInfoCompat nodeInfo)
{
nodeInfo.AddAction(AccessibilityNodeInfoCompat.ActionClick);
nodeInfo.Clickable = true;

nodeInfo.Checked = GetProvider().ToggleState == ToggleState.On;
nodeInfo.Checkable = true;
}
}
}
41 changes: 41 additions & 0 deletions src/Android/Avalonia.Android/Automation/ValueNodeInfoProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.OS;
using AndroidX.Core.View.Accessibility;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;

namespace Avalonia.Android.Automation
{
internal class ValueNodeInfoProvider : NodeInfoProvider<IValueProvider>
{
public ValueNodeInfoProvider(AutomationPeer peer, int virtualViewId) : base(peer, virtualViewId)
{
}

public override bool PerformNodeAction(int action, Bundle? arguments)
{
switch (action)
{
case AccessibilityNodeInfoCompat.ActionSetText:
string? text = arguments?.GetCharSequence(
AccessibilityNodeInfoCompat.ActionArgumentSetTextCharsequence
);
GetProvider().SetValue(text);
return true;

default:
return false;
}
}

public override void PopulateNodeInfo(AccessibilityNodeInfoCompat nodeInfo)
{
nodeInfo.AddAction(AccessibilityNodeInfoCompat.ActionSetText);
nodeInfo.Editable = !GetProvider().IsReadOnly;
}
}
}
Loading

0 comments on commit 2d772a3

Please sign in to comment.