[NUI] Add New NUI DnD Class and Demo
authorTaehyub Kim <taehyub.kim@samsung.com>
Fri, 17 Dec 2021 09:32:16 +0000 (18:32 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 10 Mar 2022 08:03:31 +0000 (17:03 +0900)
DragAndDrop Class supports the drag and drop functionality in the single window and sub-windows in an application.
Also It supports the application to application drag and drop functionality for multi-window feature.

Class
   Tizen.NUI.DragAndDrop

Dependency
   dali-adaptor : https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-adaptor/+/263704/
   dali-csharp-binder : https://review.tizen.org/gerrit/#/c/platform/core/uifw/dali-csharp-binder/+/268209/

API Changes
 public bool StartDragAndDrop(View sourceView, View shadowView, string data)
 - Start drag and drop to send the data form sourceView to targetView.
 - sourceView means the NUI View to move.
 - shadowView means the half-transparent NUI ImageView of drag object, user should be add this image.
 - data means the data to send to the target view.
 public bool AddListener(View targetView, DragAndDropEventHandler callback)
 - Add listener to receive the drag event.
 - targetView means the NUI View to receive drag event
 - callback will be called when the drag event is emitted.
 public enum DragType
 public struct DragEvent
 public delegate void DragAndDropEventHandler(DragEvent dragEvent)

16 files changed:
src/Tizen.NUI/src/internal/Interop/Interop.DragAndDrop.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/DragAndDrop/DragAndDrop.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/DragAndDrop/DragEvent.cs [new file with mode: 0755]
test/NUIDnDSource/NUIDnDSource.cs [new file with mode: 0644]
test/NUIDnDSource/NUIDnDSource.csproj [new file with mode: 0644]
test/NUIDnDSource/res/dragsource.png [new file with mode: 0644]
test/NUIDnDSource/res/droptarget.png [new file with mode: 0644]
test/NUIDnDSource/shared/res/NUIDnDSource.png [new file with mode: 0644]
test/NUIDnDSource/shared/res/dragsource.png [new file with mode: 0644]
test/NUIDnDSource/shared/res/droptarget.png [new file with mode: 0644]
test/NUIDnDSource/tizen-manifest.xml [new file with mode: 0644]
test/NUIDnDTarget/NUIDnDTarget.cs [new file with mode: 0644]
test/NUIDnDTarget/NUIDnDTarget.csproj [new file with mode: 0644]
test/NUIDnDTarget/res/droptarget.png [new file with mode: 0644]
test/NUIDnDTarget/shared/res/NUIDnDTarget.png [new file with mode: 0644]
test/NUIDnDTarget/tizen-manifest.xml [new file with mode: 0644]

diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.DragAndDrop.cs b/src/Tizen.NUI/src/internal/Interop/Interop.DragAndDrop.cs
new file mode 100755 (executable)
index 0000000..d440590
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ *
+ */
+
+namespace Tizen.NUI
+{
+    internal static partial class Interop
+    {
+        internal static partial class DragAndDrop
+        {
+            internal enum DragType
+            {
+                Enter,
+                Leave,
+                Move,
+                Drop
+            }
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_New__SWIG_0")]
+            public static extern global::System.IntPtr New();
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_StartDragAndDrop")]
+            public static extern bool StartDragAndDrop(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef sourceView, global::System.Runtime.InteropServices.HandleRef shadow, string mimeType, string data);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_AddListener")]
+            public static extern bool AddListener(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef targetView, global::System.Runtime.InteropServices.HandleRef callback);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_RemoveListener")]
+            public static extern bool RemoveListener(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef targetView, global::System.Runtime.InteropServices.HandleRef callback);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragEvent_GetAction")]
+            public static extern int GetAction(global::System.IntPtr dragAndDrop);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragEvent_GetPosition")]
+            public static extern global::System.IntPtr GetPosition(global::System.IntPtr dragAndDrop);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragEvent_GetMimeType")]
+            public static extern string GetMimeType(global::System.IntPtr dragAndDrop);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragEvent_GetData")]
+            public static extern string GetData(global::System.IntPtr dragAndDrop);
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/public/DragAndDrop/DragAndDrop.cs b/src/Tizen.NUI/src/public/DragAndDrop/DragAndDrop.cs
new file mode 100755 (executable)
index 0000000..19f3e9a
--- /dev/null
@@ -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.ComponentModel;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// DragAndDrop controls the drag objet and data.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class DragAndDrop : BaseHandle
+    {
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate void DragAndDropEventHandler(View targetView, DragEvent dragEvent);
+        private delegate void InternalDragAndDropEventHandler(global::System.IntPtr dragEvent);
+        private Dictionary<View, InternalDragAndDropEventHandler> targetEventDictionary = new Dictionary<View, InternalDragAndDropEventHandler>();
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        private DragAndDrop() : this(Interop.DragAndDrop.New(), true)
+        {
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        private DragAndDrop(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
+        {
+
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static DragAndDrop Instance { get; } = new DragAndDrop();
+
+        /// <summary>
+        /// Starts drag and drop.
+        /// </summary>
+        /// <param name="sourceView">The soruce view</param>
+        /// <param name="shadowView">The shadow view for drag object</param>
+        /// <param name="dragData">The data to send</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void StartDragAndDrop(View sourceView, View shadowView, DragData dragData)
+        {
+            if (!Interop.DragAndDrop.StartDragAndDrop(SwigCPtr, View.getCPtr(sourceView), View.getCPtr(shadowView), dragData.MimeType, dragData.Data))
+            {
+                throw new InvalidOperationException("Fail to StartDragAndDrop");
+            }
+        }
+
+        /// <summary>
+        /// Adds listener for drop targets
+        /// </summary>
+        /// <param name="targetView">The target view</param>
+        /// <param name="callback">The callback function to get drag event</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void AddListener(View targetView, DragAndDropEventHandler callback)
+        {
+            InternalDragAndDropEventHandler cb = (dragEvent) =>
+            {
+                DragType type = (DragType)Interop.DragAndDrop.GetAction(dragEvent);
+                DragEvent ev = new DragEvent();
+                global::System.IntPtr cPtr = Interop.DragAndDrop.GetPosition(dragEvent);
+                ev.Position = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false);
+
+                if (type == DragType.Enter)
+                {
+                    ev.DragType = type;
+                    callback(targetView, ev);
+                }
+                else if (type == DragType.Leave)
+                {
+                    ev.DragType = type;
+                    callback(targetView, ev);
+                }
+                else if (type == DragType.Move)
+                {
+                    ev.DragType = type;
+                    callback(targetView, ev);
+                }
+                else if (type == DragType.Drop)
+                {
+                    ev.DragType = type;
+                    ev.MimeType = Interop.DragAndDrop.GetMimeType(dragEvent);
+                    ev.Data = Interop.DragAndDrop.GetData(dragEvent);
+                    callback(targetView, ev);
+                }
+            };
+
+            targetEventDictionary.Add(targetView, cb);
+
+            if (!Interop.DragAndDrop.AddListener(SwigCPtr, View.getCPtr(targetView),
+                                                 new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(cb))))
+            {
+                 throw new InvalidOperationException("Fail to AddListener");
+            }
+        }
+
+        /// <summary>
+        /// Removes listener for drop targets
+        /// </summary>
+        /// <param name="targetView">The target view</param>
+        /// <param name="callback">The callback function to remove</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void RemoveListener(View targetView, DragAndDropEventHandler callback)
+        {
+            if (!targetEventDictionary.ContainsKey(targetView))
+            {
+                 throw new InvalidOperationException("Fail to RemoveListener");
+            }
+
+            InternalDragAndDropEventHandler cb = targetEventDictionary[targetView];
+            targetEventDictionary.Remove(targetView);
+            if (!Interop.DragAndDrop.RemoveListener(SwigCPtr, View.getCPtr(targetView),
+                                                    new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(cb))))
+            {
+                 throw new InvalidOperationException("Fail to RemoveListener");
+            }
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/public/DragAndDrop/DragEvent.cs b/src/Tizen.NUI/src/public/DragAndDrop/DragEvent.cs
new file mode 100755 (executable)
index 0000000..71cb4dc
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * 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 Tizen.NUI.Binding;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// This specifies drag data.
+    /// </summary>
+    /// Suppress warning : This struct will be used data of callback, so override equals and operator does not necessary.
+    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815: Override equals and operator equals on value types")]
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public struct DragData
+    {
+        /// <summary>
+        /// The mime type of drag data
+        /// </summary>
+        public string MimeType { get; set; }
+        /// <summary>
+        /// The drag data to send
+        /// </summary>
+        public string Data { get; set; }
+    }
+
+    /// <summary>
+    /// Drag event type.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public enum DragType
+    {
+        /// <summary>
+        /// The drag object has entered the target view.
+        /// </summary>
+        Enter,
+        /// <summary>
+        /// The drag object has leaved the target view.
+        /// </summary>
+        Leave,
+        /// <summary>
+        /// The drag object moves in the target view.
+        /// </summary>
+        Move,
+        /// <summary>
+        /// The drag object dropped in the target view.
+        /// </summary>
+        Drop
+    }
+
+    /// <summary>
+    /// This specifies drag event.
+    /// </summary>
+    /// Suppress warning : This struct will be used data of callback, so override equals and operator does not necessary.
+    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815: Override equals and operator equals on value types")]
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public struct DragEvent
+    {
+        /// <summary>
+        /// The drag event type
+        /// </summary>
+        public DragType DragType { get; set; }
+        /// <summary>
+        /// The drag object position in target view
+        /// </summary>
+        public Position Position  { get; set; }
+        /// <summary>
+        /// The mime type of drag object
+        /// </summary>
+        public string MimeType { get; set; }
+        /// <summary>
+        /// The drag data to receive
+        /// </summary>
+        public string Data { get; set; }
+    }
+}
diff --git a/test/NUIDnDSource/NUIDnDSource.cs b/test/NUIDnDSource/NUIDnDSource.cs
new file mode 100644 (file)
index 0000000..c7a9353
--- /dev/null
@@ -0,0 +1,153 @@
+
+using Tizen.NUI;
+using Tizen.NUI.Components;
+using Tizen.NUI.BaseComponents;
+
+namespace NUIDnDSource
+{
+    class Program : NUIApplication
+    {
+        ImageView sourceView;
+        ImageView shadowView;
+        ImageView targetViewA;
+        ImageView targetViewB;
+        DragAndDrop dnd;
+        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;
+            Window.Instance.TouchEvent += OnTouchEvent;
+
+            TextLabel text = new TextLabel("DragSource Application");
+            text.Position = new Position(0, 0);
+            text.TextColor = Color.Black;
+            text.PointSize = 10.0f;
+            Window.Instance.GetDefaultLayer().Add(text);
+
+            TextLabel text2 = new TextLabel("This sample demonstrates NUI DnD functionality and is the 'source' app for this sample.");
+            text2.Position = new Position(0, 70);
+            text2.Size = new Size(900, 150);
+            text2.TextColor = Color.Black;
+            text2.PointSize = 7.0f;
+            text2.MultiLine = true;
+            Window.Instance.GetDefaultLayer().Add(text2);
+
+            // Create Source View
+            sourceView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "dragsource.png");
+            sourceView.Size = new Size(250, 250);
+            sourceView.Position = new Position(300, 230);
+            Window.Instance.GetDefaultLayer().Add(sourceView);
+
+            TextLabel text3 = new TextLabel("This image can be dragged, Try dragging it to the area below.");
+            text3.Position = new Position(0, 520);
+            text3.Size = new Size(900, 150);
+            text3.TextColor = Color.Black;
+            text3.PointSize = 7.0f;
+            text3.MultiLine = true;
+            Window.Instance.GetDefaultLayer().Add(text3);
+            
+            TextLabel text4 = new TextLabel("Drop your image here");
+            text4.Position = new Position(300, 940);
+            text4.TextColor = Color.Black;
+            text4.PointSize = 7.0f;
+            Window.Instance.GetDefaultLayer().Add(text4);
+
+            // Create Target View A
+            targetViewA = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
+            targetViewA.Size = new Size(250, 250);
+            targetViewA.Position = new Position(135, 650);
+            Window.Instance.GetDefaultLayer().Add(targetViewA);
+
+            // Add Drop Target A
+            dnd.AddListener(targetViewA, OnSourceAppDnDFuncA);
+
+            // Create Target View B
+            targetViewB = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
+            targetViewB.Size = new Size(250, 250);
+            targetViewB.Position = new Position(485, 650);
+            Window.Instance.GetDefaultLayer().Add(targetViewB);
+
+            // Add Drop Target B
+            dnd.AddListener(targetViewB, OnSourceAppDnDFuncB);
+        }
+
+        public void OnSourceAppDnDFuncA(View targetView, DragEvent dragEvent)
+        {
+            if (dragEvent.DragType == DragType.Enter)
+            {
+              Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Enter]");
+            }
+            else if (dragEvent.DragType == DragType.Leave)
+            {
+              Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Leave]");
+            }
+            else if (dragEvent.DragType == DragType.Move)
+            {
+              Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
+            }
+            else if (dragEvent.DragType == DragType.Drop)
+            {
+              Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Drop] MimeType: " + dragEvent.MimeType + " Data: " + dragEvent.Data);
+              targetViewA.ResourceUrl = dragEvent.Data;
+            }
+        }
+
+        public void OnSourceAppDnDFuncB(View targetView, DragEvent dragEvent)
+        {
+            if (dragEvent.DragType == DragType.Enter)
+            {
+              Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Enter]");
+            }
+            else if (dragEvent.DragType == DragType.Leave)
+            {
+              Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Leave]");
+            }
+            else if (dragEvent.DragType == DragType.Move)
+            {
+              Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
+            }
+            else if (dragEvent.DragType == DragType.Drop)
+            {
+              Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Drop] MimeType: " + dragEvent.MimeType + " Data: " + dragEvent.Data);
+              targetViewB.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();
+            }
+        }
+
+        private void OnTouchEvent(object source, Window.TouchEventArgs e)
+        {
+            if (e.Touch.GetState(0) == PointStateType.Down)
+            {
+                Tizen.Log.Debug("NUIDnDSource", "StartDragAndDrop");
+                shadowView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png");
+                DragData dragData;
+                dragData.MimeType = "text/uri-list";
+                dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png";
+                dnd.StartDragAndDrop(sourceView, shadowView, dragData);
+            }
+        }
+
+        static void Main(string[] args)
+        {
+            var app = new Program();
+            app.Run(args);
+        }
+    }
+}
diff --git a/test/NUIDnDSource/NUIDnDSource.csproj b/test/NUIDnDSource/NUIDnDSource.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/NUIDnDSource/res/dragsource.png b/test/NUIDnDSource/res/dragsource.png
new file mode 100644 (file)
index 0000000..2aaa05c
Binary files /dev/null and b/test/NUIDnDSource/res/dragsource.png differ
diff --git a/test/NUIDnDSource/res/droptarget.png b/test/NUIDnDSource/res/droptarget.png
new file mode 100644 (file)
index 0000000..9d1bd7e
Binary files /dev/null and b/test/NUIDnDSource/res/droptarget.png differ
diff --git a/test/NUIDnDSource/shared/res/NUIDnDSource.png b/test/NUIDnDSource/shared/res/NUIDnDSource.png
new file mode 100644 (file)
index 0000000..9f3cb98
Binary files /dev/null and b/test/NUIDnDSource/shared/res/NUIDnDSource.png differ
diff --git a/test/NUIDnDSource/shared/res/dragsource.png b/test/NUIDnDSource/shared/res/dragsource.png
new file mode 100644 (file)
index 0000000..2aaa05c
Binary files /dev/null and b/test/NUIDnDSource/shared/res/dragsource.png differ
diff --git a/test/NUIDnDSource/shared/res/droptarget.png b/test/NUIDnDSource/shared/res/droptarget.png
new file mode 100644 (file)
index 0000000..9d1bd7e
Binary files /dev/null and b/test/NUIDnDSource/shared/res/droptarget.png differ
diff --git a/test/NUIDnDSource/tizen-manifest.xml b/test/NUIDnDSource/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..bea10a7
--- /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.NUIDnDSource" version="1.0.0">
+  <profile name="common" />
+  <ui-application appid="org.tizen.example.NUIDnDSource"
+                                       exec="NUIDnDSource.dll"
+                                       type="dotnet"
+                                       multiple="false"
+                                       taskmanage="true"
+                                       nodisplay="false"
+                                       launch_mode="single"
+          >
+    <label>NUIDnDSource</label>
+    <icon>NUIDnDSource.png</icon>
+    <metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
+  </ui-application>
+</manifest>
diff --git a/test/NUIDnDTarget/NUIDnDTarget.cs b/test/NUIDnDTarget/NUIDnDTarget.cs
new file mode 100644 (file)
index 0000000..2a087a7
--- /dev/null
@@ -0,0 +1,123 @@
+using System;
+using Tizen.NUI;
+using Tizen.NUI.Components;
+using Tizen.NUI.BaseComponents;
+
+namespace NUIDnDTarget
+{
+    class Program : NUIApplication
+    {
+        ImageView targetViewA;
+        ImageView targetViewB;
+        DragAndDrop dnd;
+        protected override void OnCreate()
+        {
+            base.OnCreate();
+            Initialize();
+        }
+
+        void Initialize()
+        {
+            // Create DnD Instance
+            dnd = DragAndDrop.Instance;
+
+            Window.Instance.KeyEvent += OnKeyEvent;
+            Window.Instance.WindowPosition = new Position(1020, 0); 
+            Window.Instance.WindowSize = new Size(900, 1080); 
+            Window.Instance.BackgroundColor = Color.White;
+
+            TextLabel text = new TextLabel("DropTarget Application");
+            text.Position = new Position(0, 0);
+            text.TextColor = Color.Black;
+            text.PointSize = 10.0f;
+            Window.Instance.GetDefaultLayer().Add(text);
+
+            TextLabel text2 = new TextLabel("This sample demonstrates NUI DnD functionality and is the 'target' app for this sample.");
+            text2.Position = new Position(0, 70);
+            text2.TextColor = Color.Black;
+            text2.PointSize = 7.0f;
+            text2.MultiLine = true;
+            Window.Instance.GetDefaultLayer().Add(text2);
+
+            // Create Target View A
+            targetViewA = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
+            targetViewA.Size = new Size(300, 300);
+            targetViewA.Position = new Position(100, 235);
+            Window.Instance.GetDefaultLayer().Add(targetViewA);
+
+            // Add Drop Target A
+            dnd.AddListener(targetViewA, OnTargetAppDnDFuncA);
+
+            // Create Target View B
+            targetViewB = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
+            targetViewB.Size = new Size(300, 300);
+            targetViewB.Position = new Position(100, 585);
+            Window.Instance.GetDefaultLayer().Add(targetViewB);
+
+            // Add Drop Target B
+            dnd.AddListener(targetViewB, OnTargetAppDnDFuncB);
+
+            TextLabel text3 = new TextLabel("Drop your image here.");
+            text3.Position = new Position(500, 355);
+            text3.TextColor = Color.Black;
+            text3.PointSize = 7.0f;
+            Window.Instance.GetDefaultLayer().Add(text3);
+        }
+
+        public void OnTargetAppDnDFuncA(View targetView, DragEvent dragEvent)
+        {
+            if (dragEvent.DragType == DragType.Enter)
+            {
+              Tizen.Log.Error("NUIDnDTarget", "Target App Target A [Enter]");
+            }
+            else if (dragEvent.DragType == DragType.Leave)
+            {
+              Tizen.Log.Error("NUIDnDTarget", "Target App Target A [Leave]");
+            }
+            else if (dragEvent.DragType == DragType.Move)
+            {
+              Tizen.Log.Error("NUIDnDTarget", "Target App Target A [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
+            }
+            else if (dragEvent.DragType == DragType.Drop)
+            {
+              Tizen.Log.Error("NUIDnDTarget", "Target App Target A [Drop] MimeType: " +  dragEvent.MimeType + " Data: " + dragEvent.Data);
+              targetViewA.ResourceUrl = dragEvent.Data;
+            }
+        }
+
+        public void OnTargetAppDnDFuncB(View targetView, DragEvent dragEvent)
+        {
+            if (dragEvent.DragType == DragType.Enter)
+            {
+              Tizen.Log.Error("NUIDnDTarget", "Target App Target B [Enter]");
+            }
+            else if (dragEvent.DragType == DragType.Leave)
+            {
+              Tizen.Log.Error("NUIDnDTarget", "Target App Target B [Leave]");
+            }
+            else if (dragEvent.DragType == DragType.Move)
+            {
+              Tizen.Log.Error("NUIDnDTarget", "Target App Target B [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
+            }
+            else if (dragEvent.DragType == DragType.Drop)
+            {
+              Tizen.Log.Error("NUIDnDTarget", "Target App Target B [Drop] MimeType: " +  dragEvent.MimeType + " Data: " + dragEvent.Data);
+              targetViewB.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/NUIDnDTarget/NUIDnDTarget.csproj b/test/NUIDnDTarget/NUIDnDTarget.csproj
new file mode 100644 (file)
index 0000000..8702ced
--- /dev/null
@@ -0,0 +1,26 @@
+<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.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/NUIDnDTarget/res/droptarget.png b/test/NUIDnDTarget/res/droptarget.png
new file mode 100644 (file)
index 0000000..9d1bd7e
Binary files /dev/null and b/test/NUIDnDTarget/res/droptarget.png differ
diff --git a/test/NUIDnDTarget/shared/res/NUIDnDTarget.png b/test/NUIDnDTarget/shared/res/NUIDnDTarget.png
new file mode 100644 (file)
index 0000000..9f3cb98
Binary files /dev/null and b/test/NUIDnDTarget/shared/res/NUIDnDTarget.png differ
diff --git a/test/NUIDnDTarget/tizen-manifest.xml b/test/NUIDnDTarget/tizen-manifest.xml
new file mode 100644 (file)
index 0000000..6738a3b
--- /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.NUIDnDTarget" version="1.0.0">
+  <profile name="common" />
+  <ui-application appid="org.tizen.example.NUIDnDTarget"
+                                       exec="NUIDnDTarget.dll"
+                                       type="dotnet"
+                                       multiple="false"
+                                       taskmanage="true"
+                                       nodisplay="false"
+                                       launch_mode="single"
+          >
+    <label>NUIDnDTarget</label>
+    <icon>NUIDnDTarget.png</icon>
+    <metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
+  </ui-application>
+</manifest>