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;
22 namespace DatePickerUsingJson
24 // A spin control (for continously changing values when users can easily predict a set of values)
26 class Example : NUIApplication
28 private Spin _spinYear; // spin control for year
29 private Spin _spinMonth; // spin control for month
30 private Spin _spinDay; // spin control for day
31 private Builder _builder; // DALi Builder
33 public Example() : base()
37 protected override void OnCreate()
43 public void Initialize()
46 Stage stage = Stage.Instance;
47 stage.BackgroundColor = Color.White;
49 // load date JSON template...
51 _builder = new Builder ();
53 // Optional constant to see logging information coming out
54 // of DALi JSON parser (builder)
55 PropertyMap constants = new PropertyMap();
56 constants.Insert( "CONFIG_SCRIPT_LOG_LEVEL", new PropertyValue( "Verbose") );
57 _builder.AddConstants( constants );
59 _builder.LoadFromFile("/home/owner/apps_rw/NUISamples.TizenTV/res/json/date-picker-template.json" );
61 // create the date-picker from the template in the json file
62 BaseHandle handle = _builder.Create( "date-picker");
64 Actor actorTree = Actor.DownCast( handle );
66 stage.GetDefaultLayer().Add( actorTree );
68 Actor year = actorTree.FindChildByName("Year");
69 Actor month = actorTree.FindChildByName("Month" );
70 Actor day = actorTree.FindChildByName("Day");
72 // need to get the actual C# Spin object associated with the actor,
73 _spinYear = View.DownCast<Spin>( year );
74 _spinMonth = View.DownCast<Spin>( month );
75 _spinDay = View.DownCast<Spin>( day );
77 _spinYear.Value = 2099;
81 _spinYear.Focusable = (true);
82 _spinMonth.Focusable = (true);
83 _spinDay.Focusable = (true);
85 FocusManager keyboardFocusManager = FocusManager.Instance;
86 keyboardFocusManager.PreFocusChange += OnKeyboardPreFocusChange;
87 keyboardFocusManager.FocusedViewEnterKeyPressed += OnFocusedViewEnterKeyPressed;
89 StyleManager.Get().ApplyTheme("/home/owner/apps_rw/NUISamples.TizenTV/res/json/date-picker-theme.json");
92 private View OnKeyboardPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
94 View nextFocusView = e.ProposedView;
96 // When nothing has been focused initially, focus the text field in the first spin
97 if (!e.CurrentView && !e.ProposedView)
99 nextFocusView = _spinYear.SpinText;
101 else if(e.Direction == View.FocusDirection.Left)
103 // Move the focus to the spin in the left of the current focused spin
104 if(e.CurrentView == _spinMonth.SpinText)
106 nextFocusView = _spinYear.SpinText;
108 else if(e.CurrentView == _spinDay.SpinText)
110 nextFocusView = _spinMonth.SpinText;
113 else if(e.Direction == View.FocusDirection.Right)
115 // Move the focus to the spin in the right of the current focused spin
116 if(e.CurrentView == _spinYear.SpinText)
118 nextFocusView = _spinMonth.SpinText;
120 else if(e.CurrentView == _spinMonth.SpinText)
122 nextFocusView = _spinDay.SpinText;
126 return nextFocusView;
129 private void OnFocusedViewEnterKeyPressed(object source, FocusManager.FocusedViewEnterKeyEventArgs e)
131 // Make the text field in the current focused spin to take the key input
132 KeyInputFocusManager manager = KeyInputFocusManager.Get();
134 if (e.View == _spinYear.SpinText)
136 if (manager.GetCurrentFocusControl() != _spinYear.SpinText)
138 manager.SetFocus(_spinYear.SpinText);
141 else if (e.View == _spinMonth.SpinText)
143 if (manager.GetCurrentFocusControl() != _spinMonth.SpinText)
145 manager.SetFocus(_spinMonth.SpinText);
148 else if (e.View == _spinDay.SpinText)
150 if (manager.GetCurrentFocusControl() != _spinDay.SpinText)
152 manager.SetFocus(_spinDay.SpinText);
159 /// The main entry point for the application.
162 static void _Main(string[] args)
164 Example example = new Example();