[Tizen] Update NUISamples to support .netcore 2.0
[platform/core/csapi/nui.git] / NUISamples / examples / date-picker-using-json / date-picker-using-json.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
23 namespace DatePickerUsingJson
24 {
25     // A spin control (for continously changing values when users can easily predict a set of values)
26
27     class Example : NUIApplication
28     {
29         private Spin _spinYear;  // spin control for year
30         private Spin _spinMonth; // spin control for month
31         private Spin _spinDay;   // spin control for day
32         //private Builder _builder; // DALi Builder
33
34         //private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
35         private const string _resPath = "./res";  //for ubuntu
36
37         public Example() : base()
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             //This is required for the Application which uses JSON theme and style of Dali builder
53             ViewRegistryHelper.Initialize();
54             /*
55             // load date JSON template...
56             _builder = new Builder ();
57
58             // Optional constant to see logging information coming out
59             // of DALi JSON parser (builder)
60             PropertyMap constants = new  PropertyMap();
61             constants.Insert( "CONFIG_SCRIPT_LOG_LEVEL",  new PropertyValue( "Verbose") );
62             _builder.AddConstants( constants );
63
64             _builder.LoadFromFile(_resPath + "/json/date-picker-template.json" );
65
66             // create the date-picker from the template in the json file
67             View actorTree =  _builder.Create( "date-picker");
68
69             window.Add( actorTree );
70
71             View year  = actorTree.FindChildByName("Year");
72             View month  =  actorTree.FindChildByName("Month" );
73             View day  = actorTree.FindChildByName("Day");
74
75             // need to get the actual C# Spin object associated with the actor,
76             _spinYear = year as Spin;
77             _spinMonth = month as Spin;
78             _spinDay = day as Spin;
79
80             _spinYear.Value = 2099;
81             _spinMonth.Value = 5;
82             _spinDay.Value = 23;
83
84             _spinYear.Focusable = (true);
85             _spinMonth.Focusable = (true);
86             _spinDay.Focusable = (true);
87
88             FocusManager keyboardFocusManager = FocusManager.Instance;
89             keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
90             //keyboardFocusManager.FocusedViewActivated += OnFocusedViewActivated;
91
92             StyleManager.Get().ApplyTheme(_resPath + "/json/date-picker-theme.json");
93             */
94         }
95
96         private View OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
97         {
98             View nextFocusView = e.ProposedView;
99
100             // When nothing has been focused initially, focus the text field in the first spin
101             if (!e.CurrentView && !e.ProposedView)
102             {
103                 nextFocusView = _spinYear.SpinText;
104             }
105             else if(e.Direction == View.FocusDirection.Left)
106             {
107                 // Move the focus to the spin in the left of the current focused spin
108                 if(e.CurrentView == _spinMonth.SpinText)
109                 {
110                     nextFocusView = _spinYear.SpinText;
111                 }
112                 else if(e.CurrentView == _spinDay.SpinText)
113                 {
114                     nextFocusView = _spinMonth.SpinText;
115                 }
116             }
117             else if(e.Direction == View.FocusDirection.Right)
118             {
119                 // Move the focus to the spin in the right of the current focused spin
120                 if(e.CurrentView == _spinYear.SpinText)
121                 {
122                     nextFocusView = _spinMonth.SpinText;
123                 }
124                 else if(e.CurrentView == _spinMonth.SpinText)
125                 {
126                     nextFocusView = _spinDay.SpinText;
127                 }
128             }
129
130             return nextFocusView;
131         }
132         /*
133         private void OnFocusedViewActivated(object source, FocusManager.FocusedViewActivatedEventArgs e)
134         {
135             // Make the text field in the current focused spin to take the key input
136             KeyInputFocusManager manager = KeyInputFocusManager.Get();
137
138             if (e.View == _spinYear.SpinText)
139             {
140                 if (manager.GetCurrentFocusControl() != _spinYear.SpinText)
141                 {
142                     manager.SetFocus(_spinYear.SpinText);
143                 }
144             }
145             else if (e.View == _spinMonth.SpinText)
146             {
147                 if (manager.GetCurrentFocusControl() != _spinMonth.SpinText)
148                 {
149                     manager.SetFocus(_spinMonth.SpinText);
150                 }
151             }
152             else if (e.View == _spinDay.SpinText)
153             {
154                 if (manager.GetCurrentFocusControl() != _spinDay.SpinText)
155                 {
156                     manager.SetFocus(_spinDay.SpinText);
157                 }
158             }
159         }
160         */
161
162         /// <summary>
163         /// The main entry point for the application.
164         /// </summary>
165         [STAThread]
166         static void _Main(string[] args)
167         {
168             Example example = new Example();
169             example.Run(args);
170         }
171     }
172 }