AndroidHasFocus.cs 1.34 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
using System;
using System.Threading.Tasks;
using Android.Content;
using Android.Views.Accessibility;
using SampleApp.CustomRenderers;
using SampleApp.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(CustomLabel), typeof(AndroidHasFocus))]
namespace SampleApp.Droid
{
    public class AndroidHasFocus : LabelRenderer
    {

        Context context;

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

        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);

            if(Control != null)
            {
                Task.Delay(3000).ContinueWith((arg) =>
                {
                    Device.BeginInvokeOnMainThread(() => {
                        if (Control.IsAccessibilityFocused)
                        {
                            Control.Text = "Focus";
                            Console.WriteLine("focus");
                        }
                        else
                        {
                            Control.Text = "Not in focus";
                            Console.WriteLine("Not in focus");
                        }
                    });


                });
            }



            


        }
        
    }

    
}