Skip to content

Commit

Permalink
Adds Tizen backend (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
rookiejava authored Oct 30, 2020
1 parent c6f71b5 commit 94507f5
Show file tree
Hide file tree
Showing 15 changed files with 375 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ With this plugin it is also possible to respond to hover events (if the platform
|Xamarin.Android|15+|
|Xamarin.Mac|All|
|Xamarin.UWP|10+|
|Tizen.NET|4.0+|

##### Xamarin.UWP - Build on Release with .NET Native tool chain note
````cs
Expand Down
160 changes: 160 additions & 0 deletions TouchEffect.Tizen/PlatformTouchEff.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
using ElmSharp;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform.Tizen;
using TouchEffect;
using TouchEffect.Extensions;
using TouchEffect.Enums;
using TouchEffect.Tizen;
using EColor = ElmSharp.Color;

[assembly: ResolutionGroupName(nameof(TouchEffect))]
[assembly: ExportEffect(typeof(PlatformTouchEff), nameof(TouchEff))]
namespace TouchEffect.Tizen
{
[Preserve(AllMembers = true)]
public class PlatformTouchEff : PlatformEffect
{
public static void Preserve() { }

private GestureLayer _gestureLayer;
private TouchEff _effect;

protected override void OnAttached()
{
_effect = Element.PickTouchEff();
if (_effect?.IsDisabled ?? true) return;

_effect.Control = Element as VisualElement;
_gestureLayer = new TouchTapGestureRecognizer(Control, _effect);
}

protected override void OnDetached()
{
if (_effect?.Control == null) return;

if (_gestureLayer != null)
{
_gestureLayer.ClearCallbacks();
_gestureLayer.Unrealize();
_gestureLayer = null;
}
_effect.Control = null;
_effect = null;
}
}

internal sealed class TouchTapGestureRecognizer : GestureLayer
{
private TouchEff _effect;
private bool _tapCompleted;
private bool _longTapStarted;

public TouchTapGestureRecognizer(EvasObject parent) : base(parent)
{
SetTapCallback(GestureType.Tap, GestureLayer.GestureState.Start, (data) => { OnTapStarted(data); });
SetTapCallback(GestureType.Tap, GestureLayer.GestureState.End, (data) => { OnGestureEnded(data); });
SetTapCallback(GestureType.Tap, GestureLayer.GestureState.Abort, (data) => { OnGestureAborted(data); });

SetTapCallback(GestureType.LongTap, GestureLayer.GestureState.Start, (data) => { OnLongTapStarted(data); });
SetTapCallback(GestureType.LongTap, GestureLayer.GestureState.End, (data) => { OnGestureEnded(data); });
SetTapCallback(GestureType.LongTap, GestureLayer.GestureState.Abort, (data) => { OnGestureAborted(data); });
}

public TouchTapGestureRecognizer(EvasObject parent, TouchEff effect) : this(parent)
{
Attach(parent);
_effect = effect;
}

public bool IsCanceled { get; set; } = true;

private void OnTapStarted(object data)
{
if (_effect?.IsDisabled ?? true) return;

IsCanceled = false;
HandleTouch(TouchStatus.Started, UserInteractionState.Running);
}

private void OnLongTapStarted(object data)
{
if (_effect?.IsDisabled ?? true) return;

IsCanceled = false;

_longTapStarted = true;
HandleTouch(TouchStatus.Started, UserInteractionState.Running);
}

private void OnGestureEnded(object data)
{
if (_effect?.IsDisabled ?? true) return;

HandleTouch(_effect?.Status == TouchStatus.Started ? TouchStatus.Completed : TouchStatus.Canceled, UserInteractionState.Idle);
IsCanceled = true;
_tapCompleted = true;
}

private void OnGestureAborted(object data)
{
if (_effect?.IsDisabled ?? true) return;

if (_tapCompleted || _longTapStarted)
{
_tapCompleted = false;
_longTapStarted = false;
return;
}

HandleTouch(TouchStatus.Canceled, UserInteractionState.Idle);
IsCanceled = true;
}

public void HandleTouch(TouchStatus status, UserInteractionState? userInteractionState = null)
{
if (IsCanceled || _effect == null) return;

if (_effect?.IsDisabled ?? true) return;

_effect.HandleTouch(status);
if (userInteractionState.HasValue)
{
_effect.HandleUserInteraction(userInteractionState.Value);
}

if (!_effect.NativeAnimation) return;

if (_longTapStarted && !_tapCompleted) return;

var control = _effect.Control;
var nativeView = Platform.GetOrCreateRenderer(control)?.NativeView as Widget;
if (nativeView == null) return;

if (status == TouchStatus.Started)
{
var startColor = nativeView.BackgroundColor;
if (startColor.IsDefault)
return;

var endColor = _effect.NativeAnimationColor.ToNative(); ;
if (endColor.IsDefault)
{
startColor = EColor.FromRgba(startColor.R, startColor.G, startColor.B, startColor.A/2);
endColor = startColor;
}

Transit transit = new Transit
{
Repeat = 1,
Duration = .2
};
var colorEffect = new ColorEffect(startColor, endColor);
colorEffect.EffectEnded += (s, e) => { transit?.Dispose(); };
transit.Objects.Add(nativeView);
transit.AddEffect(colorEffect);
transit.Go(.2);
}
}
}
}
18 changes: 18 additions & 0 deletions TouchEffect.Tizen/TouchEffect.Tizen.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>tizen40</TargetFramework>
<TargetFrameworkIdentifier>Tizen</TargetFrameworkIdentifier>
<RootNamespace>TouchEffect.Tizen</RootNamespace>
<AssemblyTitle>TouchEffect.Tizen</AssemblyTitle>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.6.0.847" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TouchEffect\TouchEffect.csproj" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions TouchEffect.Tizen/TouchEffectPreserver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Xamarin.Forms.Internals;

namespace TouchEffect.Tizen
{
[Preserve(AllMembers = true)]
public static class TouchEffectPreserver
{
public static void Preserve()
{
PlatformTouchEff.Preserve();
}
}
}
10 changes: 9 additions & 1 deletion TouchEffect.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<group>
<dependency id="Xamarin.Forms" version="2.4" />
</group>
<group targetFramework="tizen40">
<dependency id="Tizen.NET" version="4.0.0"/>
</group>
</dependencies>
</metadata>
<files>
Expand All @@ -39,11 +42,16 @@
<file src="TouchEffect\bin\Release\netstandard2.0\TouchEffect.dll" target="lib\uap\TouchEffect.dll" />
<file src="TouchEffect\bin\Release\netstandard2.0\TouchEffect.pdb" target="lib\uap\TouchEffect.pdb" />
<file src="TouchEffect.UWP\bin\Release\TouchEffect.UWP.dll" target="lib\uap\TouchEffect.UWP.dll" />
<file src="TouchEffect.UWP\bin\Release\TouchEffect.UWP.pdb" target="lib\uap\TouchEffect.UWP.pdb" />
<file src="TouchEffect.UWP\bin\Release\TouchEffect.UWP.pdb" target="lib\uap\TouchEffect.UWP.pdb" />
<!--Xamarin.Mac-->
<file src="TouchEffect\bin\Release\netstandard2.0\TouchEffect.dll" target="lib\Xamarin.Mac20\TouchEffect.dll" />
<file src="TouchEffect\bin\Release\netstandard2.0\TouchEffect.pdb" target="lib\Xamarin.Mac20\TouchEffect.pdb" />
<file src="TouchEffect.Mac\bin\Release\TouchEffect.Mac.dll" target="lib\Xamarin.Mac20\TouchEffect.Mac.dll" />
<file src="TouchEffect.Mac\bin\Release\TouchEffect.Mac.pdb" target="lib\Xamarin.Mac20\TouchEffect.Mac.pdb" />
<!--Tizen-->
<file src="TouchEffect\bin\Release\netstandard2.0\TouchEffect.dll" target="lib\tizen40\TouchEffect.dll" />
<file src="TouchEffect\bin\Release\netstandard2.0\TouchEffect.pdb" target="lib\tizen40\TouchEffect.pdb" />
<file src="TouchEffect.Tizen\bin\Release\TouchEffect.Tizen.dll" target="lib\tizen40\TouchEffect.Tizen.dll" />
<file src="TouchEffect.Tizen\bin\Release\TouchEffect.Tizen.pdb" target="lib\tizen40\TouchEffect.Tizen.pdb" />
</files>
</package>
24 changes: 24 additions & 0 deletions TouchEffectSample.Tizen/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using TouchEffect.Tizen;

namespace TouchEffectSample.Tizen
{
class Program : FormsApplication
{
protected override void OnCreate()
{
base.OnCreate();
LoadApplication(new App());
}

static void Main(string[] args)
{
var app = new Program();
Forms.Init(app, true);
TouchEffectPreserver.Preserve();
app.Run(args);
}
}
}
14 changes: 14 additions & 0 deletions TouchEffectSample.Tizen/TouchEffectSample.Tizen.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Tizen.NET.Sdk/1.0.9">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>tizen40</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TouchEffect.Tizen\TouchEffect.Tizen.csproj" />
<ProjectReference Include="..\TouchEffectSample\TouchEffectSample.csproj" />
<ProjectReference Include="..\TouchEffect\TouchEffect.csproj" />
</ItemGroup>

</Project>
Binary file added TouchEffectSample.Tizen/res/button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TouchEffectSample.Tizen/res/button_pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TouchEffectSample.Tizen/res/check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TouchEffectSample.Tizen/res/x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions TouchEffectSample.Tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns="http://tizen.org/ns/packages" api-version="4" package="org.tizen.example.TouchEffectSample.Tizen" version="1.0.0">
<profile name="common" />
<ui-application appid="org.tizen.example.TouchEffectSample.Tizen"
exec="TouchEffectSample.Tizen.dll"
type="dotnet"
multiple="false"
taskmanage="true"
nodisplay="false"
launch_mode="single"
>
<label>TouchEffectSample.Tizen</label>
<icon>TouchEffectSample.Tizen.png</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
</ui-application>
</manifest>
Loading

0 comments on commit 94507f5

Please sign in to comment.