DragAndDrop : Add multi-window sample
authorTaehyub Kim <taehyub.kim@samsung.com>
Tue, 21 Feb 2023 07:41:28 +0000 (16:41 +0900)
committerEunki Hong <h.pichulia@gmail.com>
Tue, 21 Feb 2023 09:32:05 +0000 (18:32 +0900)
test/NUIDnDMultiWindow/NUIDnDMultiWindow.cs [new file with mode: 0644]
test/NUIDnDMultiWindow/NUIDnDMultiWindow.csproj [new file with mode: 0644]
test/NUIDnDMultiWindow/res/dragsource.png [new file with mode: 0644]
test/NUIDnDMultiWindow/res/droptarget.png [new file with mode: 0644]
test/NUIDnDMultiWindow/shared/res/NUIDnDMultiWindow.png [new file with mode: 0644]
test/NUIDnDMultiWindow/shared/res/dragsource.png [new file with mode: 0644]
test/NUIDnDMultiWindow/shared/res/droptarget.png [new file with mode: 0644]
test/NUIDnDMultiWindow/tizen-manifest.xml [new file with mode: 0644]

diff --git a/test/NUIDnDMultiWindow/NUIDnDMultiWindow.cs b/test/NUIDnDMultiWindow/NUIDnDMultiWindow.cs
new file mode 100644 (file)
index 0000000..3d95b34
--- /dev/null
@@ -0,0 +1,214 @@
+
+using Tizen.NUI;
+using Tizen.NUI.Components;
+using Tizen.NUI.BaseComponents;
+
+namespace NUIDnDMultiWindow
+{
+    class Program : NUIApplication
+    {
+        DragAndDrop dnd;
+        ImageView sourceView;
+        ImageView shadowView;
+        ImageView MainWindow_View;
+
+        Window WindowA;
+        ImageView WindowA_ViewA;
+        ImageView WindowA_ViewB;
+
+        Window WindowB;
+        ImageView WindowB_ViewA;
+        ImageView WindowB_ViewB;
+
+        LongPressGestureDetector longPressed;
+        protected override void OnCreate()
+        {
+            base.OnCreate();
+            Initialize();
+        }
+
+        void Initialize()
+        {
+            // Create DnD Instance
+            dnd = DragAndDrop.Instance;
+
+            Window.Instance.KeyEvent += OnKeyEvent;
+            Window.Instance.WindowSize = new Size(900, 1080);
+            Window.Instance.BackgroundColor = Color.White;
+
+            TextLabel text = new TextLabel("Multi-Window Drag And Drop");
+            text.Position = new Position(0, 0);
+            text.TextColor = Color.Black;
+            text.PointSize = 8.0f;
+            Window.Instance.GetDefaultLayer().Add(text);
+
+            TextLabel text2 = new TextLabel("Source View");
+            text2.Position = new Position(330, 330);
+            text2.Size = new Size(400, 150);
+            text2.TextColor = Color.Black;
+            text2.PointSize = 5.0f;
+            text2.MultiLine = true;
+            Window.Instance.GetDefaultLayer().Add(text2);
+
+            TextLabel text3 = new TextLabel("MainWindow View");
+            text3.Position = new Position(100, 700);
+            text3.Size = new Size(400, 150);
+            text3.TextColor = Color.Black;
+            text3.PointSize = 5.0f;
+            text3.MultiLine = true;
+            Window.Instance.GetDefaultLayer().Add(text3);
+            
+            TextLabel text4 = new TextLabel("Window A");
+            text4.Position = new Position(400, 650);
+            text4.Size = new Size(400, 150);
+            text4.TextColor = Color.Black;
+            text4.PointSize = 5.0f;
+            text4.MultiLine = true;
+            Window.Instance.GetDefaultLayer().Add(text4);
+
+            TextLabel text5 = new TextLabel("Window B");
+            text5.Position = new Position(400, 1000);
+            text5.Size = new Size(400, 150);
+            text5.TextColor = Color.Black;
+            text5.PointSize = 5.0f;
+            text5.MultiLine = true;
+            Window.Instance.GetDefaultLayer().Add(text5);
+
+            // Create Source View
+            sourceView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "dragsource.png");
+            sourceView.Size = new Size(200, 200);
+            sourceView.Position = new Position(330, 120);
+            Window.Instance.GetDefaultLayer().Add(sourceView);
+
+            longPressed = new LongPressGestureDetector();
+            longPressed.Attach(sourceView);
+            longPressed.Detected += (s, e) =>
+            {
+              if(e.LongPressGesture.State == Gesture.StateType.Started)
+              {
+                Tizen.Log.Debug("NUIDnDMultiWindow", "StartDragAndDrop");
+                shadowView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png");
+                shadowView.Size = new Size(150, 150);
+                DragData dragData;
+                dragData.MimeType = "text/uri-list";
+                dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png";
+                dnd.StartDragAndDrop(sourceView, shadowView, dragData, OnSourceApp_SourceFunc);
+              }
+            };
+
+            // Create Target MainWindow_View
+            MainWindow_View = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
+            MainWindow_View.Size = new Size(200, 200);
+            MainWindow_View.Position = new Position(100, 500);
+            Window.Instance.GetDefaultLayer().Add(MainWindow_View);
+
+            // Add Drop Target MainWindow_View
+            dnd.AddListener(MainWindow_View, OnSourceApp_TargetFunc);
+
+            // Create Target Window A
+            WindowA = new Window("WindowA", new Rectangle(400, 400, 370, 250), false)
+            {
+                BackgroundColor = Color.BlueViolet,
+            };
+            WindowA.Show();
+            
+            // Create Target WindowA_ViewA
+            WindowA_ViewA = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
+            WindowA_ViewA.Size = new Size(150, 150);
+            WindowA_ViewA.Position = new Position(20, 10);
+            WindowA.GetDefaultLayer().Add(WindowA_ViewA);
+
+            // Add Drop Target WindowA_ViewA
+            dnd.AddListener(WindowA_ViewA, OnSourceApp_TargetFunc);
+
+            // Create Target View WindowA_ViewB
+            WindowA_ViewB = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
+            WindowA_ViewB.Size = new Size(150, 150);
+            WindowA_ViewB.Position = new Position(180, 50);
+            WindowA.GetDefaultLayer().Add(WindowA_ViewB);
+
+            // Add Drop Target WindowA_ViewB
+            dnd.AddListener(WindowA_ViewB, OnSourceApp_TargetFunc);
+
+            // Create Target Window B
+            WindowB = new Window("WindowB", new Rectangle(400, 750, 370, 250), false)
+            {
+                BackgroundColor = Color.LightGoldenRodYellow,
+            };
+            WindowB.Show();
+            
+            // Create Target WindowB_ViewA
+            WindowB_ViewA = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
+            WindowB_ViewA.Size = new Size(150, 150);
+            WindowB_ViewA.Position = new Position(20, 10);
+            WindowB.GetDefaultLayer().Add(WindowB_ViewA);
+
+            // Add Drop Target WindowB_ViewA
+            dnd.AddListener(WindowB_ViewA, OnSourceApp_TargetFunc);
+
+            // Create Target WindowB_ViewB
+            WindowB_ViewB = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
+            WindowB_ViewB.Size = new Size(150, 150);
+            WindowB_ViewB.Position = new Position(180, 50);
+            WindowB.GetDefaultLayer().Add(WindowB_ViewB);
+
+            // Add Drop Target WindowB_ViewB
+            dnd.AddListener(WindowB_ViewB, OnSourceApp_TargetFunc);
+        }
+
+        public void OnSourceApp_SourceFunc(DragSourceEventType type)
+        {
+          if (type == DragSourceEventType.Start)
+          {
+            Tizen.Log.Debug("NUIDnDMultiWindow", "Source App DragSourceEventType: " + "Start");
+          }
+          else if (type == DragSourceEventType.Cancel)
+          {
+            Tizen.Log.Debug("NUIDnDMultiWindow", "Source App DragSourceEventType: " + "Cancel");
+          }
+          else if (type == DragSourceEventType.Accept)
+          {
+            Tizen.Log.Debug("NUIDnDMultiWindow", "Source App DragSourceEventType: " + "Accept");
+          }
+          else if (type == DragSourceEventType.Finish)
+          {
+            Tizen.Log.Debug("NUIDnDMultiWindow", "Source App DragSourceEventType: " + "Finish");
+          }
+        }
+
+        public void OnSourceApp_TargetFunc(View targetView, DragEvent dragEvent)
+        {
+            if (dragEvent.DragType == DragType.Enter)
+            {
+              Tizen.Log.Debug("NUIDnDMultiWindow", "Source App Target A [Enter]");
+            }
+            else if (dragEvent.DragType == DragType.Leave)
+            {
+              Tizen.Log.Debug("NUIDnDMultiWindow", "Source App Target A [Leave]");
+            }
+            else if (dragEvent.DragType == DragType.Move)
+            {
+              Tizen.Log.Debug("NUIDnDMultiWindow", "Source App Target A [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
+            }
+            else if (dragEvent.DragType == DragType.Drop)
+            {
+              Tizen.Log.Debug("NUIDnDMultiWindow", "Source App Target A [Drop] MimeType: " + dragEvent.MimeType + " Data: " + dragEvent.Data);
+              ((ImageView)targetView).ResourceUrl = dragEvent.Data;
+            }
+        }
+
+        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();
+            app.Run(args);
+        }
+    }
+}
diff --git a/test/NUIDnDMultiWindow/NUIDnDMultiWindow.csproj b/test/NUIDnDMultiWindow/NUIDnDMultiWindow.csproj
new file mode 100644 (file)
index 0000000..5c97a2a
--- /dev/null
@@ -0,0 +1,27 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+    <PropertyGroup>
+        <OutputType>Exe</OutputType>
+        <TargetFramework>netcoreapp3.1</TargetFramework>
+    </PropertyGroup>
+
+    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+        <DebugType>portable</DebugType>
+    </PropertyGroup>
+    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+        <DebugType>None</DebugType>
+    </PropertyGroup>
+
+    <ItemGroup>
+        <PackageReference Include="Tizen.NET.Sdk" Version="1.0.9" />
+        <ProjectReference Include="../../src/Tizen/Tizen.csproj" />
+        <ProjectReference Include="../../src/Tizen.NUI.Components/Tizen.NUI.Components.csproj" />
+        <ProjectReference Include="../../src/Tizen.NUI/Tizen.NUI.csproj" />
+    </ItemGroup>
+
+    <PropertyGroup>
+        <NeedInjection>True</NeedInjection>
+    </PropertyGroup>
+
+</Project>
+
diff --git a/test/NUIDnDMultiWindow/res/dragsource.png b/test/NUIDnDMultiWindow/res/dragsource.png
new file mode 100644 (file)
index 0000000..2aaa05c
Binary files /dev/null and b/test/NUIDnDMultiWindow/res/dragsource.png differ
diff --git a/test/NUIDnDMultiWindow/res/droptarget.png b/test/NUIDnDMultiWindow/res/droptarget.png
new file mode 100644 (file)
index 0000000..9d1bd7e
Binary files /dev/null and b/test/NUIDnDMultiWindow/res/droptarget.png differ
diff --git a/test/NUIDnDMultiWindow/shared/res/NUIDnDMultiWindow.png b/test/NUIDnDMultiWindow/shared/res/NUIDnDMultiWindow.png
new file mode 100644 (file)
index 0000000..62d0dff
Binary files /dev/null and b/test/NUIDnDMultiWindow/shared/res/NUIDnDMultiWindow.png differ
diff --git a/test/NUIDnDMultiWindow/shared/res/dragsource.png b/test/NUIDnDMultiWindow/shared/res/dragsource.png
new file mode 100644 (file)
index 0000000..2aaa05c
Binary files /dev/null and b/test/NUIDnDMultiWindow/shared/res/dragsource.png differ
diff --git a/test/NUIDnDMultiWindow/shared/res/droptarget.png b/test/NUIDnDMultiWindow/shared/res/droptarget.png
new file mode 100644 (file)
index 0000000..9d1bd7e
Binary files /dev/null and b/test/NUIDnDMultiWindow/shared/res/droptarget.png differ
diff --git a/test/NUIDnDMultiWindow/tizen-manifest.xml b/test/NUIDnDMultiWindow/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..25ad830
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns="http://tizen.org/ns/packages" api-version="6" package="org.tizen.example.NUIDnDMultiWindow" version="1.0.0">
+  <profile name="common" />
+  <ui-application appid="org.tizen.example.NUIDnDMultiWindow"
+                                       exec="NUIDnDMultiWindow.dll"
+                                       type="dotnet-nui"
+                                       multiple="false"
+                                       taskmanage="true"
+                                       nodisplay="false"
+                                       launch_mode="single"
+          >
+    <label>NUIDnDMultiWindow</label>
+    <icon>NUIDnDMultiWindow.png</icon>
+    <metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
+  </ui-application>
+</manifest>