[Tizen] temporal API to make users use Container class
[platform/core/csapi/nui.git] / NUISamples / examples / date-picker.cs
1 /*
2  * Copyright (c) 2017 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         public Example() : base()
37         {
38
39         }
40
41         protected override void OnCreate()
42         {
43             base.OnCreate();
44             Initialize();
45         }
46
47         public void Initialize()
48         {
49             Window window = Window.Instance;
50             window.BackgroundColor = Color.White;
51
52             // Create a container for the spins
53             _container = new FlexContainer();
54
55             _container.FlexDirection = FlexContainer.FlexDirectionType.Row;
56             _container.Size2D = new Size2D(480, 150);
57
58             window.Add(_container);
59
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);
65
66             _spinYear.MinValue = 1900;
67             _spinYear.MaxValue = 2100;
68             _spinYear.Value = 2016;
69             _spinYear.Step = 1;
70             _spinYear.MaxTextLength = 4;
71             _spinYear.TextPointSize = 15;
72             _spinYear.TextColor = Color.Red;
73             _spinYear.Focusable = (true);
74             _spinYear.Name = "_spinYear";
75
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);
81
82             _spinMonth.MinValue = 1;
83             _spinMonth.MaxValue = 12;
84             _spinMonth.Value = 10;
85             _spinMonth.Step = 1;
86             _spinMonth.MaxTextLength = 2;
87             _spinMonth.TextPointSize = 15;
88             _spinMonth.TextColor = Color.Green;
89             _spinMonth.Focusable = (true);
90             _spinMonth.Name = "_spinMonth";
91
92             // Create a Spin control for day
93             _spinDay = new Spin();
94             _spinDay.Flex = 0.3f;
95             _spinDay.FlexMargin = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
96             _container.Add(_spinDay);
97
98             _spinDay.MinValue = 1;
99             _spinDay.MaxValue = 31;
100             _spinDay.Value = 26;
101             _spinDay.Step = 1;
102             _spinDay.MaxTextLength = 2;
103             _spinDay.TextPointSize = 15;
104             _spinDay.TextColor = Color.Blue;
105             _spinDay.Focusable = (true);
106             _spinDay.Name = "_spinDay";
107
108             FocusManager keyboardFocusManager = FocusManager.Instance;
109             keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
110             keyboardFocusManager.FocusedViewActivated += OnFocusedViewActivated;
111         }
112
113         private View OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
114         {
115             View nextFocusView = e.ProposedView;
116
117             // When nothing has been focused initially, focus the text field in the first spin
118             if (!e.CurrentView && !e.ProposedView)
119             {
120                 nextFocusView = _spinYear.SpinText;
121             }
122             else if(e.Direction == View.FocusDirection.Left)
123             {
124                 // Move the focus to the spin in the left of the current focused spin
125                 if(e.CurrentView == _spinMonth.SpinText)
126                 {
127                     nextFocusView = _spinYear.SpinText;
128                 }
129                 else if(e.CurrentView == _spinDay.SpinText)
130                 {
131                     nextFocusView = _spinMonth.SpinText;
132                 }
133             }
134             else if(e.Direction == View.FocusDirection.Right)
135             {
136                 // Move the focus to the spin in the right of the current focused spin
137                 if(e.CurrentView == _spinYear.SpinText)
138                 {
139                     nextFocusView = _spinMonth.SpinText;
140                 }
141                 else if(e.CurrentView == _spinMonth.SpinText)
142                 {
143                     nextFocusView = _spinDay.SpinText;
144                 }
145             }
146
147             return nextFocusView;
148         }
149
150         private void OnFocusedViewActivated(object source, FocusManager.FocusedViewActivatedEventArgs e)
151         {
152
153         }
154
155         /// <summary>
156         /// The main entry point for the application.
157         /// </summary>
158         [STAThread]
159         static void _Main(string[] args)
160         {
161             Example example = new Example();
162             example.Run(args);
163         }
164     }
165 }