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;
23 namespace DatePickerUsingJson
25 // A spin control (for continously changing values when users can easily predict a set of values)
27 class Example : NUIApplication
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
34 //private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
35 private const string _resPath = "./res"; //for ubuntu
37 public Example() : base()
41 protected override void OnCreate()
47 public void Initialize()
49 Window window = Window.Instance;
50 window.BackgroundColor = Color.White;
52 //This is required for the Application which uses JSON theme and style of Dali builder
53 ViewRegistryHelper.Initialize();
55 // load date JSON template...
56 _builder = new Builder ();
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 );
64 _builder.LoadFromFile(_resPath + "/json/date-picker-template.json" );
66 // create the date-picker from the template in the json file
67 View actorTree = _builder.Create( "date-picker");
69 window.Add( actorTree );
71 View year = actorTree.FindChildByName("Year");
72 View month = actorTree.FindChildByName("Month" );
73 View day = actorTree.FindChildByName("Day");
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;
80 _spinYear.Value = 2099;
84 _spinYear.Focusable = (true);
85 _spinMonth.Focusable = (true);
86 _spinDay.Focusable = (true);
88 FocusManager keyboardFocusManager = FocusManager.Instance;
89 keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
90 //keyboardFocusManager.FocusedViewActivated += OnFocusedViewActivated;
92 StyleManager.Get().ApplyTheme(_resPath + "/json/date-picker-theme.json");
96 private View OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
98 View nextFocusView = e.ProposedView;
100 // When nothing has been focused initially, focus the text field in the first spin
101 if (!e.CurrentView && !e.ProposedView)
103 nextFocusView = _spinYear.SpinText;
105 else if(e.Direction == View.FocusDirection.Left)
107 // Move the focus to the spin in the left of the current focused spin
108 if(e.CurrentView == _spinMonth.SpinText)
110 nextFocusView = _spinYear.SpinText;
112 else if(e.CurrentView == _spinDay.SpinText)
114 nextFocusView = _spinMonth.SpinText;
117 else if(e.Direction == View.FocusDirection.Right)
119 // Move the focus to the spin in the right of the current focused spin
120 if(e.CurrentView == _spinYear.SpinText)
122 nextFocusView = _spinMonth.SpinText;
124 else if(e.CurrentView == _spinMonth.SpinText)
126 nextFocusView = _spinDay.SpinText;
130 return nextFocusView;
133 private void OnFocusedViewActivated(object source, FocusManager.FocusedViewActivatedEventArgs e)
135 // Make the text field in the current focused spin to take the key input
136 KeyInputFocusManager manager = KeyInputFocusManager.Get();
138 if (e.View == _spinYear.SpinText)
140 if (manager.GetCurrentFocusControl() != _spinYear.SpinText)
142 manager.SetFocus(_spinYear.SpinText);
145 else if (e.View == _spinMonth.SpinText)
147 if (manager.GetCurrentFocusControl() != _spinMonth.SpinText)
149 manager.SetFocus(_spinMonth.SpinText);
152 else if (e.View == _spinDay.SpinText)
154 if (manager.GetCurrentFocusControl() != _spinDay.SpinText)
156 manager.SetFocus(_spinDay.SpinText);
163 /// The main entry point for the application.
166 static void _Main(string[] args)
168 Example example = new Example();