2 * Copyright (c) 2017 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 public Example() : base()
41 protected override void OnCreate()
47 public void Initialize()
49 Window window = Window.Instance;
50 window.BackgroundColor = Color.White;
52 // Create a container for the spins
53 _container = new FlexContainer();
55 _container.FlexDirection = FlexContainer.FlexDirectionType.Row;
56 _container.Size2D = new Size2D(480, 150);
58 window.Add(_container);
60 // Create a Spin control for year
61 _spinYear = new Spin();
62 _spinYear.Flex = 0.3f;
63 _spinYear.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
64 _container.Add(_spinYear);
66 _spinYear.MinValue = 1900;
67 _spinYear.MaxValue = 2100;
68 _spinYear.Value = 2016;
70 _spinYear.MaxTextLength = 4;
71 _spinYear.TextPointSize = 15;
72 _spinYear.TextColor = Color.Red;
73 _spinYear.Focusable = (true);
74 _spinYear.Name = "_spinYear";
76 // Create a Spin control for month
77 _spinMonth = new Spin();
78 _spinMonth.Flex = 0.3f;
79 _spinMonth.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
80 _container.Add(_spinMonth);
82 _spinMonth.MinValue = 1;
83 _spinMonth.MaxValue = 12;
84 _spinMonth.Value = 10;
86 _spinMonth.MaxTextLength = 2;
87 _spinMonth.TextPointSize = 15;
88 _spinMonth.TextColor = Color.Green;
89 _spinMonth.Focusable = (true);
90 _spinMonth.Name = "_spinMonth";
92 // Create a Spin control for day
93 _spinDay = new Spin();
95 _spinDay.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
96 _container.Add(_spinDay);
98 _spinDay.MinValue = 1;
99 _spinDay.MaxValue = 31;
102 _spinDay.MaxTextLength = 2;
103 _spinDay.TextPointSize = 15;
104 _spinDay.TextColor = Color.Blue;
105 _spinDay.Focusable = (true);
106 _spinDay.Name = "_spinDay";
108 FocusManager keyboardFocusManager = FocusManager.Instance;
109 keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
110 keyboardFocusManager.FocusedViewActivated += OnFocusedViewActivated;
113 private View OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
115 View nextFocusView = e.ProposedView;
117 // When nothing has been focused initially, focus the text field in the first spin
118 if (!e.CurrentView && !e.ProposedView)
120 nextFocusView = _spinYear.SpinText;
122 else if(e.Direction == View.FocusDirection.Left)
124 // Move the focus to the spin in the left of the current focused spin
125 if(e.CurrentView == _spinMonth.SpinText)
127 nextFocusView = _spinYear.SpinText;
129 else if(e.CurrentView == _spinDay.SpinText)
131 nextFocusView = _spinMonth.SpinText;
134 else if(e.Direction == View.FocusDirection.Right)
136 // Move the focus to the spin in the right of the current focused spin
137 if(e.CurrentView == _spinYear.SpinText)
139 nextFocusView = _spinMonth.SpinText;
141 else if(e.CurrentView == _spinMonth.SpinText)
143 nextFocusView = _spinDay.SpinText;
147 return nextFocusView;
150 private void OnFocusedViewActivated(object source, FocusManager.FocusedViewActivatedEventArgs e)
156 /// The main entry point for the application.
159 static void _Main(string[] args)
161 Example example = new Example();