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;
            }
        }
Example #2
0
        static partial void MappingSemantics(IViewHandler handler, IView view)
        {
            if (handler.PlatformView == null)
            {
                return;
            }

            AccessibilityDelegateCompat?accessibilityDelegate = null;

            if (handler.PlatformView is View viewPlatform)
            {
                accessibilityDelegate = ViewCompat.GetAccessibilityDelegate(viewPlatform) as MauiAccessibilityDelegateCompat;
            }

            if (handler.PlatformView is not PlatformView platformView)
            {
                return;
            }

            platformView = platformView.GetSemanticPlatformElement();

            var desc = view.Semantics?.Description;
            var hint = view.Semantics?.Hint;

            // We use MauiAccessibilityDelegateCompat to fix the issue of AutomationId breaking accessibility
            // Because AutomationId gets set on the contentDesc we have to clear that out on the accessibility node via
            // the use of our MauiAccessibilityDelegateCompat
            if (!string.IsNullOrWhiteSpace(hint) ||
                !string.IsNullOrWhiteSpace(desc) ||
                !string.IsNullOrWhiteSpace(view.AutomationId))
            {
                if (accessibilityDelegate == null)
                {
                    var currentDelegate = ViewCompat.GetAccessibilityDelegate(platformView);
                    if (currentDelegate is MauiAccessibilityDelegateCompat)
                    {
                        currentDelegate = null;
                    }

                    accessibilityDelegate = new MauiAccessibilityDelegateCompat(currentDelegate)
                    {
                        Handler = handler
                    };

                    ViewCompat.SetAccessibilityDelegate(platformView, accessibilityDelegate);
                }

                if (!string.IsNullOrWhiteSpace(hint) ||
                    !string.IsNullOrWhiteSpace(desc))
                {
                    platformView.ImportantForAccessibility = ImportantForAccessibility.Yes;
                }
            }
            else if (accessibilityDelegate != null)
            {
                ViewCompat.SetAccessibilityDelegate(platformView, null);
            }
        }
Example #3
0
 partial void DisconnectingHandler(NativeView nativeView)
 {
     if (nativeView.IsAlive() &&
         ViewCompat.GetAccessibilityDelegate(nativeView) is MauiAccessibilityDelegateCompat ad)
     {
         ad.Handler = null;
         ViewCompat.SetAccessibilityDelegate(nativeView, null);
     }
 }
Example #4
0
 partial void DisconnectingHandler(NativeView?nativeView)
 {
     if (nativeView.IsAlive() && AccessibilityDelegate != null)
     {
         AccessibilityDelegate.Handler = null;
         ViewCompat.SetAccessibilityDelegate(nativeView, null);
         AccessibilityDelegate = null;
     }
 }
Example #5
0
 private void InstallAccessibilityDelegate()
 {
     // The accessibility delegate enables customizing accessibility behavior
     // via composition as opposed as inheritance. The main benefit is that
     // one can write a backwards compatible application by setting the delegate
     // only if the API level is high enough i.e. the delegate is part of the APIs.
     // The easiest way to achieve that is by using the support library which
     // takes the burden of checking API version and knowing which API version
     // introduced the delegate off the developer.
     ViewCompat.SetAccessibilityDelegate(this, new MyAccessibilityDelegateCompat());
 }
Example #6
0
        partial void DisconnectingHandler(PlatformView platformView)
        {
            if (platformView.IsAlive())
            {
                platformView.FocusChange -= OnPlatformViewFocusChange;

                if (ViewCompat.GetAccessibilityDelegate(platformView) is MauiAccessibilityDelegateCompat ad)
                {
                    ad.Handler = null;
                    ViewCompat.SetAccessibilityDelegate(platformView, null);
                }
            }
        }
        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;
            }
        }
Example #8
0
        static partial void MappingSemantics(IViewHandler handler, IView view)
        {
            if (handler.NativeView == null)
            {
                return;
            }

            var accessibilityDelegate = ViewCompat.GetAccessibilityDelegate(handler.NativeView as View) as MauiAccessibilityDelegateCompat;

            if (view.Semantics != null && accessibilityDelegate == null)
            {
                if (handler.NativeView is not NativeView nativeView)
                {
                    return;
                }

                if (nativeView is AndroidX.AppCompat.Widget.SearchView sv)
                {
                    nativeView = sv.FindViewById(Resource.Id.search_button) !;
                }

                if (!string.IsNullOrWhiteSpace(view.Semantics.Hint) || !string.IsNullOrWhiteSpace(view.Semantics.Description))
                {
                    if (accessibilityDelegate == null)
                    {
                        var currentDelegate = ViewCompat.GetAccessibilityDelegate(nativeView);
                        if (currentDelegate is MauiAccessibilityDelegateCompat)
                        {
                            currentDelegate = null;
                        }

                        accessibilityDelegate = new MauiAccessibilityDelegateCompat(currentDelegate)
                        {
                            Handler = handler
                        };

                        ViewCompat.SetAccessibilityDelegate(nativeView, accessibilityDelegate);
                    }
                }
                else if (accessibilityDelegate != null)
                {
                    ViewCompat.SetAccessibilityDelegate(nativeView, null);
                }

                if (accessibilityDelegate != null)
                {
                    nativeView.ImportantForAccessibility = ImportantForAccessibility.Yes;
                }
            }
        }
Example #9
0
        private void Initialize(Context context, IAttributeSet attrs, int defStyle)
        {
            if (context == null)
            {
                return;
            }

            TypedArray typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.ConditionResultView);

            displayMode = (DisplayMode)typedArray.GetInt(Resource.Styleable.ConditionResultView_condition_displayMode, (int)DisplayMode.Normal);

            InflateLayout(context);
            InitializeAttributes(typedArray);

            ViewCompat.SetAccessibilityDelegate(this, new ConditionResultAccessibilityDelegate());
        }
Example #10
0
 static partial void MappingSemantics(IViewHandler handler, IView view)
 {
     if (view.Semantics != null &&
         handler is ViewHandler viewHandler &&
         viewHandler.AccessibilityDelegate == null &&
         ViewCompat.GetAccessibilityDelegate(handler.NativeView as NativeView) == null)
     {
         if (!string.IsNullOrEmpty(view.Semantics.Hint))
         {
             viewHandler.AccessibilityDelegate = new MauiAccessibilityDelegate()
             {
                 Handler = viewHandler
             };
             ViewCompat.SetAccessibilityDelegate(handler.NativeView as NativeView, viewHandler.AccessibilityDelegate);
         }
     }
 }
Example #11
0
        static partial void MappingSemantics(ViewHandler handler, IView view)
        {
            if (handler.NativeView == null)
            {
                return;
            }

            if (view.Semantics != null &&
                handler is ViewHandler viewHandler &&
                viewHandler.AccessibilityDelegate == null &&
                ViewCompat.GetAccessibilityDelegate(handler.NativeView as NativeView) == null)
            {
                if (handler.NativeView is not NativeView nativeView)
                {
                    return;
                }

                if (nativeView is AndroidX.AppCompat.Widget.SearchView sv)
                {
                    nativeView = sv.FindViewById(Resource.Id.search_button) !;
                }

                if (!string.IsNullOrWhiteSpace(view.Semantics.Hint) || !string.IsNullOrWhiteSpace(view.Semantics.Description))
                {
                    if (viewHandler.AccessibilityDelegate == null)
                    {
                        viewHandler.AccessibilityDelegate = new MauiAccessibilityDelegate()
                        {
                            Handler = viewHandler
                        };
                        ViewCompat.SetAccessibilityDelegate(nativeView, viewHandler.AccessibilityDelegate);
                    }
                }
                else if (viewHandler.AccessibilityDelegate != null)
                {
                    viewHandler.AccessibilityDelegate = null;
                    ViewCompat.SetAccessibilityDelegate(nativeView, null);
                }

                if (viewHandler.AccessibilityDelegate != null)
                {
                    nativeView.ImportantForAccessibility = ImportantForAccessibility.Yes;
                }
            }
        }
Example #12
0
        internal static void AddOrRemoveControlsAccessibilityDelegate(this View virtualView)
        {
            if (virtualView?.Handler?.NativeView is not AView view)
            {
                return;
            }

            bool needsDelegate   = virtualView.ControlsAccessibilityDelegateNeeded();
            var  currentDelegate = ViewCompat.GetAccessibilityDelegate(view);

            if (needsDelegate)
            {
                if (currentDelegate is ControlsAccessibilityDelegate)
                {
                    return;
                }

                // This means the current delegate didn't come from our code at all so we just exit and assume
                // the user wants full control of the delegate
                // If the user is inheriting from AccessibilityDelegateCompatWrapper then we will continue wrapping
                if (currentDelegate != null && currentDelegate is not AccessibilityDelegateCompatWrapper)
                {
                    return;
                }

                var controlsDelegate = new ControlsAccessibilityDelegate(currentDelegate, virtualView.Handler);
                ViewCompat.SetAccessibilityDelegate(view, controlsDelegate);
            }
            else if (currentDelegate != null)
            {
                if (currentDelegate is ControlsAccessibilityDelegate cad)
                {
                    ViewCompat.SetAccessibilityDelegate(view, cad.WrappedDelegate);
                    return;
                }
            }
        }