3 using Tizen.NUI.Components;
4 using Tizen.NUI.BaseComponents;
8 class Program : NUIApplication
10 const string TAG = "clipboard";
11 const string MIME_TYPE_PLAIN_TEXT = "text/plain;charset=utf-8";
12 const string MIME_TYPE_TEXT_URI = "text/uri-list";
13 const string MIME_TYPE_HTML = "application/xhtml+xml";
21 protected override void OnCreate()
29 Window.Instance.WindowSize = new Size(900, 1080);
30 Window.Instance.BackgroundColor = Color.White;
32 View mainView = NewView(false);
33 Window.Instance.GetDefaultLayer().Add(mainView);
35 TextLabel title = NewTextLabel("Tizen.NUI.Clipboard Test", LayoutParamPolicies.MatchParent);
36 title.HorizontalAlignment = HorizontalAlignment.Center;
37 title.PointSize = 30.0f;
40 string descriptionText = "[Description]\n" +
41 "* Copy : Copy the text entered in the TextField using the Clipboard's SetData() API.\n" +
42 "* This sample uses the 'text/plain;charset=utf-8' MIME type to send and receive data.\n" +
43 "* Paste : Paste the text using the Clipboard's GetData() API.\n" +
44 "* Clear : Clear Information.";
46 TextLabel description = NewTextLabel(descriptionText, LayoutParamPolicies.MatchParent);
47 description.PointSize = 20.0f;
48 mainView.Add(description);
50 View vertView1 = NewView(true);
51 mainView.Add(vertView1);
53 fieldCopy = NewTextField("Enter text to copy", LayoutParamPolicies.MatchParent);
54 vertView1.Add(fieldCopy);
56 Button buttonCopy = NewButton("Copy");
57 vertView1.Add(buttonCopy);
58 buttonCopy.Clicked += (s, e) =>
60 string data = fieldCopy.Text;
61 Clipboard.Instance.SetData(MIME_TYPE_PLAIN_TEXT, data);
62 Tizen.Log.Info(TAG, $"SetData type:{MIME_TYPE_PLAIN_TEXT}, data:{data}\n");
66 View vertView2 = NewView(true);
67 mainView.Add(vertView2);
69 Button buttonPaste = NewButton("Paste");
70 vertView2.Add(buttonPaste);
71 buttonPaste.Clicked += (s, e) =>
73 Clipboard.Instance.GetData(MIME_TYPE_PLAIN_TEXT, OnClipboardDataReceived);
74 Tizen.Log.Info(TAG, $"GetData request type:{MIME_TYPE_PLAIN_TEXT}\n");
77 Button buttonCopyClear = NewButton("Clear");
78 vertView2.Add(buttonCopyClear);
79 buttonCopyClear.Clicked += (s, e) =>
86 View vertView3 = NewView(true);
87 mainView.Add(vertView3);
89 TextLabel pastedType = NewTextLabel("MIME type", 300);
90 vertView3.Add(pastedType);
92 labelType = NewTextLabel(" ", LayoutParamPolicies.MatchParent);
93 vertView3.Add(labelType);
95 View vertView4 = NewView(true);
96 mainView.Add(vertView4);
98 TextLabel pastedData = NewTextLabel("Data", 300);
99 vertView4.Add(pastedData);
101 labelData = NewTextLabel(" ", LayoutParamPolicies.MatchParent);
102 vertView4.Add(labelData);
105 public void OnClipboardDataReceived(bool success, ClipEvent clipEvent)
109 Tizen.Log.Error(TAG, $"Data receive fail");
113 Tizen.Log.Info(TAG, $"OnClipboardDataReceived type:{clipEvent.MimeType}, data:{clipEvent.Data}\n");
116 labelType.Text = clipEvent.MimeType;
117 labelData.Text = clipEvent.Data;
120 public View NewView(bool horizontal)
122 var view = new View()
124 Layout = new LinearLayout()
126 LinearOrientation = horizontal ? LinearLayout.Orientation.Horizontal : LinearLayout.Orientation.Vertical,
127 LinearAlignment = LinearLayout.Alignment.Begin,
128 CellPadding = new Size2D(10, 20),
130 WidthSpecification = LayoutParamPolicies.MatchParent,
131 HeightSpecification = LayoutParamPolicies.WrapContent,
132 BackgroundColor = Color.White,
137 public TextLabel NewTextLabel(string text, int width)
139 var label = new TextLabel
143 WidthSpecification = width,
144 HeightSpecification = LayoutParamPolicies.WrapContent,
146 BackgroundColor = Color.White,
147 BorderlineWidth = 1.0f,
152 public TextField NewTextField(string placeholderText, int width)
154 var field = new TextField
156 PlaceholderText = placeholderText,
157 PlaceholderTextFocused = placeholderText,
158 WidthSpecification = width,
159 HeightSpecification = LayoutParamPolicies.WrapContent,
161 BackgroundColor = Color.White,
162 BorderlineWidth = 1.0f,
167 public Button NewButton(string text)
169 var button = new Button(NewButtonStyle())
173 WidthSpecification = 200,
174 HeightSpecification = LayoutParamPolicies.WrapContent,
179 public ButtonStyle NewButtonStyle()
181 var style = new ButtonStyle
184 BackgroundColor = new Selector<Color>()
186 Normal = new Color(0.25f, 0.75f, 1.0f, 1.0f),
187 Pressed = new Color(0.25f, 0.75f, 1.0f, 0.3f),
189 Overlay = new ImageViewStyle()
191 BackgroundColor = new Selector<Color>()
193 Pressed = new Color(0, 0, 0, 0.1f),
194 Other = new Color(1, 1, 1, 0.1f),
197 Text = new TextLabelStyle()
199 TextColor = new Color(0.0f, 0.0f, 0.0f, 1.0f),
205 static void Main(string[] args)
207 var app = new Program();