private int shadowWidth = 100;
private int shadowHeight = 100;
+ private bool initDrag = false;
+
private DragAndDrop() : this(Interop.DragAndDrop.New(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
}
+ private void ReleaseDragWindow()
+ {
+ if (mDragWindow)
+ {
+ if (mShadowView)
+ {
+ //Application has Shadow View ownership, so DnD doesn't dispose Shadow View
+ mDragWindow.Remove(mShadowView);
+ mShadowView = null;
+ }
+
+ mDragWindow.Dispose();
+ mDragWindow = null;
+ }
+ }
+
/// <summary>
/// Gets the singleton instance of DragAndDrop.
/// </summary>
/// <param name="callback">The source event callback</param>
/// <since_tizen> 10 </since_tizen>
public void StartDragAndDrop(View sourceView, View shadowView, DragData dragData, SourceEventHandler callback)
- {
+ {
+ if (initDrag)
+ {
+ Tizen.Log.Fatal("NUI", "Start Drag And Drop Initializing...");
+ return;
+ }
+ initDrag = true;
+
if (Window.IsSupportedMultiWindow() == false)
{
throw new NotSupportedException("This device does not support surfaceless_context. So Window cannot be created.");
throw new ArgumentNullException(nameof(shadowView));
}
+ ReleaseDragWindow();
+
shadowWidth = (int)shadowView.Size.Width;
shadowHeight = (int)shadowView.Size.Height;
shadowHeight = 100;
}
- if (null == mDragWindow)
+ mDragWindow = new Window("DragWindow", new Rectangle(-shadowWidth, -shadowHeight, shadowWidth, shadowHeight), true)
{
- mDragWindow = new Window("DragWindow", new Rectangle(-shadowWidth, -shadowHeight, shadowWidth, shadowHeight), true)
- {
- BackgroundColor = Color.Transparent,
- };
- }
-
- //Initialize Drag Window Position and Size based on Shadow View Position and Size
- mDragWindow.SetPosition(new Position2D((int)shadowView.Position.X, (int)shadowView.Position.Y));
- mDragWindow.SetWindowSize(new Size(shadowWidth, shadowHeight));
-
- //Make Shadow View Transparent
- shadowView.SetOpacity(0.9f);
-
- //Make Position 0, 0 for Moving into Drag Window
- shadowView.Position = new Position(0, 0);
+ BackgroundColor = Color.Transparent,
+ };
- if (mShadowView)
+ if (mDragWindow)
{
- mShadowView.Hide();
- mDragWindow.Remove(mShadowView);
- mShadowView.Dispose();
- }
+ //Initialize Drag Window Size based on Shadow View Size,
+ //Don't set Drag Window Posiiton, Window Server sets Position Internally
+ mDragWindow.SetWindowSize(new Size(shadowWidth, shadowHeight));
+
+ //Make Shadow View Transparent
+ shadowView.SetOpacity(0.9f);
+
+ //Make Position 0, 0 for Moving into Drag Window
+ shadowView.Position = new Position(0, 0);
+
+ mShadowView = shadowView;
+ mDragWindow.Add(mShadowView);
+
+ sourceEventCb = (sourceEventType) =>
+ {
+ if ((DragSourceEventType)sourceEventType != DragSourceEventType.Start)
+ {
+ Tizen.Log.Fatal("NUI", "DnD Source Event is Called");
+ ReleaseDragWindow();
+ }
- mShadowView = shadowView;
- mDragWindow.Add(mShadowView);
+ callback((DragSourceEventType)sourceEventType);
+ };
- //Update Window Directly
- mDragWindow.VisibiltyChangedSignalEmit(true);
- mDragWindow.RenderOnce();
+ //Show Drag Window before StartDragAndDrop
+ mDragWindow.Show();
- sourceEventCb = (sourceEventType) =>
- {
- if ((DragSourceEventType)sourceEventType == DragSourceEventType.Finish)
+ if (!Interop.DragAndDrop.StartDragAndDrop(SwigCPtr, View.getCPtr(sourceView), Window.getCPtr(mDragWindow), dragData.MimeType, dragData.Data,
+ new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(sourceEventCb))))
{
- if (mShadowView)
- {
- mShadowView.Hide();
- mDragWindow.Remove(mShadowView);
- mShadowView.Dispose();
- }
-
- //Update Window Directly
- mDragWindow.VisibiltyChangedSignalEmit(true);
- mDragWindow.RenderOnce();
+ throw new InvalidOperationException("Fail to StartDragAndDrop");
}
- callback((DragSourceEventType)sourceEventType);
- };
-
- if (!Interop.DragAndDrop.StartDragAndDrop(SwigCPtr, View.getCPtr(sourceView), Window.getCPtr(mDragWindow), dragData.MimeType, dragData.Data,
- new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(sourceEventCb))))
- {
- throw new InvalidOperationException("Fail to StartDragAndDrop");
- }
-
- mDragWindow.Show();
+ }
+
+ initDrag = false;
}
/// <summary>
ImageView targetViewA;
ImageView targetViewB;
DragAndDrop dnd;
+
+ LongPressGestureDetector longPressed;
protected override void OnCreate()
{
base.OnCreate();
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);
// Add Drop Target B
dnd.AddListener(targetViewB, OnSourceAppDnDFuncB);
+
+ longPressed = new LongPressGestureDetector();
+ longPressed.Attach(sourceView);
+ longPressed.Detected += (s, e) =>
+ {
+ if(e.LongPressGesture.State == Gesture.StateType.Started)
+ {
+ Tizen.Log.Debug("NUIDnDSource", "StartDragAndDrop");
+ shadowView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png");
+ shadowView.Size = new Size(150, 150);
+ DragData dragData;
+ dragData.MimeType = "text/uri-list";
+ dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png";
+ dnd.StartDragAndDrop(sourceView, shadowView, dragData, OnSourceEventFunc);
+ }
+ };
}
public void OnSourceAppDnDFuncA(View targetView, DragEvent dragEvent)
}
}
- 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");
- shadowView.Size = new Size(150, 150);
- DragData dragData;
- dragData.MimeType = "text/uri-list";
- dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png";
- dnd.StartDragAndDrop(sourceView, shadowView, dragData, OnSourceEventFunc);
- }
- }
-
static void Main(string[] args)
{
var app = new Program();