Commit d40e6438 authored by Mattia's avatar Mattia

update fun5

parent 25a970e3
using System; using System;
using System.Threading.Tasks; using Android.Views;
using Android.Content; using fun5.Droid;
using Android.Views.Accessibility; using SampleApp.DependencyServices;
using SampleApp.CustomRenderers;
using SampleApp.Droid;
using Xamarin.Forms; using Xamarin.Forms;
using Xamarin.Forms.Platform.Android; using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(CustomLabel), typeof(AndroidHasFocus))] [assembly: Dependency(typeof(focusAndroid))]
namespace SampleApp.Droid namespace fun5.Droid
{ {
public class AndroidHasFocus : LabelRenderer public class focusAndroid : IIsFocused
{ {
Context context; public bool isFocused(Xamarin.Forms.View v)
public AndroidHasFocus(Context context) : base(context)
{ {
this.context = context; return v.GetRenderer().View.IsAccessibilityFocused;
} }
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");
}
});
});
}
}
} }
}
\ No newline at end of file
}
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<Reference Include="System.Numerics.Vectors" /> <Reference Include="System.Numerics.Vectors" />
</ItemGroup> </ItemGroup>
<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" /> <PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
<Reference Include="System.Numerics.Vectors" /> <Reference Include="System.Numerics.Vectors" />
</ItemGroup> </ItemGroup>
<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" /> <PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
......
...@@ -4,7 +4,6 @@ using Xamarin.Forms; ...@@ -4,7 +4,6 @@ using Xamarin.Forms;
using SampleApp.iOS; using SampleApp.iOS;
using Xamarin.Forms.Platform.iOS; using Xamarin.Forms.Platform.iOS;
using SampleApp.Views; using SampleApp.Views;
using SampleApp.Models;
[assembly: ExportRenderer(typeof(IFocusEvents), typeof(iOSFocusEvents))] [assembly: ExportRenderer(typeof(IFocusEvents), typeof(iOSFocusEvents))]
namespace SampleApp.iOS namespace SampleApp.iOS
......
using System; 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 UIKit;
using Xamarin.Forms; using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS; using Xamarin.Forms.Platform.iOS;
using fun5.iOS;
using System.Threading.Tasks;
using SampleApp.DependencyServices;
[assembly: ExportRenderer(typeof(CustomLabel),typeof(iOSHasFocus))] [assembly: Dependency(typeof(iOSFocus))]
namespace SampleApp.iOS namespace fun5.iOS
{ {
public class iOSHasFocus : LabelRenderer public class iOSFocus : IIsFocused
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Control != null)
{
SetNativeControl(new AccessibleLabel());
}
}
}
public class AccessibleLabel : UILabel
{ {
public AccessibleLabel() : base()
{
Console.WriteLine("ACCESSIBLE LABEL CREATED");
if (AccessibilityElementIsFocused())
{
this.Text = "focus";
Console.WriteLine("accessibilityelementisfocused");
}
else
{
this.Text = "NOTinfocus";
Console.WriteLine("accessibilityelementisNOTinfocus");
}
public bool isFocused(View v)
}
public override bool AccessibilityElementIsFocused()
{ {
if (base.AccessibilityElementIsFocused()) return v.GetRenderer().NativeView.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 @@ ...@@ -11,7 +11,7 @@
</PropertyGroup> </PropertyGroup>
<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" /> <PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
<?xml version="1.0" encoding="UTF-8"?> <?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"> <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"></StackLayout> <StackLayout x:Name="background">
<Image Source="{local:ImageResource SampleApp.images.bell.png}" x:Name="bellImage"></Image>
</StackLayout>
</ContentPage> </ContentPage>
using System; using System;
using System.Collections.Generic; using System.Reflection;
using SampleApp.CustomRenderers; using SampleApp.DependencyServices;
using Xamarin.Forms; using Xamarin.Forms;
namespace SampleApp.Views namespace SampleApp.Views
{ {
public partial class Functionality5 : ContentPage 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() public Functionality5()
{ {
InitializeComponent(); InitializeComponent();
dependency = DependencyService.Get<IIsFocused>();
CustomLabel label = new CustomLabel
{
Text = "Focus?",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
background.Children.Add(label); 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