From: tscholb Date: Thu, 21 Jul 2022 02:57:08 +0000 (+0900) Subject: [NUI][TEST] add widget sample for sending message X-Git-Tag: accepted/tizen/unified/20231205.024657~832 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8ebe57ab29fc06efd9ed1b76dc480de1ea16146;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI][TEST] add widget sample for sending message 1. Add animation to widget template 2. Add new sample for seding message test --- diff --git a/test/Tizen.NUI.WidgetViewTest/0.Template/Tizen.NUI.WidgetTest/SimpleWidgetApp.cs b/test/Tizen.NUI.WidgetViewTest/0.Template/Tizen.NUI.WidgetTest/SimpleWidgetApp.cs index fbc13bf..4189942 100755 --- a/test/Tizen.NUI.WidgetViewTest/0.Template/Tizen.NUI.WidgetTest/SimpleWidgetApp.cs +++ b/test/Tizen.NUI.WidgetViewTest/0.Template/Tizen.NUI.WidgetTest/SimpleWidgetApp.cs @@ -43,6 +43,11 @@ namespace WidgetTemplate sampleLabel.SizeWidth = 300; sampleLabel.PivotPoint = PivotPoint.Center; mRootView.Add(sampleLabel); + + mAnimation = new Animation(1000); + mAnimation.AnimateTo(sampleLabel, "PositionX", 300.0f); + mAnimation.Looping = true; + mAnimation.Play(); } protected override void OnPause() @@ -72,6 +77,7 @@ namespace WidgetTemplate } private View mRootView; + private Animation mAnimation; } class BlueWidget : Widget @@ -92,6 +98,11 @@ namespace WidgetTemplate sampleLabel.SizeWidth = 300; sampleLabel.PivotPoint = PivotPoint.Center; mRootView.Add(sampleLabel); + + mAnimation = new Animation(1000); + mAnimation.AnimateTo(sampleLabel, "PositionX", 400.0f); + mAnimation.Looping = true; + mAnimation.Play(); } protected override void OnPause() @@ -120,6 +131,7 @@ namespace WidgetTemplate } private View mRootView; + private Animation mAnimation; } class Program : NUIWidgetApplication diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/SimpleWidgetApp.cs b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/SimpleWidgetApp.cs new file mode 100755 index 0000000..81741f4 --- /dev/null +++ b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/SimpleWidgetApp.cs @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Collections.Generic; // for Dictionary +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; +using Tizen.Applications; +using Tizen.Applications.Messages; + +namespace WidgetTemplate +{ + class RedWidget : Widget + { + string rcvPort = "my_widget_port"; + + protected override void OnCreate(string contentInfo, Window window) + { + Tizen.Log.Info("NUI", "OnCreate(RedWidget) \n"); + Bundle bundle = Bundle.Decode(contentInfo); + mRootView = new View(); + mRootView.BackgroundColor = Color.Red; + mRootView.Size2D = window.Size; + window.GetDefaultLayer().Add(mRootView); + + TextLabel sampleLabel = new TextLabel("Red Widget "); + sampleLabel.FontFamily = "SamsungOneUI 500"; + sampleLabel.PointSize = 8; + sampleLabel.TextColor = Color.Black; + sampleLabel.SizeWidth = 300; + sampleLabel.PivotPoint = PivotPoint.Center; + mRootView.Add(sampleLabel); + + // Create receive port + _rcvPort = new MessagePort(rcvPort, false); + Tizen.Log.Info("NUI", "ReceivePort Create: " + _rcvPort.PortName + "Trusted: " + _rcvPort.Trusted); + _rcvPort.MessageReceived += MessageReceived_Callback; + _rcvPort.Listen(); + + // For testing send to bundle data from widget to widgetViewer, pleaes enable this code. + //timer = new Timer(5000); + //timer.Tick += TimerTick; + //timer.Start(); + } + + private void MessageReceived_Callback(object sender, MessageReceivedEventArgs e) + { + Tizen.Log.Info("NUI", "Message Received"); + Tizen.Log.Info("NUI", "App ID: " + e.Remote.AppId); + Tizen.Log.Info("NUI", "PortName: " + e.Remote.PortName); + Tizen.Log.Info("NUI", "Trusted: " + e.Remote.Trusted); + Tizen.Log.Info("NUI", "message: " + e.Message.GetItem ("message")); + } + + protected override void OnPause() + { + base.OnPause(); + } + + protected override void OnResume() + { + base.OnResume(); + } + + protected override void OnResize(Window window) + { + mRootView.Size2D = window.Size; + base.OnResize(window); + } + + protected override void OnTerminate(string contentInfo, TerminationType type) + { + base.OnTerminate(contentInfo, type); + } + + protected override void OnUpdate(string contentInfo, int force) + { + base.OnUpdate(contentInfo, force); + } + +/* + private bool TimerTick(object source, Timer.TickEventArgs e) + { + Bundle bundle = new Bundle(); + bundle.AddItem("COUNT", "1"); + String encodedBundle = bundle.Encode(); + SetContentInfo(encodedBundle); + return false; + } +*/ + + private static MessagePort _rcvPort; + + private View mRootView; + private Animation mAnimation; + private Timer timer; + } + + class BlueWidget : Widget + { + protected override void OnCreate(string contentInfo, Window window) + { + Tizen.Log.Info("NUI", "OnCreate(BlueWidget) \n"); + Bundle bundle = Bundle.Decode(contentInfo); + mRootView = new View(); + mRootView.BackgroundColor = Color.Blue; + mRootView.Size2D = window.Size; + window.GetDefaultLayer().Add(mRootView); + + TextLabel sampleLabel = new TextLabel("Blue Widget "); + sampleLabel.FontFamily = "SamsungOneUI 500"; + sampleLabel.PointSize = 8; + sampleLabel.TextColor = Color.Black; + sampleLabel.SizeWidth = 300; + sampleLabel.PivotPoint = PivotPoint.Center; + mRootView.Add(sampleLabel); + } + + protected override void OnPause() + { + base.OnPause(); + } + + protected override void OnResume() + { + base.OnResume(); + } + + protected override void OnResize(Window window) + { + base.OnResize(window); + } + + protected override void OnTerminate(string contentInfo, TerminationType type) + { + base.OnTerminate(contentInfo, type); + } + + protected override void OnUpdate(string contentInfo, int force) + { + base.OnUpdate(contentInfo, force); + } + + private View mRootView; + private Animation mAnimation; + } + + class Program : NUIWidgetApplication + { + public Program(Dictionary widgetSet) : base(widgetSet) + { + + } + + protected override void OnCreate() + { + base.OnCreate(); + Initialize(); + } + + void Initialize() + { + } + + 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) + { + Dictionary widgetSet = new Dictionary(); + widgetSet.Add(typeof(RedWidget), "class1@Tizen.NUI.WidgetTest"); + widgetSet.Add(typeof(BlueWidget), "class2@Tizen.NUI.WidgetTest"); + var app = new Program(widgetSet); + app.Run(args); + } + } +} + diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/Tizen.NUI.WidgetTest.csproj b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/Tizen.NUI.WidgetTest.csproj new file mode 100755 index 0000000..b1d08d9 --- /dev/null +++ b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/Tizen.NUI.WidgetTest.csproj @@ -0,0 +1,28 @@ + + + + Exe + netcoreapp2.0 + Tizen.NUI.WidgetTest + true + Tizen.NUI.WidgetTest + Tizen.NUI.WidgetTest + Tizen.NUI.WidgetTest + Tizen.NUI.WidgetTest + + + + portable + + + None + + + + + + + + + + diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/Tizen.NUI.WidgetTest.sln b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/Tizen.NUI.WidgetTest.sln new file mode 100755 index 0000000..79d0b33 --- /dev/null +++ b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/Tizen.NUI.WidgetTest.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30309.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.NUI.WidgetTest", "Tizen.NUI.WidgetTest.csproj", "{3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {355D568D-D02A-490A-A6AC-FD6C7D97457A} + EndGlobalSection +EndGlobal diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/shared/res/Tizen.NUI.WidgetTest.png b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/shared/res/Tizen.NUI.WidgetTest.png new file mode 100755 index 0000000..9f3cb98 Binary files /dev/null and b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/shared/res/Tizen.NUI.WidgetTest.png differ diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/tizen-manifest.xml b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/tizen-manifest.xml new file mode 100755 index 0000000..5611bc6 --- /dev/null +++ b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetTest/tizen-manifest.xml @@ -0,0 +1,22 @@ + + + + + + Tizen.NUI.WidgetTest.png + + 4x4 + + + 4x4 + + + + + diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/SimpleWidgetViewApp.cs b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/SimpleWidgetViewApp.cs new file mode 100755 index 0000000..41eed8a --- /dev/null +++ b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/SimpleWidgetViewApp.cs @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +using System; +using System.Collections.Generic; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using Tizen.Applications; +using Tizen.Applications.Messages; + +namespace WidgetApplicationTemplate +{ + class Program : NUIApplication + { + string widgetAppId = "Tizen.NUI.WidgetTest"; + string rcvPort = "my_widget_port"; + + protected override void OnCreate() + { + base.OnCreate(); + Initialize(); + } + void Initialize() + { + Window window = GetDefaultWindow(); + + window.KeyEvent += OnKeyEvent; + window.TouchEvent += OnTouchEvent; + + rootView = new View(); + rootView.BackgroundColor = Color.White; + rootView.Size = Window.Instance.Size; + rootView.PivotPoint = PivotPoint.Center; + window.GetDefaultLayer().Add(rootView); + + TextLabel sampleLabel = new TextLabel("Widget Viewer "); + sampleLabel.FontFamily = "SamsungOneUI 500"; + sampleLabel.PointSize = 8; + sampleLabel.TextColor = Color.Black; + sampleLabel.SizeWidth = 300; + sampleLabel.PivotPoint = PivotPoint.Center; + rootView.Add(sampleLabel); + + Bundle bundle = new Bundle(); + bundle.AddItem("COUNT", "1"); + String encodedBundle = bundle.Encode(); + + widgetWidth = 500; + widgetHeight = 500; + mWidgetView = WidgetViewManager.Instance.AddWidget("class1@Tizen.NUI.WidgetTest", encodedBundle, widgetWidth, widgetHeight, 0.0f); + mWidgetView.Position = new Position(100,100); + window.GetDefaultLayer().Add(mWidgetView); + + //mWidgetView.WidgetContentUpdated += OnWidgetContentUpdatedCB; + + mWidgetView2 = WidgetViewManager.Instance.AddWidget("class2@Tizen.NUI.WidgetTest", encodedBundle, widgetWidth, widgetHeight, 0.0f); + mWidgetView2.Position = new Position(100, widgetHeight + 110); + window.GetDefaultLayer().Add(mWidgetView2); + + // Send message using port + _msgPort = new MessagePort(rcvPort, false); + Tizen.Log.Info("NUI", "MessagePort Create: " + _msgPort.PortName + "Trusted: " + _msgPort.Trusted); + _msgPort.Listen(); + } + public void OnKeyEvent(object sender, Window.KeyEventArgs e) + { + if (e.Key.State == Key.StateType.Down ) + { + Tizen.Log.Info("NUI", "OnKeyEvent(View-Window) : " + e.Key.KeyPressedName + "\n"); + if (e.Key.KeyPressedName == "1") + { + widgetWidth += 200; + widgetHeight += 200; + if(widgetWidth > 1000 || widgetHeight > 1000) + { + widgetWidth = 200; + widgetHeight = 200; + } + mWidgetView.Size2D = new Size2D(widgetWidth, widgetHeight); + + // Send the WidgetView's width to Widget + var msg = new Bundle(); + msg.AddItem("message", "WidgetView's message >> width:" + widgetWidth); + _msgPort.Send(msg, widgetAppId, rcvPort); + } + + } + } + private void OnTouchEvent(object source, Window.TouchEventArgs e) + { + } + +/* + private void OnWidgetContentUpdatedCB(object sender, WidgetView.WidgetViewEventArgs e) + { + String encodedBundle = e.WidgetView.ContentInfo; + Tizen.Log.Info("NUI", "tscholb : OnWidgetContentUpdatedCB : " + encodedBundle + "\n"); + Bundle bundle = Bundle.Decode(encodedBundle); + string outString; + if (bundle.TryGetItem("COUNT", out outString)) + { + Tizen.Log.Info("NUI", "OnWidgetContentUpdatedCB(2) : " + outString + "\n"); + } + + } +*/ + + static void Main(string[] args) + { + var app = new Program(); + app.Run(args); + } + + private static MessagePort _msgPort; + private View rootView; + WidgetView mWidgetView; + WidgetView mWidgetView2; + int widgetWidth; + int widgetHeight; + } +} + + diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/Tizen.NUI.WidgetViewTest.csproj b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/Tizen.NUI.WidgetViewTest.csproj new file mode 100755 index 0000000..4395beb --- /dev/null +++ b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/Tizen.NUI.WidgetViewTest.csproj @@ -0,0 +1,28 @@ + + + + Exe + netcoreapp2.0 + Tizen.NUI.WidgetViewTest + true + Tizen.NUI.WidgetViewTest + Tizen.NUI.WidgetViewTest + Tizen.NUI.WidgetViewTest + Tizen.NUI.WidgetViewTest + + + + portable + + + None + + + + + + + + + + diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/Tizen.NUI.WidgetViewTest.sln b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/Tizen.NUI.WidgetViewTest.sln new file mode 100755 index 0000000..d5413b5 --- /dev/null +++ b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/Tizen.NUI.WidgetViewTest.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30309.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.NUI.WidgetViewTest", "Tizen.NUI.WidgetViewTest.csproj", "{3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C6CE4CE-9D35-42C9-B23D-BBFFA96B3955}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {355D568D-D02A-490A-A6AC-FD6C7D97457A} + EndGlobalSection +EndGlobal diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/shared/res/Tizen.NUI.WidgetViewTest.png b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/shared/res/Tizen.NUI.WidgetViewTest.png new file mode 100755 index 0000000..9f3cb98 Binary files /dev/null and b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/shared/res/Tizen.NUI.WidgetViewTest.png differ diff --git a/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/tizen-manifest.xml b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/tizen-manifest.xml new file mode 100755 index 0000000..964ca09 --- /dev/null +++ b/test/Tizen.NUI.WidgetViewTest/1.SendInfo/Tizen.NUI.WidgetViewTest/tizen-manifest.xml @@ -0,0 +1,18 @@ + + + + + + Tizen.NUI.WidgetViewTest.png + + + + + http://tizen.org/privilege/widget.viewer + http://tizen.org/privilege/appmanager.launch + http://tizen.org/privilege/datasharing + +