public override void OnInitializeAccessibilityNodeInfo(global::Android.Views.View host, AccessibilityNodeInfoCompat info)
            {
                base.OnInitializeAccessibilityNodeInfo(host, info);

                if (Element == null)
                {
                    return;
                }

                if (info == null)
                {
                    return;
                }

                var hint = SemanticEffect.GetHint(Element);

                if (!string.IsNullOrEmpty(hint))
                {
                    info.HintText = hint;

                    if (host is EditText)
                    {
                        info.ShowingHintText = false;
                    }
                }

                var desc = SemanticEffect.GetDescription(Element);

                if (!string.IsNullOrEmpty(desc))
                {
                    info.ContentDescription = desc;
                }
            }
        protected override void Update(global::Android.Views.View view, SemanticEffectRouter effect)
        {
            var isHeading = SemanticEffect.GetHeadingLevel(Element) != CommunityToolkit.Effects.Semantic.HeadingLevel.None;

            ViewCompat.SetAccessibilityHeading(view, isHeading);
            var desc = SemanticEffect.GetDescription(Element);
            var hint = SemanticEffect.GetHint(Element);

            if (!string.IsNullOrEmpty(hint) || !string.IsNullOrEmpty(desc))
            {
                if (semanticAccessibilityDelegate == null)
                {
                    semanticAccessibilityDelegate = new SemanticAccessibilityDelegate(Element);
                    ViewCompat.SetAccessibilityDelegate(view, semanticAccessibilityDelegate);
                }
            }
            else if (semanticAccessibilityDelegate != null)
            {
                semanticAccessibilityDelegate = null;
                ViewCompat.SetAccessibilityDelegate(view, null);
            }

            if (semanticAccessibilityDelegate != null)
            {
                semanticAccessibilityDelegate.Element = Element;
                view.ImportantForAccessibility        = global::Android.Views.ImportantForAccessibility.Yes;
            }
        }
        protected override void Update(UIView view, SemanticEffectRouter effect)
        {
            var isHeading = SemanticEffect.GetHeadingLevel(Element) != CommunityToolkit.Effects.Semantic.HeadingLevel.None;

            if (isHeading)
            {
                view.AccessibilityTraits |= UIAccessibilityTrait.Header;
            }
            else
            {
                view.AccessibilityTraits &= ~UIAccessibilityTrait.Header;
            }

            var desc = SemanticEffect.GetDescription(Element);
            var hint = SemanticEffect.GetHint(Element);

            view.AccessibilityLabel = desc;
            view.AccessibilityHint  = hint;

            // UIControl elements automatically have IsAccessibilityElement set to true
            if (view is not UIControl && (!string.IsNullOrWhiteSpace(hint) || !string.IsNullOrWhiteSpace(desc)))
            {
                view.IsAccessibilityElement = true;
            }
        }
Ejemplo n.º 4
0
        protected override void Update(FrameworkElement view, SemanticEffectRouter effect)
        {
            var headingLevel = (AutomationHeadingLevel)((int)SemanticEffect.GetHeadingLevel(Element));

            AutomationProperties.SetHeadingLevel(view, headingLevel);

            AutomationProperties.SetName(view, SemanticEffect.GetDescription(Element) ?? string.Empty);
            AutomationProperties.SetHelpText(view, SemanticEffect.GetHint(Element) ?? string.Empty);
        }
Ejemplo n.º 5
0
        protected override void Update(UIView view, A11YTools.NativeSemanticEffect effect)
        {
            bool isHeading = SemanticEffect.GetIsHeading(Element);

            if (isHeading)
            {
                view.AccessibilityTraits |= UIAccessibilityTrait.Header;
            }
            else
            {
                view.AccessibilityTraits &= ~UIAccessibilityTrait.Header;
            }
        }
        protected override void Update(global::Android.Views.View view, SemanticEffectRouter effect)
        {
            var isHeading = SemanticEffect.GetHeadingLevel(Element) != CommunityToolkit.Effects.Semantic.HeadingLevel.None;

            ViewCompat.SetAccessibilityHeading(view, isHeading);

            var a11yVisibility = SemanticEffect.GetSemanticInclusion(Element);

            switch (a11yVisibility)
            {
            case SemanticInclusion.Default:
                ViewCompat.SetImportantForAccessibility(view, ViewCompat.ImportantForAccessibilityAuto);
                break;

            case SemanticInclusion.Include:
                ViewCompat.SetImportantForAccessibility(view, ViewCompat.ImportantForAccessibilityYes);
                break;

            case SemanticInclusion.Exclude:
                ViewCompat.SetImportantForAccessibility(view, ViewCompat.ImportantForAccessibilityNo);
                break;

            case SemanticInclusion.ExcludeWithChildren:
                ViewCompat.SetImportantForAccessibility(view, ViewCompat.ImportantForAccessibilityNoHideDescendants);
                break;
            }

            var desc = SemanticEffect.GetDescription(Element);
            var hint = SemanticEffect.GetHint(Element);

            if (!string.IsNullOrWhiteSpace(hint) || !string.IsNullOrWhiteSpace(desc))
            {
                if (semanticAccessibilityDelegate == null)
                {
                    semanticAccessibilityDelegate = new SemanticAccessibilityDelegate(Element);
                    ViewCompat.SetAccessibilityDelegate(view, semanticAccessibilityDelegate);
                }
            }
            else if (semanticAccessibilityDelegate != null)
            {
                semanticAccessibilityDelegate = null;
                ViewCompat.SetAccessibilityDelegate(view, null);
            }

            if (semanticAccessibilityDelegate != null)
            {
                semanticAccessibilityDelegate.Element = Element;
                view.ImportantForAccessibility        = global::Android.Views.ImportantForAccessibility.Yes;
            }
        }
Ejemplo n.º 7
0
        protected override void Update(UIView view, SemanticEffectRouter effect)
        {
            var isHeading = SemanticEffect.GetHeadingLevel(Element) != CommunityToolkit.Effects.Semantic.HeadingLevel.None;

            if (isHeading)
            {
                view.AccessibilityTraits |= UIAccessibilityTrait.Header;
            }
            else
            {
                view.AccessibilityTraits &= ~UIAccessibilityTrait.Header;
            }

            var semanticInclusion = SemanticEffect.GetSemanticInclusion(Element);

            switch (semanticInclusion)
            {
            case SemanticInclusion.Default:
                view.IsAccessibilityElement      = view is UIControl;
                view.AccessibilityElementsHidden = false;
                break;

            case SemanticInclusion.Include:
                view.IsAccessibilityElement      = true;
                view.AccessibilityElementsHidden = false;
                break;

            case SemanticInclusion.Exclude:
                view.IsAccessibilityElement      = false;
                view.AccessibilityElementsHidden = false;
                break;

            case SemanticInclusion.ExcludeWithChildren:
                view.IsAccessibilityElement      = false;
                view.AccessibilityElementsHidden = true;
                break;
            }

            var desc = SemanticEffect.GetDescription(Element);
            var hint = SemanticEffect.GetHint(Element);

            view.AccessibilityLabel = desc;
            view.AccessibilityHint  = hint;

            // UIControl elements automatically have IsAccessibilityElement set to true
            if (view is not UIControl && (!string.IsNullOrWhiteSpace(hint) || !string.IsNullOrWhiteSpace(desc)))
            {
                view.IsAccessibilityElement = true;
            }
        }
            public override void OnInitializeAccessibilityNodeInfo(global::Android.Views.View host, AccessibilityNodeInfoCompat info)
            {
                base.OnInitializeAccessibilityNodeInfo(host, info);

                if (Element == null)
                {
                    return;
                }

                if (info == null)
                {
                    return;
                }

                string?newText = null;
                string?newContentDescription = null;

                var desc = SemanticEffect.GetDescription(Element);

                if (!string.IsNullOrEmpty(desc))
                {
                    // Edit Text fields won't read anything for the content description
                    if (host is EditText et)
                    {
                        if (!string.IsNullOrEmpty(et.Text))
                        {
                            newText = $"{desc}, {et.Text}";
                        }
                        else
                        {
                            newText = $"{desc}";
                        }
                    }
                    else
                    {
                        newContentDescription = desc;
                    }
                }

                var hint = SemanticEffect.GetHint(Element);

                if (!string.IsNullOrEmpty(hint))
                {
                    // info HintText won't read anything back when using TalkBack pre API 26
                    if (XCT.SdkInt >= (int)BuildVersionCodes.O)
                    {
                        info.HintText = hint;

                        if (host is EditText)
                        {
                            info.ShowingHintText = false;
                        }
                    }
                    else
                    {
                        if (host is EditText et)
                        {
                            newText = newText ?? et.Text;
                            newText = $"{newText}, {hint}";
                        }
                        else if (host is TextView tv)
                        {
                            if (newContentDescription != null)
                            {
                                newText = $"{newContentDescription}, {hint}";
                            }
                            else if (!string.IsNullOrEmpty(tv.Text))
                            {
                                newText = $"{tv.Text}, {hint}";
                            }
                            else
                            {
                                newText = $"{hint}";
                            }
                        }
                        else
                        {
                            if (newContentDescription != null)
                            {
                                newText = $"{newContentDescription}, {hint}";
                            }
                            else
                            {
                                newText = $"{hint}";
                            }
                        }

                        newContentDescription = null;
                    }
                }

                if (!string.IsNullOrWhiteSpace(newContentDescription))
                {
                    info.ContentDescription = newContentDescription;
                }

                if (!string.IsNullOrWhiteSpace(newText))
                {
                    info.Text = newText;
                }
            }
Ejemplo n.º 9
0
        protected override void Update(Android.Views.View view, A11YTools.NativeSemanticEffect effect)
        {
            bool isHeading = SemanticEffect.GetIsHeading(Element);

            ViewCompat.SetAccessibilityHeading(view, isHeading);
        }
Ejemplo n.º 10
0
 void ExcludeButton_Clicked(object sender, System.EventArgs e)
 {
     SemanticEffect.SetSemanticInclusion(semanticInclusionSampleLayout, SemanticInclusion.ExcludeWithChildren);
 }