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;
24 namespace DatePickerTest
26 // A spin control (for continously changing values when users can easily predict a set of values)
28 class Example : NUIApplication
30 private FlexContainer _container; // Flex container to hold spin controls
31 private Spin _spinYear; // spin control for year
32 private Spin _spinMonth; // spin control for month
33 private Spin _spinDay; // spin control for day
35 public Example() : base()
40 protected override void OnCreate()
46 public void Initialize()
48 Stage stage = Stage.Instance;
49 stage.BackgroundColor = Color.White;
51 // Create a container for the spins
52 _container = new FlexContainer();
54 //_container.ParentOrigin = ParentOrigin.Center;
55 _container.AnchorPoint = AnchorPoint.Center;
56 _container.FlexDirection = FlexContainer.FlexDirectionType.Row;
57 _container.Size = new Vector3(480.0f, 150.0f, 0.0f);
58 _container.Position2D = new Position2D(400, 400);
60 stage.GetDefaultLayer().Add(_container);
62 // Create a Spin control for year
63 _spinYear = new Spin();
64 _spinYear.AnchorPoint = AnchorPoint.Center;
65 _spinYear.Flex = 0.3f;
66 _spinYear.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
67 _container.Add(_spinYear);
69 _spinYear.MinValue = 1900;
70 _spinYear.MaxValue = 2100;
71 _spinYear.Value = 2016;
73 _spinYear.MaxTextLength = 4;
74 _spinYear.TextPointSize = 15;
75 _spinYear.TextColor = Color.Red;
76 _spinYear.Focusable = (true);
77 _spinYear.Name = "_spinYear";
79 // Create a Spin control for month
80 _spinMonth = new Spin();
81 _spinMonth.AnchorPoint = AnchorPoint.Center;
82 _spinMonth.Flex = 0.3f;
83 _spinMonth.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
84 _container.Add(_spinMonth);
86 _spinMonth.MinValue = 1;
87 _spinMonth.MaxValue = 12;
88 _spinMonth.Value = 10;
90 _spinMonth.MaxTextLength = 2;
91 _spinMonth.TextPointSize = 15;
92 _spinMonth.TextColor = Color.Green;
93 _spinMonth.Focusable = (true);
94 _spinMonth.Name = "_spinMonth";
96 // Create a Spin control for day
97 _spinDay = new Spin();
98 _spinDay.AnchorPoint = AnchorPoint.Center;
100 _spinDay.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
101 _container.Add(_spinDay);
103 _spinDay.MinValue = 1;
104 _spinDay.MaxValue = 31;
107 _spinDay.MaxTextLength = 2;
108 _spinDay.TextPointSize = 15;
109 _spinDay.TextColor = Color.Blue;
110 _spinDay.Focusable = (true);
111 _spinDay.Name = "_spinDay";
113 FocusManager keyboardFocusManager = FocusManager.Instance;
114 keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
115 keyboardFocusManager.FocusedViewEnterKeyPressed += OnFocusedActorEnterKeyPressed;
119 private View OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
121 View nextFocusView = e.ProposedView;
123 // When nothing has been focused initially, focus the text field in the first spin
124 if (!e.CurrentView && !e.ProposedView)
126 nextFocusView = _spinYear.SpinText;
128 else if(e.Direction == View.FocusDirection.Left)
130 // Move the focus to the spin in the left of the current focused spin
131 if(e.CurrentView == _spinMonth.SpinText)
133 nextFocusView = _spinYear.SpinText;
135 else if(e.CurrentView == _spinDay.SpinText)
137 nextFocusView = _spinMonth.SpinText;
140 else if(e.Direction == View.FocusDirection.Right)
142 // Move the focus to the spin in the right of the current focused spin
143 if(e.CurrentView == _spinYear.SpinText)
145 nextFocusView = _spinMonth.SpinText;
147 else if(e.CurrentView == _spinMonth.SpinText)
149 nextFocusView = _spinDay.SpinText;
153 return nextFocusView;
156 private void OnFocusedActorEnterKeyPressed(object source, FocusManager.FocusedViewEnterKeyEventArgs e)
158 // Make the text field in the current focused spin to take the key input
159 KeyInputFocusManager manager = KeyInputFocusManager.Get();
161 if (e.View == _spinYear.SpinText)
163 if (manager.GetCurrentFocusControl() != _spinYear.SpinText)
165 manager.SetFocus(_spinYear.SpinText);
168 else if (e.View == _spinMonth.SpinText)
170 if (manager.GetCurrentFocusControl() != _spinMonth.SpinText)
172 manager.SetFocus(_spinMonth.SpinText);
175 else if (e.View == _spinDay.SpinText)
177 if (manager.GetCurrentFocusControl() != _spinDay.SpinText)
179 manager.SetFocus(_spinDay.SpinText);
185 /// The main entry point for the application.
188 static void _Main(string[] args)
190 Example example = new Example();