3 using Tizen.NUI.Components;
4 using Tizen.NUI.BaseComponents;
8 class Program : NUIApplication
12 ImageView targetViewA;
13 ImageView targetViewB;
16 LongPressGestureDetector longPressed;
17 protected override void OnCreate()
25 // Create DnD Instance
26 dnd = DragAndDrop.Instance;
28 Window.Instance.KeyEvent += OnKeyEvent;
29 Window.Instance.WindowSize = new Size(900, 1080);
30 Window.Instance.BackgroundColor = Color.White;
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);
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);
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);
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);
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);
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);
73 dnd.AddListener(targetViewA, OnSourceAppDnDFuncA);
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);
82 dnd.AddListener(targetViewB, OnSourceAppDnDFuncB);
84 longPressed = new LongPressGestureDetector();
85 longPressed.Attach(sourceView);
86 longPressed.Detected += (s, e) =>
88 if(e.LongPressGesture.State == Gesture.StateType.Started)
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);
94 dragData.MimeType = "text/uri-list";
95 dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png";
96 dnd.StartDragAndDrop(sourceView, shadowView, dragData, OnSourceEventFunc);
101 public void OnSourceAppDnDFuncA(View targetView, DragEvent dragEvent)
103 if (dragEvent.DragType == DragType.Enter)
105 Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Enter]");
107 else if (dragEvent.DragType == DragType.Leave)
109 Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Leave]");
111 else if (dragEvent.DragType == DragType.Move)
113 Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
115 else if (dragEvent.DragType == DragType.Drop)
117 Tizen.Log.Debug("NUIDnDSource", "Source App Target A [Drop] MimeType: " + dragEvent.MimeType + " Data: " + dragEvent.Data);
118 targetViewA.ResourceUrl = dragEvent.Data;
122 public void OnSourceAppDnDFuncB(View targetView, DragEvent dragEvent)
124 if (dragEvent.DragType == DragType.Enter)
126 Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Enter]");
128 else if (dragEvent.DragType == DragType.Leave)
130 Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Leave]");
132 else if (dragEvent.DragType == DragType.Move)
134 Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Move]: " + dragEvent.Position.X + " " + dragEvent.Position.Y);
136 else if (dragEvent.DragType == DragType.Drop)
138 Tizen.Log.Debug("NUIDnDSource", "Source App Target B [Drop] MimeType: " + dragEvent.MimeType + " Data: " + dragEvent.Data);
139 targetViewB.ResourceUrl = dragEvent.Data;
143 public void OnKeyEvent(object sender, Window.KeyEventArgs e)
145 if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
151 public void OnSourceEventFunc(DragSourceEventType type)
153 if (type == DragSourceEventType.Start)
155 Tizen.Log.Debug("NUIDnDSource", "Source App DragSourceEventType: " + "Start");
157 else if (type == DragSourceEventType.Cancel)
159 Tizen.Log.Debug("NUIDnDSource", "Source App DragSourceEventType: " + "Cancel");
161 else if (type == DragSourceEventType.Accept)
163 Tizen.Log.Debug("NUIDnDSource", "Source App DragSourceEventType: " + "Accept");
165 else if (type == DragSourceEventType.Finish)
167 Tizen.Log.Debug("NUIDnDSource", "Source App DragSourceEventType: " + "Finish");
171 static void Main(string[] args)
173 var app = new Program();