AndroidFocusEvents.cs 1.81 KB
Newer Older
Mattia's avatar
Mattia committed
1 2 3 4 5
using System;
using Android.Content;
using Android.Service.Autofill;
using Android.Views.Accessibility;
using CustomViewAccessibility.Droid;
Mattia's avatar
Mattia committed
6
using SampleApp.DependencyServices;
Mattia's avatar
Mattia committed
7
using SampleApp.Views;
Mattia's avatar
Mattia committed
8 9 10
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

Mattia's avatar
Mattia committed
11
[assembly: ExportRenderer(typeof(IFocusEvents), typeof(AndroidFocusEvents))]
Mattia's avatar
Mattia committed
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
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)
            {
Mattia's avatar
Mattia committed
55 56
                Functionality4.myLabel.Text = "Bell Image Has Focus";

Mattia's avatar
Mattia committed
57 58 59 60
                Console.WriteLine("ACCESSIBILITY I am in focus");
            }
            else if (e.EventType == EventTypes.ViewAccessibilityFocusCleared)
            {
Mattia's avatar
Mattia committed
61
                Functionality4.myLabel.Text = "Bell Image does not have focus";
Mattia's avatar
Mattia committed
62 63 64 65 66
                Console.WriteLine("ACCESSIBILITY I am in NOT in focus");
            }
        }
    }
}