DragAndDrop : Add multi-window sample
[platform/core/csapi/tizenfx.git] / test / NUIDnDMultiWindow / NUIDnDMultiWindow.cs
1 
2 using Tizen.NUI;
3 using Tizen.NUI.Components;
4 using Tizen.NUI.BaseComponents;
5
6 namespace NUIDnDMultiWindow
7 {
8     class Program : NUIApplication
9     {
10         DragAndDrop dnd;
11         ImageView sourceView;
12         ImageView shadowView;
13         ImageView MainWindow_View;
14
15         Window WindowA;
16         ImageView WindowA_ViewA;
17         ImageView WindowA_ViewB;
18
19         Window WindowB;
20         ImageView WindowB_ViewA;
21         ImageView WindowB_ViewB;
22
23         LongPressGestureDetector longPressed;
24         protected override void OnCreate()
25         {
26             base.OnCreate();
27             Initialize();
28         }
29
30         void Initialize()
31         {
32             // Create DnD Instance
33             dnd = DragAndDrop.Instance;
34
35             Window.Instance.KeyEvent += OnKeyEvent;
36             Window.Instance.WindowSize = new Size(900, 1080);
37             Window.Instance.BackgroundColor = Color.White;
38
39             TextLabel text = new TextLabel("Multi-Window Drag And Drop");
40             text.Position = new Position(0, 0);
41             text.TextColor = Color.Black;
42             text.PointSize = 8.0f;
43             Window.Instance.GetDefaultLayer().Add(text);
44
45             TextLabel text2 = new TextLabel("Source View");
46             text2.Position = new Position(330, 330);
47             text2.Size = new Size(400, 150);
48             text2.TextColor = Color.Black;
49             text2.PointSize = 5.0f;
50             text2.MultiLine = true;
51             Window.Instance.GetDefaultLayer().Add(text2);
52
53             TextLabel text3 = new TextLabel("MainWindow View");
54             text3.Position = new Position(100, 700);
55             text3.Size = new Size(400, 150);
56             text3.TextColor = Color.Black;
57             text3.PointSize = 5.0f;
58             text3.MultiLine = true;
59             Window.Instance.GetDefaultLayer().Add(text3);
60             
61             TextLabel text4 = new TextLabel("Window A");
62             text4.Position = new Position(400, 650);
63             text4.Size = new Size(400, 150);
64             text4.TextColor = Color.Black;
65             text4.PointSize = 5.0f;
66             text4.MultiLine = true;
67             Window.Instance.GetDefaultLayer().Add(text4);
68
69             TextLabel text5 = new TextLabel("Window B");
70             text5.Position = new Position(400, 1000);
71             text5.Size = new Size(400, 150);
72             text5.TextColor = Color.Black;
73             text5.PointSize = 5.0f;
74             text5.MultiLine = true;
75             Window.Instance.GetDefaultLayer().Add(text5);
76
77             // Create Source View
78             sourceView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "dragsource.png");
79             sourceView.Size = new Size(200, 200);
80             sourceView.Position = new Position(330, 120);
81             Window.Instance.GetDefaultLayer().Add(sourceView);
82
83             longPressed = new LongPressGestureDetector();
84             longPressed.Attach(sourceView);
85             longPressed.Detected += (s, e) =>
86             {
87               if(e.LongPressGesture.State == Gesture.StateType.Started)
88               {
89                 Tizen.Log.Debug("NUIDnDMultiWindow", "StartDragAndDrop");
90                 shadowView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png");
91                 shadowView.Size = new Size(150, 150);
92                 DragData dragData;
93                 dragData.MimeType = "text/uri-list";
94                 dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png";
95                 dnd.StartDragAndDrop(sourceView, shadowView, dragData, OnSourceApp_SourceFunc);
96               }
97             };
98
99             // Create Target MainWindow_View
100             MainWindow_View = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
101             MainWindow_View.Size = new Size(200, 200);
102             MainWindow_View.Position = new Position(100, 500);
103             Window.Instance.GetDefaultLayer().Add(MainWindow_View);
104
105             // Add Drop Target MainWindow_View
106             dnd.AddListener(MainWindow_View, OnSourceApp_TargetFunc);
107
108             // Create Target Window A
109             WindowA = new Window("WindowA", new Rectangle(400, 400, 370, 250), false)
110             {
111                 BackgroundColor = Color.BlueViolet,
112             };
113             WindowA.Show();
114             
115             // Create Target WindowA_ViewA
116             WindowA_ViewA = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
117             WindowA_ViewA.Size = new Size(150, 150);
118             WindowA_ViewA.Position = new Position(20, 10);
119             WindowA.GetDefaultLayer().Add(WindowA_ViewA);
120
121             // Add Drop Target WindowA_ViewA
122             dnd.AddListener(WindowA_ViewA, OnSourceApp_TargetFunc);
123
124             // Create Target View WindowA_ViewB
125             WindowA_ViewB = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
126             WindowA_ViewB.Size = new Size(150, 150);
127             WindowA_ViewB.Position = new Position(180, 50);
128             WindowA.GetDefaultLayer().Add(WindowA_ViewB);
129
130             // Add Drop Target WindowA_ViewB
131             dnd.AddListener(WindowA_ViewB, OnSourceApp_TargetFunc);
132
133             // Create Target Window B
134             WindowB = new Window("WindowB", new Rectangle(400, 750, 370, 250), false)
135             {
136                 BackgroundColor = Color.LightGoldenRodYellow,
137             };
138             WindowB.Show();
139             
140             // Create Target WindowB_ViewA
141             WindowB_ViewA = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
142             WindowB_ViewA.Size = new Size(150, 150);
143             WindowB_ViewA.Position = new Position(20, 10);
144             WindowB.GetDefaultLayer().Add(WindowB_ViewA);
145
146             // Add Drop Target WindowB_ViewA
147             dnd.AddListener(WindowB_ViewA, OnSourceApp_TargetFunc);
148
149             // Create Target WindowB_ViewB
150             WindowB_ViewB = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "droptarget.png");
151             WindowB_ViewB.Size = new Size(150, 150);
152             WindowB_ViewB.Position = new Position(180, 50);
153             WindowB.GetDefaultLayer().Add(WindowB_ViewB);
154
155             // Add Drop Target WindowB_ViewB
156             dnd.AddListener(WindowB_ViewB, OnSourceApp_TargetFunc);
157         }
158
159         public void OnSourceApp_SourceFunc(DragSourceEventType type)
160         {
161           if (type == DragSourceEventType.Start)
162           {
163             Tizen.Log.Debug("NUIDnDMultiWindow", "Source App DragSourceEventType: " + "Start");
164           }
165           else if (type == DragSourceEventType.Cancel)
166           {
167             Tizen.Log.Debug("NUIDnDMultiWindow", "Source App DragSourceEventType: " + "Cancel");
168           }
169           else if (type == DragSourceEventType.Accept)
170           {
171             Tizen.Log.Debug("NUIDnDMultiWindow", "Source App DragSourceEventType: " + "Accept");
172           }
173           else if (type == DragSourceEventType.Finish)
174           {
175             Tizen.Log.Debug("NUIDnDMultiWindow", "Source App DragSourceEventType: " + "Finish");
176           }
177         }
178
179         public void OnSourceApp_TargetFunc(View targetView, DragEvent dragEvent)
180         {
181             if (dragEvent.DragType == DragType.Enter)
182             {
183               Tizen.Log.Debug("NUIDnDMultiWindow", "Source App Target A [Enter]");
184             }
185             else if (dragEvent.DragType == DragType.Leave)
186             {
187               Tizen.Log.Debug("NUIDnDMultiWindow", "Source App Target A [Leave]");
188             }
189             else if (dragEvent.DragType == DragType.Move)
190             {
191               Tizen.Log.Debug("NUIDnDMultiWindow", "Source App Target A [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
192             }
193             else if (dragEvent.DragType == DragType.Drop)
194             {
195               Tizen.Log.Debug("NUIDnDMultiWindow", "Source App Target A [Drop] MimeType: " + dragEvent.MimeType + " Data: " + dragEvent.Data);
196               ((ImageView)targetView).ResourceUrl = dragEvent.Data;
197             }
198         }
199
200         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
201         {
202             if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
203             {
204                 Exit();
205             }
206         }
207         
208         static void Main(string[] args)
209         {
210             var app = new Program();
211             app.Run(args);
212         }
213     }
214 }