ImfManager manual binding
[platform/core/csapi/nui.git] / NUISamples / NUISamples / NUISamples.TizenTV / examples / date-picker.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.UIComponents;
23
24
25 namespace DatePickerTest
26 {
27     // A spin control (for continously changing values when users can easily predict a set of values)
28
29     class Example : NUIApplication
30     {
31         private FlexContainer _container;   // Flex container to hold spin controls
32         private Spin _spinYear;  // spin control for year
33         private Spin _spinMonth; // spin control for month
34         private Spin _spinDay;   // spin control for day
35
36         private ImfManager _imfMgr;
37         private TextField _textField;
38         private PushButton _pushButton;
39         public bool _toggle;
40
41         public Example() : base()
42         {
43
44         }
45
46         protected override void OnCreate()
47         {
48             base.OnCreate();
49             Initialize();
50         }
51
52         public void Initialize()
53         {
54             Stage stage = Stage.Instance;
55             stage.BackgroundColor = Color.White;
56
57             // Create a container for the spins
58             _container = new FlexContainer();
59
60             //_container.ParentOrigin = ParentOrigin.Center;
61             _container.AnchorPoint = AnchorPoint.Center;
62             _container.FlexDirection = FlexContainer.FlexDirectionType.Row;
63             _container.Size = new Vector3(480.0f, 150.0f, 0.0f);
64             _container.Position2D = new Position2D(400, 400);
65
66             stage.GetDefaultLayer().Add(_container);
67
68             // Create a Spin control for year
69             _spinYear = new Spin();
70             _spinYear.AnchorPoint = AnchorPoint.Center;
71             _spinYear.Flex = 0.3f;
72             _spinYear.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
73             _container.Add(_spinYear);
74
75             _spinYear.MinValue = 1900;
76             _spinYear.MaxValue = 2100;
77             _spinYear.Value = 2016;
78             _spinYear.Step = 1;
79             _spinYear.MaxTextLength = 4;
80             _spinYear.TextPointSize = 15;
81             _spinYear.TextColor = Color.Red;
82             _spinYear.Focusable = (true);
83             _spinYear.Name = "_spinYear";
84
85             // Create a Spin control for month
86             _spinMonth = new Spin();
87             _spinMonth.AnchorPoint = AnchorPoint.Center;
88             _spinMonth.Flex = 0.3f;
89             _spinMonth.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
90             _container.Add(_spinMonth);
91
92             _spinMonth.MinValue = 1;
93             _spinMonth.MaxValue = 12;
94             _spinMonth.Value = 10;
95             _spinMonth.Step = 1;
96             _spinMonth.MaxTextLength = 2;
97             _spinMonth.TextPointSize = 15;
98             _spinMonth.TextColor = Color.Green;
99             _spinMonth.Focusable = (true);
100             _spinMonth.Name = "_spinMonth";
101
102             // Create a Spin control for day
103             _spinDay = new Spin();
104             _spinDay.AnchorPoint = AnchorPoint.Center;
105             _spinDay.Flex = 0.3f;
106             _spinDay.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
107             _container.Add(_spinDay);
108
109             _spinDay.MinValue = 1;
110             _spinDay.MaxValue = 31;
111             _spinDay.Value = 26;
112             _spinDay.Step = 1;
113             _spinDay.MaxTextLength = 2;
114             _spinDay.TextPointSize = 15;
115             _spinDay.TextColor = Color.Blue;
116             _spinDay.Focusable = (true);
117             _spinDay.Name = "_spinDay";
118
119             FocusManager keyboardFocusManager = FocusManager.Instance;
120             keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
121             keyboardFocusManager.FocusedViewEnterKeyPressed += OnFocusedActorEnterKeyPressed;
122
123             ////////////////////////////////////////////////////////////////////////
124             _imfMgr = ImfManager.Get();
125             _imfMgr.ImfManagerActivated += _imfMgr_ImfManagerActivated;
126
127             _textField = new TextField();
128             _textField.Position2D = new Position2D(100, 100);
129             _textField.Size2D = new Size2D(900, 100);
130             _textField.Text = "imf manager test!";
131             _textField.BackgroundColor = Color.Blue;
132             _textField.TextColor = Color.White;
133             stage.GetDefaultLayer().Add(_textField);
134
135             keyboardFocusManager.SetCurrentFocusView(_textField);
136
137             _pushButton = new PushButton();
138             _pushButton.Position2D = new Position2D(100, 210);
139             _pushButton.Size2D = new Size2D(900, 100);
140             _pushButton.LabelText = "imf activate";
141             _pushButton.Clicked += _pushButton_Clicked;
142             stage.GetDefaultLayer().Add(_pushButton);
143         }
144
145         private bool _pushButton_Clicked(object source, EventArgs e)
146         {
147             Tizen.Log.Fatal("NUI", "_pushButton_Clicked event comes!");
148
149             if (_toggle)
150             {
151                 _imfMgr.Activate();
152                 _pushButton.LabelText = "imf activated";
153                 _toggle = false;
154             }
155             else
156             {
157                 _imfMgr.Deactivate();
158                 _pushButton.LabelText = "imf deactivated";
159                 _toggle = true;
160             }
161             return true;
162         }
163
164         private void _imfMgr_ImfManagerActivated(object sender, ImfManager.ImfManagerActivatedEventArgs e)
165         {
166             Tizen.Log.Fatal("NUI", "_imfMgr_ImfManagerActivated event comes!");
167         }
168
169         private View OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
170         {
171             View nextFocusView = e.ProposedView;
172
173             // When nothing has been focused initially, focus the text field in the first spin
174             if (!e.CurrentView && !e.ProposedView)
175             {
176                 nextFocusView = _spinYear.SpinText;
177             }
178             else if(e.Direction == View.FocusDirection.Left)
179             {
180                 // Move the focus to the spin in the left of the current focused spin
181                 if(e.CurrentView == _spinMonth.SpinText)
182                 {
183                     nextFocusView = _spinYear.SpinText;
184                 }
185                 else if(e.CurrentView == _spinDay.SpinText)
186                 {
187                     nextFocusView = _spinMonth.SpinText;
188                 }
189             }
190             else if(e.Direction == View.FocusDirection.Right)
191             {
192                 // Move the focus to the spin in the right of the current focused spin
193                 if(e.CurrentView == _spinYear.SpinText)
194                 {
195                     nextFocusView = _spinMonth.SpinText;
196                 }
197                 else if(e.CurrentView == _spinMonth.SpinText)
198                 {
199                     nextFocusView = _spinDay.SpinText;
200                 }
201             }
202
203             return nextFocusView;
204         }
205
206         private void OnFocusedActorEnterKeyPressed(object source, FocusManager.FocusedViewEnterKeyEventArgs e)
207         {
208             // Make the text field in the current focused spin to take the key input
209             KeyInputFocusManager manager = KeyInputFocusManager.Get();
210
211             if (e.View == _spinYear.SpinText)
212             {
213                 if (manager.GetCurrentFocusControl() != _spinYear.SpinText)
214                 {
215                     manager.SetFocus(_spinYear.SpinText);
216                 }
217             }
218             else if (e.View == _spinMonth.SpinText)
219             {
220                 if (manager.GetCurrentFocusControl() != _spinMonth.SpinText)
221                 {
222                     manager.SetFocus(_spinMonth.SpinText);
223                 }
224             }
225             else if (e.View == _spinDay.SpinText)
226             {
227                 if (manager.GetCurrentFocusControl() != _spinDay.SpinText)
228                 {
229                     manager.SetFocus(_spinDay.SpinText);
230                 }
231             }
232         }
233
234         /// <summary>
235         /// The main entry point for the application.
236         /// </summary>
237         [STAThread]
238         static void _Main(string[] args)
239         {
240             Example example = new Example();
241             example.Run(args);
242         }
243     }
244 }