forked from AvaloniaUI/Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValueNodeInfoProvider.cs
59 lines (52 loc) · 1.99 KB
/
ValueNodeInfoProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Android.OS;
using AndroidX.Core.View;
using AndroidX.Core.View.Accessibility;
using AndroidX.CustomView.Widget;
using Avalonia.Automation;
using Avalonia.Automation.Peers;
using Avalonia.Automation.Provider;
namespace Avalonia.Android.Automation
{
internal class ValueNodeInfoProvider : NodeInfoProvider<IValueProvider>
{
public ValueNodeInfoProvider(ExploreByTouchHelper owner, AutomationPeer peer, int virtualViewId) :
base(owner, peer, virtualViewId)
{
}
protected override void PeerPropertyChanged(object? sender, AutomationPropertyChangedEventArgs e)
{
base.PeerPropertyChanged(sender, e);
if (e.Property == ValuePatternIdentifiers.ValueProperty)
{
InvalidateSelf(AccessibilityEventCompat.ContentChangeTypeText);
}
}
public override bool PerformNodeAction(int action, Bundle? arguments)
{
IValueProvider provider = GetProvider();
switch (action)
{
case AccessibilityNodeInfoCompat.ActionSetText:
string? text = arguments?.GetCharSequence(
AccessibilityNodeInfoCompat.ActionArgumentSetTextCharsequence
);
provider.SetValue(provider.Value + text);
return true;
default:
return false;
}
}
public override void PopulateNodeInfo(AccessibilityNodeInfoCompat nodeInfo)
{
nodeInfo.AddAction(AccessibilityNodeInfoCompat.ActionSetText);
IValueProvider provider = GetProvider();
nodeInfo.Text = provider.Value;
nodeInfo.Editable = !provider.IsReadOnly;
nodeInfo.SetTextSelection(
provider.Value?.Length ?? 0,
provider.Value?.Length ?? 0
);
nodeInfo.LiveRegion = ViewCompat.AccessibilityLiveRegionPolite;
}
}
}