Update nightly-release.yml
[platform/core/csapi/tizenfx.git] / test / NUIDnDSource / NUIDnDSource.cs
1 
2 using Tizen.NUI;
3 using Tizen.NUI.Components;
4 using Tizen.NUI.BaseComponents;
5
6 namespace NUIDnDSource
7 {
8     class Program : NUIApplication
9     {
10         ImageView sourceView;
11         ImageView shadowView;
12         ImageView targetViewA;
13         ImageView targetViewB;
14         DragAndDrop dnd;
15
16         LongPressGestureDetector longPressed;
17         protected override void OnCreate()
18         {
19             base.OnCreate();
20             Initialize();
21         }
22
23         void Initialize()
24         {
25             // Create DnD Instance
26             dnd = DragAndDrop.Instance;
27
28             Window.Instance.KeyEvent += OnKeyEvent;
29             Window.Instance.WindowSize = new Size(900, 1080);
30             Window.Instance.BackgroundColor = Color.White;
31
32             TextLabel text = new TextLabel("DragSource Application");
33             text.Position = new Position(0, 0);
34             text.TextColor = Color.Black;
35             text.PointSize = 10.0f;
36             Window.Instance.GetDefaultLayer().Add(text);
37
38             TextLabel text2 = new TextLabel("This sample demonstrates NUI DnD functionality and is the 'source' app for this sample.");
39             text2.Position = new Position(0, 70);
40             text2.Size = new Size(900, 150);
41             text2.TextColor = Color.Black;
42             text2.PointSize = 7.0f;
43             text2.MultiLine = true;
44             Window.Instance.GetDefaultLayer().Add(text2);
45
46             // Create Source View
47             sourceView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "dragsource.png");
48             sourceView.Size = new Size(250, 250);
49             sourceView.Position = new Position(300, 230);
50             Window.Instance.GetDefaultLayer().Add(sourceView);
51
52             TextLabel text3 = new TextLabel("This image can be dragged, Try dragging it to the area below.");
53             text3.Position = new Position(0, 520);
54             text3.Size = new Size(900, 150);
55             text3.TextColor = Color.Black;
56             text3.PointSize = 7.0f;
57             text3.MultiLine = true;
58             Window.Instance.GetDefaultLayer().Add(text3);
59             
60             TextLabel text4 = new TextLabel("Drop your image here");
61             text4.Position = new Position(300, 940);
62             text4.TextColor = Color.Black;
63             text4.PointSize = 7.0f;
64             Window.Instance.GetDefaultLayer().Add(text4);
65
66             // Create Target View A
67             targetViewA = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
68             targetViewA.Size = new Size(250, 250);
69             targetViewA.Position = new Position(135, 650);
70             Window.Instance.GetDefaultLayer().Add(targetViewA);
71
72             // Add Drop Target A
73             dnd.AddListener(targetViewA, OnSourceAppDnDFuncA);
74
75             // Create Target View B
76             targetViewB = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
77             targetViewB.Size = new Size(250, 250);
78             targetViewB.Position = new Position(485, 650);
79             Window.Instance.GetDefaultLayer().Add(targetViewB);
80
81             // Add Drop Target B
82             dnd.AddListener(targetViewB, OnSourceAppDnDFuncB);
83
84             longPressed = new LongPressGestureDetector();
85             longPressed.Attach(sourceView);
86             longPressed.Detected += (s, e) =>
87             {
88               if(e.LongPressGesture.State == Gesture.StateType.Started)
89               {
90                 Tizen.Log.Debug("NUIDnDSource", "StartDragAndDrop");
91                 shadowView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png");
92                 shadowView.Size = new Size(150, 150);
93                 DragData dragData;
94                 dragData.MimeType = "text/uri-list";
95                 dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png";
96                 dnd.StartDragAndDrop(sourceView, shadowView, dragData, OnSourceEventFunc);
97               }
98             };
99         }
100
101         public void OnSourceAppDnDFuncA(View targetView, DragEvent dragEvent)
102         {
103             if (dragEvent.DragType == DragType.Enter)
104             {
105               Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Enter]");
106             }
107             else if (dragEvent.DragType == DragType.Leave)
108             {
109               Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Leave]");
110             }
111             else if (dragEvent.DragType == DragType.Move)
112             {
113               Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
114             }
115             else if (dragEvent.DragType == DragType.Drop)
116             {
117               Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Drop] MimeType: " + dragEvent.MimeType + " Data: " + dragEvent.Data);
118               targetViewA.ResourceUrl = dragEvent.Data;
119             }
120         }
121
122         public void OnSourceAppDnDFuncB(View targetView, DragEvent dragEvent)
123         {
124             if (dragEvent.DragType == DragType.Enter)
125             {
126               Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Enter]");
127             }
128             else if (dragEvent.DragType == DragType.Leave)
129             {
130               Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Leave]");
131             }
132             else if (dragEvent.DragType == DragType.Move)
133             {
134               Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
135             }
136             else if (dragEvent.DragType == DragType.Drop)
137             {
138               Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Drop] MimeType: " + dragEvent.MimeType + " Data: " + dragEvent.Data);
139               targetViewB.ResourceUrl = dragEvent.Data;
140             }
141         }
142
143         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
144         {
145             if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
146             {
147                 Exit();
148             }
149         }
150
151         public void OnSourceEventFunc(DragSourceEventType type)
152         {
153           if (type == DragSourceEventType.Start)
154           {
155             Tizen.Log.Debug("NUIDnDSource", "Source App DragSourceEventType: " + "Start");
156           }
157           else if (type == DragSourceEventType.Cancel)
158           {
159             Tizen.Log.Debug("NUIDnDSource", "Source App DragSourceEventType: " + "Cancel");
160           }
161           else if (type == DragSourceEventType.Accept)
162           {
163             Tizen.Log.Debug("NUIDnDSource", "Source App DragSourceEventType: " + "Accept");
164           }
165           else if (type == DragSourceEventType.Finish)
166           {
167             Tizen.Log.Debug("NUIDnDSource", "Source App DragSourceEventType: " + "Finish");
168           }
169         }
170
171         static void Main(string[] args)
172         {
173             var app = new Program();
174             app.Run(args);
175         }
176     }
177 }