Skip to content

Commit

Permalink
Update Piano using NUI Xaml.
Browse files Browse the repository at this point in the history
  • Loading branch information
huayongxu committed Jan 30, 2023
1 parent 6f7a29f commit 6500db4
Show file tree
Hide file tree
Showing 41 changed files with 211 additions and 186 deletions.
Empty file modified Mobile/Xamarin.Forms/Piano/LICENSE
100644 → 100755
Empty file.
12 changes: 3 additions & 9 deletions Mobile/Xamarin.Forms/Piano/Piano.sln
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.16
# Visual Studio Version 16
VisualStudioVersion = 16.0.32929.386
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piano", "Piano\Piano\Piano.csproj", "{B99A786D-E74B-4DBA-B7DD-B5AE4DDF455F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piano.Tizen.Mobile", "Piano\Piano.Tizen.Mobile\Piano.Tizen.Mobile.csproj", "{88E15381-DFC8-41CA-9D73-078B77F8A6BE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Piano.Tizen.Mobile", "Piano\Piano.Tizen.Mobile\Piano.Tizen.Mobile.csproj", "{88E15381-DFC8-41CA-9D73-078B77F8A6BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B99A786D-E74B-4DBA-B7DD-B5AE4DDF455F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B99A786D-E74B-4DBA-B7DD-B5AE4DDF455F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B99A786D-E74B-4DBA-B7DD-B5AE4DDF455F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B99A786D-E74B-4DBA-B7DD-B5AE4DDF455F}.Release|Any CPU.Build.0 = Release|Any CPU
{88E15381-DFC8-41CA-9D73-078B77F8A6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88E15381-DFC8-41CA-9D73-078B77F8A6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88E15381-DFC8-41CA-9D73-078B77F8A6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
36 changes: 30 additions & 6 deletions Mobile/Xamarin.Forms/Piano/Piano/Piano.Tizen.Mobile/Piano.Tizen.Mobile.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,48 @@
* limitations under the License.
*/

using ElmSharp;
using Xamarin.Forms;
using Piano.Models;
using Piano.Views;
using System;
using Tizen.NUI;

namespace Piano.Tizen.Mobile
{
class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication
class Program : NUIApplication
{
protected override void OnCreate()
{
base.OnCreate();
LoadApplication(new App());
MainWindow.AvailableRotations = DisplayRotation.Degree_90 | DisplayRotation.Degree_270;

Window window = Window.Instance;
window.BackgroundColor = Color.Cyan;
window.KeyEvent += OnKeyEvent;

try
{
Sound.Init();
}
catch (Exception e)
{
global::Tizen.Log.Error("Piano", "Init : " + e.Message);
}

MainPage page = new MainPage();
window.Add(page);
window.AddAvailableOrientation(Window.WindowOrientation.Landscape);
}

public void OnKeyEvent(object sender, Window.KeyEventArgs e)
{
if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
{
Exit();
}
}

static void Main(string[] args)
{
var app = new Program();
Forms.Init(app);
app.Run(args);
}
}
Expand Down
22 changes: 13 additions & 9 deletions Mobile/Xamarin.Forms/Piano/Piano/Piano.Tizen.Mobile/Piano.Tizen.Mobile.csproj
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>tizen80</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<XamlOptimization>1</XamlOptimization>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -11,24 +12,27 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>None</DebugType>
</PropertyGroup>

<ItemGroup>
<Folder Include="lib\" />
<Folder Include="res\" />
<Compile Remove="lib\**" />
<EmbeddedResource Remove="lib\**" />
<None Remove="lib\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2244" />
<None Remove="Piano\Controls\Key.xaml" />
<None Remove="Piano\Views\MainPage.xaml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Piano\Controls\Key.xaml" />
<EmbeddedResource Include="Piano\Views\MainPage.xaml" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\Piano\Piano.csproj" />
<Folder Include="res\" />
</ItemGroup>


<ItemGroup>
<PackageReference Update="Tizen.NET" Version="9.0.0.16760">
<PackageReference Include="Tizen.NET" Version="11.0.0.17614">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>

<ImageView xmlns="http://tizen.org/Tizen.NUI/2018/XAML"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewModels="clr-namespace:Piano.ViewModels;assembly=Piano.Tizen.Mobile"
x:Class="Piano.Controls.Key"
WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
HeightSpecification="{Static LayoutParamPolicies.MatchParent}"
x:Name="Root"
AdjustViewSize="true" >

<ImageView.BindingContext>
<viewModels:KeyViewModel SoundNumber="{Binding Source={x:Reference Name='Root'}, Path=SoundNumber}"
PlaySoundCommand="{Binding Source={x:Reference Name='Root'}, Path=OnClickedCommand, Mode=OneWayToSource}" />
</ImageView.BindingContext>

</ImageView>
51 changes: 35 additions & 16 deletions ...ms/Piano/Piano/Piano/Controls/Key.xaml.cs → ...o.Tizen.Mobile/Piano/Controls/Key.xaml.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@
* limitations under the License.
*/

using System;
using Xamarin.Forms;
using Tizen.NUI;
using Tizen.NUI.Binding;
using Tizen.NUI.BaseComponents;

namespace Piano.Controls
{
/// <summary>
/// Interaction logic for Key.xaml.
/// </summary>
public partial class Key
public partial class Key : ImageView
{
#region fields

/// <summary>
/// Local storage of <see cref="SoundNumber"/>
/// </summary>
private int _soundNumber;
private Timer mViewTimer;

#endregion

Expand All @@ -48,6 +50,16 @@ public partial class Key
BindableProperty.Create(nameof(UnPressedImageSource), typeof(string), typeof(Key),
propertyChanged: UnPressedImageSourcePropertyChanged);

public Vector4 LayoutBounds
{
set
{
PositionX = value.X * Window.Instance.Size.Height;
PositionY = value.Y * Window.Instance.Size.Width;
SizeWidth = value.Z * Window.Instance.Size.Height;
SizeHeight = value.W * Window.Instance.Size.Width;
}
}
/// <summary>
/// Gets or sets sound index that will be played.
/// </summary>
Expand Down Expand Up @@ -94,13 +106,13 @@ public string UnPressedImageSource
public Key()
{
InitializeComponent();
Root.TouchEvent += OnTouchEvent;
}

var tapGestureRecognizer = new TapGestureRecognizer
{
Command = new Command(ExecuteClickCommand)
};

GestureRecognizers.Add(tapGestureRecognizer);
private bool OnTouchEvent(object source, View.TouchEventArgs e)
{
ExecuteClickCommand();
return false;
}

/// <summary>
Expand All @@ -125,14 +137,21 @@ private static void UnPressedImageSourcePropertyChanged(BindableObject bindable,
private void ExecuteClickCommand()
{
UpdateImageSource(PressedImageSource);
//OnClickedCommand?.Execute(null);

mViewTimer = new Timer(300);
mViewTimer.Tick += OnTimerTick;
mViewTimer.Start();
}

OnClickedCommand?.Execute(null);
private bool OnTimerTick(object sender, Timer.TickEventArgs args)
{
UpdateImageSource(UnPressedImageSource);

Device.StartTimer(new TimeSpan(0, 0, 0, 0, 300), () =>
{
UpdateImageSource(UnPressedImageSource);
return false;
});
mViewTimer.Stop();
mViewTimer.Dispose();

return false;
}

/// <summary>
Expand All @@ -141,7 +160,7 @@ private void ExecuteClickCommand()
/// <param name="newSource">New image source.</param>
private void UpdateImageSource(string newSource)
{
Source = ImageSource.FromFile(newSource);
ResourceUrl = newSource;
}

#endregion
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

using System.Threading.Tasks;
using Xamarin.Forms;
using Tizen.NUI.Binding;

namespace Piano.Models
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<None Remove="Controls\Key.xaml" />
<None Remove="Views\MainPage.xaml" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Controls\Key.xaml" />
<EmbeddedResource Include="Views\MainPage.xaml" />
</ItemGroup>

<!-- Include Nuget Package for Xamarin building -->
<ItemGroup>
<PackageReference Include="Tizen.NET" Version="11.0.0.17614" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

using Piano.Models;
using Xamarin.Forms;
using Tizen.NUI.Binding;

namespace Piano.ViewModels
{
Expand All @@ -30,13 +30,17 @@ public class KeyViewModel : BindableObject
/// Bindable property that allows to set sound index that will be played.
/// </summary>
public static BindableProperty SoundNumberProperty =
#pragma warning disable Reflection // The code contains reflection
BindableProperty.Create(nameof(SoundNumber), typeof(int), typeof(KeyViewModel), 0);
#pragma warning restore Reflection // The code contains reflection

/// <summary>
/// Bindable property that allows to set command that plays sound.
/// </summary>
public static BindableProperty PlaySoundCommandProperty =
#pragma warning disable Reflection // The code contains reflection
BindableProperty.Create(nameof(PlaySoundCommand), typeof(Command), typeof(KeyViewModel));
#pragma warning restore Reflection // The code contains reflection

/// <summary>
/// Gets or sets sound index that will be played.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>

<ContentPage xmlns="http://tizen.org/Tizen.NUI/2018/XAML"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:control="clr-namespace:Piano.Controls;assembly=Piano.Tizen.Mobile"
x:Class="Piano.Views.MainPage"
WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
HeightSpecification="{Static LayoutParamPolicies.MatchParent}" >

<ContentPage.XamlResources>

<XamlStyle x:Key="whiteKeyStyle" TargetType="control:Key">
<Setter Property="UnPressedImageSource" Value="*Resource*/white.png" />
<Setter Property="PressedImageSource" Value="*Resource*/white_pressed.png" />
</XamlStyle>
<XamlStyle x:Key="blackKeyStyle" TargetType="control:Key">
<Setter Property="UnPressedImageSource" Value="*Resource*/black.png" />
<Setter Property="PressedImageSource" Value="*Resource*/black_pressed.png" />
</XamlStyle>

</ContentPage.XamlResources>

<ContentPage.Content>

<View WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
HeightSpecification="{Static LayoutParamPolicies.MatchParent}">

<View.Layout>
<AbsoluteLayout />
</View.Layout>

<control:Key SoundNumber="0"
LayoutBounds="0.0,0.0,0.125,1.0"
XamlStyle="{StaticResource whiteKeyStyle}" />
<control:Key SoundNumber="2"
LayoutBounds="0.125,0.0,0.125,1.0"
XamlStyle="{StaticResource whiteKeyStyle}" />
<control:Key SoundNumber="4"
LayoutBounds="0.250,0.0,0.125,1.0"
XamlStyle="{StaticResource whiteKeyStyle}" />
<control:Key SoundNumber="5"
LayoutBounds="0.375,0.0,0.125,1.0"
XamlStyle="{StaticResource whiteKeyStyle}" />
<control:Key SoundNumber="7"
LayoutBounds="0.500,0.0,0.125,1.0"
XamlStyle="{StaticResource whiteKeyStyle}" />
<control:Key SoundNumber="9"
LayoutBounds="0.625,0.0,0.125,1.0"
XamlStyle="{StaticResource whiteKeyStyle}" />
<control:Key SoundNumber="11"
LayoutBounds="0.750,0.0,0.125,1.0"
XamlStyle="{StaticResource whiteKeyStyle}" />
<control:Key SoundNumber="12"
LayoutBounds="0.875,0.0,0.125,1.0"
XamlStyle="{StaticResource whiteKeyStyle}" />

<control:Key SoundNumber="1"
LayoutBounds="0.09,0,0.075,0.6694"
XamlStyle="{StaticResource blackKeyStyle}" />
<control:Key SoundNumber="3"
LayoutBounds="0.215,0,0.075,0.6694"
XamlStyle="{StaticResource blackKeyStyle}" />
<control:Key SoundNumber="6"
LayoutBounds="0.465,0,0.075,0.6694"
XamlStyle="{StaticResource blackKeyStyle}" />
<control:Key SoundNumber="8"
LayoutBounds="0.59,0,0.075,0.6694"
XamlStyle="{StaticResource blackKeyStyle}" />
<control:Key SoundNumber="10"
LayoutBounds="0.715,0,0.075,0.6694"
XamlStyle="{StaticResource blackKeyStyle}" />
<control:Key SoundNumber="13"
LayoutBounds="0.965,0,0.075,0.6694"
XamlStyle="{StaticResource blackKeyStyle}" />

</View>

</ContentPage.Content>

</ContentPage>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

using Tizen.NUI;
using Tizen.NUI.BaseComponents;

namespace Piano.Views
{
/// <summary>
Expand Down
Loading

0 comments on commit 6500db4

Please sign in to comment.