AndroidFocusEvents.cs 1.81 KB
Newer Older
Mattia's avatar
Mattia committed
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 60 61 62 63 64 65 66
using System;
using Android.Content;
using Android.Service.Autofill;
using Android.Views.Accessibility;
using CustomViewAccessibility.Droid;
using SampleApp.CustomRenderers;
using SampleApp.Views;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(CustomImage), typeof(AndroidFocusEvents))]
namespace CustomViewAccessibility.Droid
{
    public class AndroidFocusEvents : ImageRenderer
    {
        Context context;

        public AndroidFocusEvents(Context context) : base(context)
        {
            this.context = context;
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
        {
            base.OnElementChanged(e);
            if (Control == null)
            {
                return;
            }
        }
   
        protected override Android.Widget.ImageView CreateNativeControl()
        {
            return new AccessibleButton(context);
        }





    }

    public class AccessibleButton : Android.Widget.ImageView
    {
        public AccessibleButton(Context context) : base(context)
        {
            Console.WriteLine("***** AccessibleButton created *****");
        }

        public override void OnInitializeAccessibilityEvent(AccessibilityEvent e)
        {
            base.OnInitializeAccessibilityEvent(e);
            if (e.EventType == EventTypes.ViewAccessibilityFocused)
            {
                Functionality4.myLabel.Text = "Bell Image Has Focus";

                Console.WriteLine("ACCESSIBILITY I am in focus");
            }
            else if (e.EventType == EventTypes.ViewAccessibilityFocusCleared)
            {
                Functionality4.myLabel.Text = "Bell Image does not have focus";
                Console.WriteLine("ACCESSIBILITY I am in NOT in focus");
            }
        }
    }
}