Commit d40e6438 authored by Mattia's avatar Mattia

update fun5

parent 25a970e3
using System;
using System.Threading.Tasks;
using Android.Content;
using Android.Views.Accessibility;
using SampleApp.CustomRenderers;
using SampleApp.Droid;
using Android.Views;
using fun5.Droid;
using SampleApp.DependencyServices;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(CustomLabel), typeof(AndroidHasFocus))]
namespace SampleApp.Droid
[assembly: Dependency(typeof(focusAndroid))]
namespace fun5.Droid
{
public class AndroidHasFocus : LabelRenderer
public class focusAndroid : IIsFocused
{
Context context;
public AndroidHasFocus(Context context) : base(context)
{
this.context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if(Control != null)
public bool isFocused(Xamarin.Forms.View v)
{
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");
return v.GetRenderer().View.IsAccessibilityFocused;
}
});
});
}
}
}
}
\ No newline at end of file
......@@ -53,7 +53,7 @@
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.7.0.968" />
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1451" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
</ItemGroup>
<ItemGroup>
......
......@@ -128,7 +128,7 @@
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.7.0.968" />
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1451" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
......
......@@ -4,7 +4,6 @@ using Xamarin.Forms;
using SampleApp.iOS;
using Xamarin.Forms.Platform.iOS;
using SampleApp.Views;
using SampleApp.Models;
[assembly: ExportRenderer(typeof(IFocusEvents), typeof(iOSFocusEvents))]
namespace SampleApp.iOS
......
using System;
using System.Runtime.Remoting.Contexts;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using SampleApp.CustomRenderers;
using SampleApp.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using fun5.iOS;
using System.Threading.Tasks;
using SampleApp.DependencyServices;
[assembly: ExportRenderer(typeof(CustomLabel),typeof(iOSHasFocus))]
namespace SampleApp.iOS
[assembly: Dependency(typeof(iOSFocus))]
namespace fun5.iOS
{
public class iOSHasFocus : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Control != null)
{
SetNativeControl(new AccessibleLabel());
}
}
}
public class AccessibleLabel : UILabel
public class iOSFocus : IIsFocused
{
public AccessibleLabel() : base()
{
Console.WriteLine("ACCESSIBLE LABEL CREATED");
if (AccessibilityElementIsFocused())
public bool isFocused(View v)
{
this.Text = "focus";
Console.WriteLine("accessibilityelementisfocused");
return v.GetRenderer().NativeView.AccessibilityElementIsFocused();
}
else
{
this.Text = "NOTinfocus";
Console.WriteLine("accessibilityelementisNOTinfocus");
}
}
public override bool AccessibilityElementIsFocused()
{
if (base.AccessibilityElementIsFocused())
{
return true;
}
else
{
return false;
}
}
}
}
using System;
using Xamarin.Forms;
namespace SampleApp.DependencyServices
{
public interface IIsFocused
{
bool isFocused(View v);
}
}
......@@ -11,7 +11,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.7.0.968" />
<PackageReference Include="Xamarin.Forms" Version="4.8.0.1451" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
</ItemGroup>
<ItemGroup>
......
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SampleApp.Views.Functionality5">
<StackLayout x:Name="background"></StackLayout>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SampleApp.Views.Functionality5" xmlns:local="clr-namespace:SampleApp;assembly=SampleApp">
<StackLayout x:Name="background">
<Image Source="{local:ImageResource SampleApp.images.bell.png}" x:Name="bellImage"></Image>
</StackLayout>
</ContentPage>
using System;
using System.Collections.Generic;
using SampleApp.CustomRenderers;
using System.Reflection;
using SampleApp.DependencyServices;
using Xamarin.Forms;
namespace SampleApp.Views
......@@ -8,25 +8,52 @@ namespace SampleApp.Views
public partial class Functionality5 : ContentPage
{
//label
Label label= new Label { Text = "Does the Bell's Image Have the Focus?", HorizontalOptions = LayoutOptions.CenterAndExpand };
Label labelYN = new Label { Text = "YES/ NO", HorizontalOptions = LayoutOptions.CenterAndExpand };
Label infoLabel = new Label { Text = "i: This view updates every 2 seconds", HorizontalOptions = LayoutOptions.CenterAndExpand, Margin = new Thickness(0, 200) };
IIsFocused dependency;
public Functionality5()
{
InitializeComponent();
dependency = DependencyService.Get<IIsFocused>();
CustomLabel label = new CustomLabel
{
Text = "Focus?",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
background.Children.Add(label);
AutomationProperties.SetIsInAccessibleTree(label, true);
background.Children.Add(labelYN);
background.Children.Add(infoLabel);
AutomationProperties.SetIsInAccessibleTree(label, true);
AutomationProperties.SetIsInAccessibleTree(labelYN, true);
AutomationProperties.SetIsInAccessibleTree(bellImage, true);
AutomationProperties.SetHelpText(bellImage, "Bell Image");
// timer che si ripete ogni 2 secondi
Device.StartTimer(TimeSpan.FromMilliseconds(2000.0), () =>
{
Console.WriteLine("TIMER FIRED");
Device.BeginInvokeOnMainThread(() =>
{
if (dependency.isFocused(bellImage))
{
Console.WriteLine("is focused");
labelYN.TextColor = Color.Green;
labelYN.Text = "YES";
}
else
{
Console.WriteLine("is NOT focused");
labelYN.TextColor = Color.Red;
labelYN.Text = "NO";
}
});
return true; // runs again, or false to stop
});
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment