Release 10.0.0.17318
[platform/core/csapi/tizenfx.git] / test / NUIDnDTarget / NUIDnDTarget.cs
1 using System;
2 using Tizen.NUI;
3 using Tizen.NUI.Components;
4 using Tizen.NUI.BaseComponents;
5
6 namespace NUIDnDTarget
7 {
8     class Program : NUIApplication
9     {
10         ImageView targetViewA;
11         ImageView targetViewB;
12         DragAndDrop dnd;
13         protected override void OnCreate()
14         {
15             base.OnCreate();
16             Initialize();
17         }
18
19         void Initialize()
20         {
21             // Create DnD Instance
22             dnd = DragAndDrop.Instance;
23
24             Window.Instance.KeyEvent += OnKeyEvent;
25             Window.Instance.WindowPosition = new Position(1020, 0); 
26             Window.Instance.WindowSize = new Size(900, 1080); 
27             Window.Instance.BackgroundColor = Color.White;
28
29             TextLabel text = new TextLabel("DropTarget Application");
30             text.Position = new Position(0, 0);
31             text.TextColor = Color.Black;
32             text.PointSize = 10.0f;
33             Window.Instance.GetDefaultLayer().Add(text);
34
35             TextLabel text2 = new TextLabel("This sample demonstrates NUI DnD functionality and is the 'target' app for this sample.");
36             text2.Position = new Position(0, 70);
37             text2.TextColor = Color.Black;
38             text2.PointSize = 7.0f;
39             text2.MultiLine = true;
40             Window.Instance.GetDefaultLayer().Add(text2);
41
42             // Create Target View A
43             targetViewA = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
44             targetViewA.Size = new Size(300, 300);
45             targetViewA.Position = new Position(100, 235);
46             Window.Instance.GetDefaultLayer().Add(targetViewA);
47
48             // Add Drop Target A
49             dnd.AddListener(targetViewA, OnTargetAppDnDFuncA);
50
51             // Create Target View B
52             targetViewB = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
53             targetViewB.Size = new Size(300, 300);
54             targetViewB.Position = new Position(100, 585);
55             Window.Instance.GetDefaultLayer().Add(targetViewB);
56
57             // Add Drop Target B
58             dnd.AddListener(targetViewB, OnTargetAppDnDFuncB);
59
60             TextLabel text3 = new TextLabel("Drop your image here.");
61             text3.Position = new Position(500, 355);
62             text3.TextColor = Color.Black;
63             text3.PointSize = 7.0f;
64             Window.Instance.GetDefaultLayer().Add(text3);
65         }
66
67         public void OnTargetAppDnDFuncA(View targetView, DragEvent dragEvent)
68         {
69             if (dragEvent.DragType == DragType.Enter)
70             {
71               Tizen.Log.Error("NUIDnDTarget", "Target App Target A [Enter]");
72             }
73             else if (dragEvent.DragType == DragType.Leave)
74             {
75               Tizen.Log.Error("NUIDnDTarget", "Target App Target A [Leave]");
76             }
77             else if (dragEvent.DragType == DragType.Move)
78             {
79               Tizen.Log.Error("NUIDnDTarget", "Target App Target A [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
80             }
81             else if (dragEvent.DragType == DragType.Drop)
82             {
83               Tizen.Log.Error("NUIDnDTarget", "Target App Target A [Drop] MimeType: " +  dragEvent.MimeType + " Data: " + dragEvent.Data);
84               targetViewA.ResourceUrl = dragEvent.Data;
85             }
86         }
87
88         public void OnTargetAppDnDFuncB(View targetView, DragEvent dragEvent)
89         {
90             if (dragEvent.DragType == DragType.Enter)
91             {
92               Tizen.Log.Error("NUIDnDTarget", "Target App Target B [Enter]");
93             }
94             else if (dragEvent.DragType == DragType.Leave)
95             {
96               Tizen.Log.Error("NUIDnDTarget", "Target App Target B [Leave]");
97             }
98             else if (dragEvent.DragType == DragType.Move)
99             {
100               Tizen.Log.Error("NUIDnDTarget", "Target App Target B [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
101             }
102             else if (dragEvent.DragType == DragType.Drop)
103             {
104               Tizen.Log.Error("NUIDnDTarget", "Target App Target B [Drop] MimeType: " +  dragEvent.MimeType + " Data: " + dragEvent.Data);
105               targetViewB.ResourceUrl = dragEvent.Data;
106             }
107         }
108
109         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
110         {
111             if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
112             {
113                 Exit();
114             }
115         }
116
117         static void Main(string[] args)
118         {
119             var app = new Program();
120             app.Run(args);
121         }
122     }
123 }