3 using Tizen.NUI.BaseComponents;
4 using Tizen.NUI.WindowSystem;
8 * After the app is launched, it is hidden and the focus is skipped.
9 * This is a sample app that becomes SecondarySelection and catches the Copy event of another process.
10 * If there is another SecondarySelection already running on the device, this sample will not work properly.
13 namespace NUIClipboardDataSelected
15 class Program : NUIApplication
17 const string TAG = "clipboard";
18 const string MIME_TYPE_PLAIN_TEXT = "text/plain;charset=utf-8";
20 protected override void OnCreate()
28 Window.Instance.WindowSize = new Size(1, 1);
29 Window.Instance.BackgroundColor = Color.White;
31 Tizen.NUI.WindowSystem.Shell.TizenShell tzShell;
32 tzShell = new Tizen.NUI.WindowSystem.Shell.TizenShell();
33 Window.Instance.SetAcceptFocus(false);
35 Tizen.NUI.WindowSystem.Shell.KVMService kvmService;
36 // Window that will act as KVM Service.
37 kvmService = new Tizen.NUI.WindowSystem.Shell.KVMService(tzShell, Window.Instance);
38 kvmService.SetSecondarySelction();
40 // This view has nothing to do with this test, just for easy debugging.
41 // If there is a view, it is exposed to the process monitor.
42 View view = NewView();
43 Window.Instance.GetDefaultLayer().Add(view);
45 // Register event handler.
46 Clipboard.Instance.DataSelected += OnClipboardDataSelected;
52 // When copy occurs somewhere, this callback is invoked.
53 public void OnClipboardDataSelected(object sender, ClipboardDataSelectedEventArgs e)
55 // e.MimeType is the MIME type of the copy data that invoked this callback.
56 string selectedType = e.MimeType;
57 Tizen.Log.Info(TAG, $"OnClipboardDataSelected type:{selectedType}\n");
60 // For example, MC app can call Clipboard's GetData() with the MIME type of the event argument.
61 Clipboard.Instance.GetData(selectedType, OnClipboardDataReceived);
64 // When call Clipboard's GetData(), the user callback is called.
65 public void OnClipboardDataReceived(bool success, ClipEvent clipEvent)
69 Tizen.Log.Error(TAG, $"Data receive fail");
73 Tizen.Log.Info(TAG, $"OnClipboardDataReceived type:{clipEvent.MimeType}, data:{clipEvent.Data}\n");
76 public void CopyTest()
79 // * SetData() is called 5 seconds after app execution.
80 // * Observe the Log of OnClipboardDataSelected.
81 // * If the log is output, there is a problem somewhere.
82 // * DataSelected event should not be invoked
83 // * by the SetData() called within the SecondarySelection.
84 Timer timer = new Timer(5000);
85 timer.Tick += (s, e) =>
87 string data = "Lorem ipsum dolor sit amet consectetuer";
88 Tizen.Log.Info(TAG, $"SetData type:{MIME_TYPE_PLAIN_TEXT}, data:{data}\n");
89 Clipboard.Instance.SetData(MIME_TYPE_PLAIN_TEXT, data);
99 Layout = new LinearLayout()
101 LinearOrientation = LinearLayout.Orientation.Vertical,
102 LinearAlignment = LinearLayout.Alignment.Begin,
104 WidthSpecification = LayoutParamPolicies.MatchParent,
105 HeightSpecification = LayoutParamPolicies.WrapContent,
106 BackgroundColor = Color.White,
111 static void Main(string[] args)
113 var app = new Program();