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 public Example() : base()
38 protected override void OnCreate()
44 public void Initialize()
46 Window window = Window.Instance;
47 window.BackgroundColor = Color.White;
49 //This is required for the Application which uses JSON theme and style of Dali builder
50 ViewRegistryHelper.Initialize();
52 // load date JSON template...
53 _builder = new Builder ();
55 // Optional constant to see logging information coming out
56 // of DALi JSON parser (builder)
57 PropertyMap constants = new PropertyMap();
58 constants.Insert( "CONFIG_SCRIPT_LOG_LEVEL", new PropertyValue( "Verbose") );
59 _builder.AddConstants( constants );
61 _builder.LoadFromFile("/home/owner/apps_rw/NUISamples.TizenTV/res/json/date-picker-template.json" );
63 // create the date-picker from the template in the json file
64 BaseHandle handle = _builder.Create( "date-picker");
66 View actorTree = View.DownCast( handle );
68 window.GetDefaultLayer().Add( actorTree );
70 View year = actorTree.FindChildByName("Year");
71 View month = actorTree.FindChildByName("Month" );
72 View day = actorTree.FindChildByName("Day");
74 // need to get the actual C# Spin object associated with the actor,
75 _spinYear = View.DownCast<Spin>( year );
76 _spinMonth = View.DownCast<Spin>( month );
77 _spinDay = View.DownCast<Spin>( day );
79 _spinYear.Value = 2099;
83 _spinYear.Focusable = (true);
84 _spinMonth.Focusable = (true);
85 _spinDay.Focusable = (true);
87 FocusManager keyboardFocusManager = FocusManager.Instance;
88 keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
89 keyboardFocusManager.FocusedViewEnterKeyPressed += OnFocusedViewEnterKeyPressed;
91 StyleManager.Get().ApplyTheme("/home/owner/apps_rw/NUISamples.TizenTV/res/json/date-picker-theme.json");
94 private View OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
96 View nextFocusView = e.ProposedView;
98 // When nothing has been focused initially, focus the text field in the first spin
99 if (!e.CurrentView && !e.ProposedView)
101 nextFocusView = _spinYear.SpinText;
103 else if(e.Direction == View.FocusDirection.Left)
105 // Move the focus to the spin in the left of the current focused spin
106 if(e.CurrentView == _spinMonth.SpinText)
108 nextFocusView = _spinYear.SpinText;
110 else if(e.CurrentView == _spinDay.SpinText)
112 nextFocusView = _spinMonth.SpinText;
115 else if(e.Direction == View.FocusDirection.Right)
117 // Move the focus to the spin in the right of the current focused spin
118 if(e.CurrentView == _spinYear.SpinText)
120 nextFocusView = _spinMonth.SpinText;
122 else if(e.CurrentView == _spinMonth.SpinText)
124 nextFocusView = _spinDay.SpinText;
128 return nextFocusView;
131 private void OnFocusedViewEnterKeyPressed(object source, FocusManager.FocusedViewEnterKeyEventArgs e)
133 // Make the text field in the current focused spin to take the key input
134 KeyInputFocusManager manager = KeyInputFocusManager.Get();
136 if (e.View == _spinYear.SpinText)
138 if (manager.GetCurrentFocusControl() != _spinYear.SpinText)
140 manager.SetFocus(_spinYear.SpinText);
143 else if (e.View == _spinMonth.SpinText)
145 if (manager.GetCurrentFocusControl() != _spinMonth.SpinText)
147 manager.SetFocus(_spinMonth.SpinText);
150 else if (e.View == _spinDay.SpinText)
152 if (manager.GetCurrentFocusControl() != _spinDay.SpinText)
154 manager.SetFocus(_spinDay.SpinText);
161 /// The main entry point for the application.
164 static void _Main(string[] args)
166 Example example = new Example();