2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.InteropServices;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.UIComponents;
25 namespace DatePickerTest
27 // A spin control (for continously changing values when users can easily predict a set of values)
29 class Example : NUIApplication
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
36 private ImfManager _imfMgr;
37 private TextField _textField;
38 private PushButton _pushButton;
41 public Example() : base()
46 protected override void OnCreate()
52 public void Initialize()
54 Stage stage = Stage.Instance;
55 stage.BackgroundColor = Color.White;
57 // Create a container for the spins
58 _container = new FlexContainer();
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);
66 stage.GetDefaultLayer().Add(_container);
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);
75 _spinYear.MinValue = 1900;
76 _spinYear.MaxValue = 2100;
77 _spinYear.Value = 2016;
79 _spinYear.MaxTextLength = 4;
80 _spinYear.TextPointSize = 15;
81 _spinYear.TextColor = Color.Red;
82 _spinYear.Focusable = (true);
83 _spinYear.Name = "_spinYear";
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);
92 _spinMonth.MinValue = 1;
93 _spinMonth.MaxValue = 12;
94 _spinMonth.Value = 10;
96 _spinMonth.MaxTextLength = 2;
97 _spinMonth.TextPointSize = 15;
98 _spinMonth.TextColor = Color.Green;
99 _spinMonth.Focusable = (true);
100 _spinMonth.Name = "_spinMonth";
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);
109 _spinDay.MinValue = 1;
110 _spinDay.MaxValue = 31;
113 _spinDay.MaxTextLength = 2;
114 _spinDay.TextPointSize = 15;
115 _spinDay.TextColor = Color.Blue;
116 _spinDay.Focusable = (true);
117 _spinDay.Name = "_spinDay";
119 FocusManager keyboardFocusManager = FocusManager.Instance;
120 keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
121 keyboardFocusManager.FocusedViewEnterKeyPressed += OnFocusedActorEnterKeyPressed;
123 ////////////////////////////////////////////////////////////////////////
124 _imfMgr = ImfManager.Get();
125 _imfMgr.ImfManagerActivated += _imfMgr_ImfManagerActivated;
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);
135 keyboardFocusManager.SetCurrentFocusView(_textField);
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);
145 private bool _pushButton_Clicked(object source, EventArgs e)
147 Tizen.Log.Fatal("NUI", "_pushButton_Clicked event comes!");
152 _pushButton.LabelText = "imf activated";
157 _imfMgr.Deactivate();
158 _pushButton.LabelText = "imf deactivated";
164 private void _imfMgr_ImfManagerActivated(object sender, ImfManager.ImfManagerActivatedEventArgs e)
166 Tizen.Log.Fatal("NUI", "_imfMgr_ImfManagerActivated event comes!");
169 private View OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
171 View nextFocusView = e.ProposedView;
173 // When nothing has been focused initially, focus the text field in the first spin
174 if (!e.CurrentView && !e.ProposedView)
176 nextFocusView = _spinYear.SpinText;
178 else if(e.Direction == View.FocusDirection.Left)
180 // Move the focus to the spin in the left of the current focused spin
181 if(e.CurrentView == _spinMonth.SpinText)
183 nextFocusView = _spinYear.SpinText;
185 else if(e.CurrentView == _spinDay.SpinText)
187 nextFocusView = _spinMonth.SpinText;
190 else if(e.Direction == View.FocusDirection.Right)
192 // Move the focus to the spin in the right of the current focused spin
193 if(e.CurrentView == _spinYear.SpinText)
195 nextFocusView = _spinMonth.SpinText;
197 else if(e.CurrentView == _spinMonth.SpinText)
199 nextFocusView = _spinDay.SpinText;
203 return nextFocusView;
206 private void OnFocusedActorEnterKeyPressed(object source, FocusManager.FocusedViewEnterKeyEventArgs e)
208 // Make the text field in the current focused spin to take the key input
209 KeyInputFocusManager manager = KeyInputFocusManager.Get();
211 if (e.View == _spinYear.SpinText)
213 if (manager.GetCurrentFocusControl() != _spinYear.SpinText)
215 manager.SetFocus(_spinYear.SpinText);
218 else if (e.View == _spinMonth.SpinText)
220 if (manager.GetCurrentFocusControl() != _spinMonth.SpinText)
222 manager.SetFocus(_spinMonth.SpinText);
225 else if (e.View == _spinDay.SpinText)
227 if (manager.GetCurrentFocusControl() != _spinDay.SpinText)
229 manager.SetFocus(_spinDay.SpinText);
235 /// The main entry point for the application.
238 static void _Main(string[] args)
240 Example example = new Example();